Skip to content

Commit 89a921b

Browse files
authored
Update test suite to use fewer GitHub API calls (#144)
1 parent cdb6572 commit 89a921b

File tree

12 files changed

+81
-265
lines changed

12 files changed

+81
-265
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ updates:
1616
groups:
1717
actions:
1818
patterns:
19-
- "*"
19+
- "*"

.github/workflows/tests.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: continuous-integration
22

33
on:
4-
# pull_request_target makes secrets available in the PR, so we avoid rate limits
5-
# YOU MUST MERGE THE PR to test changes to this file. GitHub run the version on `main`.
6-
pull_request_target:
4+
pull_request:
75
push:
86
branches: [main]
97
tags:
@@ -36,11 +34,9 @@ jobs:
3634
3735
tests:
3836
runs-on: ubuntu-24.04
39-
environment: pr-tests
4037
env:
41-
# This is a private access token for @choldgraf that has public read-only access.
42-
# FUTURE: We should update the tests to only pull from this repository and not
43-
# need a token at all.
38+
# This is a PAT for @choldgraf that only has read-access to this repo.
39+
# We use it to avoid query limits.
4440
GITHUB_ACCESS_TOKEN: "${{ secrets.TOKEN_READONLY }}"
4541
strategy:
4642
matrix:

github_activity/github_activity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ def filter_ignored(userlist):
565565
if data.empty:
566566
return
567567

568+
# Extract datetime strings from data attributes for pandas query
569+
since_dt_str = data.since_dt_str # noqa: F841
570+
until_dt_str = data.until_dt_str # noqa: F841
571+
568572
# Separate into closed and opened
569573
closed = data.query("closedAt >= @since_dt_str and closedAt <= @until_dt_str")
570574
opened = data.query("createdAt >= @since_dt_str and createdAt <= @until_dt_str")
@@ -876,7 +880,7 @@ def _get_datetime_from_git_ref(org, repo, ref, token):
876880
try:
877881
data = response.json()
878882
print(f"\n!! GitHub error: {data['message']}\n")
879-
except Exception as e:
883+
except Exception:
880884
pass
881885
raise
882886
return dateutil.parser.parse(response.json()["commit"]["committer"]["date"])

tests/test_cli.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
[
1111
# CLI with URL
1212
(
13-
"github-activity {url} -s 2019-09-01 -u 2019-11-01 -o {path_output}",
13+
"github-activity {url} -s 2021-01-01 -u 2021-01-15 -o {path_output}",
1414
"cli_w_url",
1515
),
1616
# CLI with parts
1717
(
18-
"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output}",
18+
"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output}",
1919
"cli_w_parts",
2020
),
2121
# CLI with default branch
2222
(
23-
"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b master",
23+
"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output} -b master",
2424
"cli_def_branch",
2525
),
2626
# CLI with no target
2727
(
28-
"github-activity -s 2019-09-01 -u 2019-11-01 -o {path_output}",
28+
"github-activity -s 2021-01-01 -u 2021-01-15 -o {path_output}",
2929
"cli_no_target",
3030
),
3131
],
@@ -46,7 +46,7 @@ def test_cli(tmpdir, file_regression, cmd, basename):
4646

4747
def test_cli_dot_config(tmp_path, monkeypatch, file_regression):
4848
"""Test that pyproject.toml config is loaded"""
49-
cmd = "github-activity -s 2019-09-01 -u 2019-11-01 -o {path_output}"
49+
cmd = "github-activity -s 2021-01-01 -u 2021-01-15 -o {path_output}"
5050
basename = "cli_no_target_pyproject"
5151

5252
path_output = tmp_path / "out.md"
@@ -85,7 +85,7 @@ def test_cli_nonexistent_branch(tmpdir):
8585

8686
org, repo = ("executablebooks", "github-activity")
8787

88-
cmd = f"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b foo"
88+
cmd = f"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output} -b foo"
8989
run(cmd.split(), check=True)
9090
md = path_output.read_text()
9191
assert "Contributors to this release" in md
@@ -97,10 +97,10 @@ def test_pr_split(tmpdir, file_regression):
9797
path_tmp = Path(tmpdir)
9898
path_output = path_tmp.joinpath("out.md")
9999

100-
url = "https://github.com/jupyter-book/jupyter-book"
100+
url = "https://github.com/executablebooks/github-activity"
101101

102-
# This release range covers some PRs with tags, and some with prefixes
103-
cmd = f"github-activity {url} -s v0.7.1 -u v0.7.3 -o {path_output}"
102+
# Test PR tag/prefix splitting using recent consecutive releases
103+
cmd = f"github-activity {url} -s v1.0.2 -u v1.0.3 -o {path_output}"
104104
run(cmd.split(), check=True)
105105
md = path_output.read_text()
106106
md = md.split("## Contributors to this release")[0]
@@ -111,18 +111,19 @@ def test_cli_all(tmpdir, file_regression):
111111
"""Test that a full changelog is created"""
112112
path_tmp = Path(tmpdir)
113113
path_output = path_tmp.joinpath("out.md")
114-
cmd = f"github-activity executablebooks/github-activity --all -o {path_output}"
114+
# Use recent consecutive releases to reduce API calls
115+
cmd = f"github-activity executablebooks/github-activity -s v1.0.2 -u v1.0.3 -o {path_output}"
115116
run(cmd.split(), check=True)
116117
md = path_output.read_text()
117-
index = md.index("## v0.2.0")
118-
file_regression.check(md[index:], extension=".md")
118+
file_regression.check(md, extension=".md")
119119

120120

121121
def test_cli_ignore_user(tmpdir):
122122
"""Test that a full changelog is created"""
123123
path_tmp = Path(tmpdir)
124124
path_output = path_tmp.joinpath("out.md")
125-
cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -o {path_output}"
125+
# Add end date to limit query range
126+
cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -u v1.0.3 -o {path_output}"
126127
run(cmd.split(), check=True)
127128
md = path_output.read_text()
128129
assert "@choldgraf" not in md
@@ -133,11 +134,10 @@ def test_contributor_sorting(tmpdir, file_regression):
133134
path_tmp = Path(tmpdir)
134135
path_output = path_tmp.joinpath("out.md")
135136

136-
org, repo = ("jupyter-book", "mystmd")
137+
org, repo = ("executablebooks", "github-activity")
137138

138-
cmd = (
139-
f"github-activity {org}/{repo} -s [email protected] -u [email protected] -o {path_output}"
140-
)
139+
# Test contributor sorting using recent consecutive releases
140+
cmd = f"github-activity {org}/{repo} -s v0.2.0 -u v0.3.0 -o {path_output}"
141141
run(cmd.split(), check=True)
142142
md = path_output.read_text()
143143
file_regression.check(md, extension=".md")

tests/test_cli/cli_def_branch.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
1-
# master@{2019-09-01}...master@{2019-11-01}
1+
# master@{2021-01-01}...master@{2021-01-15}
22

3-
([full changelog](https://github.com/executablebooks/github-activity/compare/479cc4b2f5504945021e3c4ee84818a10fabf810...ed7f1ed78b523c6b9fe6b3ac29e834087e299296))
4-
5-
## New features added
6-
7-
- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
8-
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
9-
10-
## Enhancements made
11-
12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
13-
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
14-
- some improvements to `since` and opened issues list [#8](https://github.com/executablebooks/github-activity/pull/8) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
3+
([full changelog](https://github.com/executablebooks/github-activity/compare/c740a454def057304556675ce7694dc0f2eb6c88...c740a454def057304556675ce7694dc0f2eb6c88))
154

165
## Bugs fixed
176

18-
- fixing link to changelog with refs [#11](https://github.com/executablebooks/github-activity/pull/11) ([@choldgraf](https://github.com/choldgraf))
19-
20-
## Maintenance and upkeep improvements
21-
22-
- adding authentication information [#2](https://github.com/executablebooks/github-activity/pull/2) ([@choldgraf](https://github.com/choldgraf))
23-
24-
## Documentation improvements
25-
26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
7+
- 🐛 FIX: tags like 'doctor' would trigger 'doc' tag [#40](https://github.com/executablebooks/github-activity/pull/40) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
278

289
## Contributors to this release
2910

3011
The following people contributed discussions, new ideas, code and documentation contributions, and review.
3112
See [our definition of contributors](https://github-activity.readthedocs.io/en/latest/#how-does-this-tool-define-contributions-in-the-reports).
3213

33-
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2019-09-01&to=2019-11-01&type=c))
14+
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2021-01-01&to=2021-01-15&type=c))
3415

35-
@betatim ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Abetatim+updated%3A2019-09-01..2019-11-01&type=Issues)) | @choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2019-09-01..2019-11-01&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2019-09-01..2019-11-01&type=Issues))
16+
@choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2021-01-01..2021-01-15&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2021-01-01..2021-01-15&type=Issues))

tests/test_cli/cli_no_target.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
1-
# master@{2019-09-01}...master@{2019-11-01}
1+
# master@{2021-01-01}...master@{2021-01-15}
22

3-
([full changelog](https://github.com/executablebooks/github-activity/compare/479cc4b2f5504945021e3c4ee84818a10fabf810...ed7f1ed78b523c6b9fe6b3ac29e834087e299296))
4-
5-
## New features added
6-
7-
- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
8-
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
9-
10-
## Enhancements made
11-
12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
13-
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
14-
- some improvements to `since` and opened issues list [#8](https://github.com/executablebooks/github-activity/pull/8) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
3+
([full changelog](https://github.com/executablebooks/github-activity/compare/c740a454def057304556675ce7694dc0f2eb6c88...c740a454def057304556675ce7694dc0f2eb6c88))
154

165
## Bugs fixed
176

18-
- fixing link to changelog with refs [#11](https://github.com/executablebooks/github-activity/pull/11) ([@choldgraf](https://github.com/choldgraf))
19-
20-
## Maintenance and upkeep improvements
21-
22-
- adding authentication information [#2](https://github.com/executablebooks/github-activity/pull/2) ([@choldgraf](https://github.com/choldgraf))
23-
24-
## Documentation improvements
25-
26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
7+
- 🐛 FIX: tags like 'doctor' would trigger 'doc' tag [#40](https://github.com/executablebooks/github-activity/pull/40) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
278

289
## Contributors to this release
2910

3011
The following people contributed discussions, new ideas, code and documentation contributions, and review.
3112
See [our definition of contributors](https://github-activity.readthedocs.io/en/latest/#how-does-this-tool-define-contributions-in-the-reports).
3213

33-
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2019-09-01&to=2019-11-01&type=c))
14+
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2021-01-01&to=2021-01-15&type=c))
3415

35-
@betatim ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Abetatim+updated%3A2019-09-01..2019-11-01&type=Issues)) | @choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2019-09-01..2019-11-01&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2019-09-01..2019-11-01&type=Issues))
16+
@choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2021-01-01..2021-01-15&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2021-01-01..2021-01-15&type=Issues))
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
1-
##### master@{2019-09-01}...master@{2019-11-01}
1+
##### master@{2021-01-01}...master@{2021-01-15}
22

3-
([full changelog](https://github.com/executablebooks/github-activity/compare/479cc4b2f5504945021e3c4ee84818a10fabf810...ed7f1ed78b523c6b9fe6b3ac29e834087e299296))
4-
5-
###### New features added
6-
7-
- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
8-
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
9-
10-
###### Enhancements made
11-
12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
13-
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
14-
- some improvements to `since` and opened issues list [#8](https://github.com/executablebooks/github-activity/pull/8) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
3+
([full changelog](https://github.com/executablebooks/github-activity/compare/c740a454def057304556675ce7694dc0f2eb6c88...c740a454def057304556675ce7694dc0f2eb6c88))
154

165
###### Bugs fixed
176

18-
- fixing link to changelog with refs [#11](https://github.com/executablebooks/github-activity/pull/11) ([@choldgraf](https://github.com/choldgraf))
19-
20-
###### Maintenance and upkeep improvements
21-
22-
- adding authentication information [#2](https://github.com/executablebooks/github-activity/pull/2) ([@choldgraf](https://github.com/choldgraf))
23-
24-
###### Documentation improvements
25-
26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
7+
- 🐛 FIX: tags like 'doctor' would trigger 'doc' tag [#40](https://github.com/executablebooks/github-activity/pull/40) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
278

289
###### Contributors to this release
2910

3011
The following people contributed discussions, new ideas, code and documentation contributions, and review.
3112
See [our definition of contributors](https://github-activity.readthedocs.io/en/latest/#how-does-this-tool-define-contributions-in-the-reports).
3213

33-
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2019-09-01&to=2019-11-01&type=c))
14+
([GitHub contributors page for this release](https://github.com/executablebooks/github-activity/graphs/contributors?from=2021-01-01&to=2021-01-15&type=c))
3415

35-
@betatim ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Abetatim+updated%3A2019-09-01..2019-11-01&type=Issues)) | @choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2019-09-01..2019-11-01&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2019-09-01..2019-11-01&type=Issues))
16+
@choldgraf ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3Acholdgraf+updated%3A2021-01-01..2021-01-15&type=Issues)) | @consideRatio ([activity](https://github.com/search?q=repo%3Aexecutablebooks%2Fgithub-activity+involves%3AconsideRatio+updated%3A2021-01-01..2021-01-15&type=Issues))

0 commit comments

Comments
 (0)