Skip to content

Commit 4617899

Browse files
committed
Sort order: PR author, then others
1 parent 3e1dff7 commit 4617899

File tree

10 files changed

+104
-35
lines changed

10 files changed

+104
-35
lines changed

github_activity/github_activity.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Use the GraphQL api to grab issues/PRs that match a query."""
2+
import dataclasses
23
import datetime
34
import fnmatch
45
import os
@@ -343,6 +344,26 @@ def filter(datum):
343344
return output
344345

345346

347+
@dataclasses.dataclass(slots=True)
348+
class ContributorSet:
349+
"""This class represents a sorted set of PR contributor usernames.
350+
351+
The sorting is special, in that the author is placed first.
352+
"""
353+
354+
author: str = ""
355+
other: set = dataclasses.field(default_factory=set)
356+
357+
def add(self, contributor):
358+
self.other.add(contributor)
359+
360+
def __iter__(self):
361+
if self.author:
362+
yield self.author
363+
for item in sorted(self.other - {self.author}):
364+
yield item
365+
366+
346367
def generate_activity_md(
347368
target,
348369
since=None,
@@ -438,7 +459,8 @@ def filter_ignored(userlist):
438459
return {user for user in userlist if not ignored_user(user)}
439460

440461
for ix, row in data.iterrows():
441-
item_contributors = set()
462+
# Track contributors to this PR
463+
item_contributors = ContributorSet()
442464

443465
# This is a list, since we *want* duplicates in here—they
444466
# indicate number of times a contributor commented
@@ -450,7 +472,7 @@ def filter_ignored(userlist):
450472
# - merger
451473
# - reviewers
452474

453-
item_contributors.add(row.author)
475+
item_contributors.author = row.author
454476

455477
if row.kind == "pr":
456478
for committer in filter_ignored(row.committers):
@@ -491,7 +513,7 @@ def filter_ignored(userlist):
491513
all_contributors.add(person)
492514

493515
# record contributor list (ordered, unique)
494-
data.at[ix, "contributors"] = sorted(item_contributors)
516+
data.at[ix, "contributors"] = list(item_contributors)
495517

496518
comment_contributor_counts = pd.Series(comment_helpers).value_counts()
497519
all_contributors |= set(

tests/test_cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,18 @@ def test_cli_ignore_user(tmpdir):
127127
run(cmd.split(), check=True)
128128
md = path_output.read_text()
129129
assert not "@choldgraf" in md
130+
131+
132+
def test_contributor_sorting(tmpdir, file_regression):
133+
"""Test that PR author appears first, then rest of contributors, sorted"""
134+
path_tmp = Path(tmpdir)
135+
path_output = path_tmp.joinpath("out.md")
136+
137+
org, repo = ("jupyter-book", "mystmd")
138+
139+
cmd = (
140+
f"github-activity {org}/{repo} -s mystmd@1.5.1 -u mystmd@1.6.0 -o {path_output}"
141+
)
142+
run(cmd.split(), check=True)
143+
md = path_output.read_text()
144+
file_regression.check(md, extension=".md")

tests/test_cli/cli_def_branch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
## New features added
66

77
- 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) ([@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))
99

1010
## Enhancements made
1111

12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@betatim](https://github.com/betatim), [@choldgraf](https://github.com/choldgraf))
12+
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
1313
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
1414
- 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))
1515

@@ -23,7 +23,7 @@
2323

2424
## Documentation improvements
2525

26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
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))
2727

2828
## Contributors to this release
2929

tests/test_cli/cli_no_target.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
## New features added
66

77
- 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) ([@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))
99

1010
## Enhancements made
1111

12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@betatim](https://github.com/betatim), [@choldgraf](https://github.com/choldgraf))
12+
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
1313
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
1414
- 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))
1515

@@ -23,7 +23,7 @@
2323

2424
## Documentation improvements
2525

26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
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))
2727

2828
## Contributors to this release
2929

tests/test_cli/cli_no_target_pyproject.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
###### New features added
66

77
- 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) ([@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))
99

1010
###### Enhancements made
1111

12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@betatim](https://github.com/betatim), [@choldgraf](https://github.com/choldgraf))
12+
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
1313
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
1414
- 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))
1515

@@ -23,7 +23,7 @@
2323

2424
###### Documentation improvements
2525

26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
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))
2727

2828
###### Contributors to this release
2929

tests/test_cli/cli_w_parts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
## New features added
66

77
- 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) ([@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))
99

1010
## Enhancements made
1111

12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@betatim](https://github.com/betatim), [@choldgraf](https://github.com/choldgraf))
12+
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
1313
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
1414
- 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))
1515

@@ -23,7 +23,7 @@
2323

2424
## Documentation improvements
2525

26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
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))
2727

2828
## Contributors to this release
2929

tests/test_cli/cli_w_url.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
## New features added
66

77
- 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) ([@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))
99

1010
## Enhancements made
1111

12-
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@betatim](https://github.com/betatim), [@choldgraf](https://github.com/choldgraf))
12+
- defining contributions [#14](https://github.com/executablebooks/github-activity/pull/14) ([@choldgraf](https://github.com/choldgraf), [@betatim](https://github.com/betatim))
1313
- updating CLI for new tags [#12](https://github.com/executablebooks/github-activity/pull/12) ([@choldgraf](https://github.com/choldgraf))
1414
- 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))
1515

@@ -23,7 +23,7 @@
2323

2424
## Documentation improvements
2525

26-
- Mention the required GITHUB_ACCESS_TOKEN [#1](https://github.com/executablebooks/github-activity/pull/1) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
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))
2727

2828
## Contributors to this release
2929

tests/test_cli/test_cli_all.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
### Enhancements made
66

77
- Use auth for all usages of requests [#60](https://github.com/executablebooks/github-activity/pull/60) ([@blink1073](https://github.com/blink1073), [@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
8-
- Handle detection of target from SSH based remotes [#51](https://github.com/executablebooks/github-activity/pull/51) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
8+
- Handle detection of target from SSH based remotes [#51](https://github.com/executablebooks/github-activity/pull/51) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
99
- ✨ ENH: Auto-detecting the target [#45](https://github.com/executablebooks/github-activity/pull/45) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
1010

1111
### Bugs fixed
1212

13-
- 🐛 FIX: write status messages to sys.stderr [#47](https://github.com/executablebooks/github-activity/pull/47) ([@choldgraf](https://github.com/choldgraf), [@minrk](https://github.com/minrk))
13+
- 🐛 FIX: write status messages to sys.stderr [#47](https://github.com/executablebooks/github-activity/pull/47) ([@minrk](https://github.com/minrk), [@choldgraf](https://github.com/choldgraf))
1414

1515
### Maintenance and upkeep improvements
1616

17-
- 🔧 MAINT: Split test_cli using @pytest.mark.parameterize [#56](https://github.com/executablebooks/github-activity/pull/56) ([@choldgraf](https://github.com/choldgraf), [@manics](https://github.com/manics))
18-
- pre-commit configured and executed [#55](https://github.com/executablebooks/github-activity/pull/55) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
19-
- 🔧 MAINT: _get_latest_tag should use the remote repo [#52](https://github.com/executablebooks/github-activity/pull/52) ([@consideRatio](https://github.com/consideRatio), [@manics](https://github.com/manics))
17+
- 🔧 MAINT: Split test_cli using @pytest.mark.parameterize [#56](https://github.com/executablebooks/github-activity/pull/56) ([@manics](https://github.com/manics), [@choldgraf](https://github.com/choldgraf))
18+
- pre-commit configured and executed [#55](https://github.com/executablebooks/github-activity/pull/55) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
19+
- 🔧 MAINT: _get_latest_tag should use the remote repo [#52](https://github.com/executablebooks/github-activity/pull/52) ([@manics](https://github.com/manics), [@consideRatio](https://github.com/consideRatio))
2020
- 🔧 MAINT: hyphen instead of asterisk [#44](https://github.com/executablebooks/github-activity/pull/44) ([@choldgraf](https://github.com/choldgraf))
2121

2222
### Contributors to this release
@@ -34,23 +34,23 @@ See [our definition of contributors](https://github-activity.readthedocs.io/en/l
3434

3535
### New features added
3636

37-
- Adding filtering by branch [#42](https://github.com/executablebooks/github-activity/pull/42) ([@blink1073](https://github.com/blink1073), [@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
38-
- ✨NEW: heading_level argument for increasing heading level [#38](https://github.com/executablebooks/github-activity/pull/38) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio), [@minrk](https://github.com/minrk))
37+
- Adding filtering by branch [#42](https://github.com/executablebooks/github-activity/pull/42) ([@choldgraf](https://github.com/choldgraf), [@blink1073](https://github.com/blink1073), [@consideRatio](https://github.com/consideRatio))
38+
- ✨NEW: heading_level argument for increasing heading level [#38](https://github.com/executablebooks/github-activity/pull/38) ([@minrk](https://github.com/minrk), [@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
3939

4040
### Enhancements made
4141

42-
- use tqdm for progress [#39](https://github.com/executablebooks/github-activity/pull/39) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio), [@minrk](https://github.com/minrk))
43-
- 👌IMPROVE: add blank lines below headings [#36](https://github.com/executablebooks/github-activity/pull/36) ([@choldgraf](https://github.com/choldgraf), [@minrk](https://github.com/minrk))
44-
- 👌 IMPROVE: since/until: assume git reference, fallback to datetime [#33](https://github.com/executablebooks/github-activity/pull/33) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
42+
- use tqdm for progress [#39](https://github.com/executablebooks/github-activity/pull/39) ([@minrk](https://github.com/minrk), [@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
43+
- 👌IMPROVE: add blank lines below headings [#36](https://github.com/executablebooks/github-activity/pull/36) ([@minrk](https://github.com/minrk), [@choldgraf](https://github.com/choldgraf))
44+
- 👌 IMPROVE: since/until: assume git reference, fallback to datetime [#33](https://github.com/executablebooks/github-activity/pull/33) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
4545

4646
### Bugs fixed
4747

48-
- 🐛 FIX: tags like 'doctor' would trigger 'doc' tag [#40](https://github.com/executablebooks/github-activity/pull/40) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
48+
- 🐛 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))
4949

5050
### Maintenance and upkeep improvements
5151

52-
- Remove no longer used code [#37](https://github.com/executablebooks/github-activity/pull/37) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
53-
- [FIX,TST] resolve refs when not run from a repo [#35](https://github.com/executablebooks/github-activity/pull/35) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio), [@minrk](https://github.com/minrk))
52+
- Remove no longer used code [#37](https://github.com/executablebooks/github-activity/pull/37) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
53+
- [FIX,TST] resolve refs when not run from a repo [#35](https://github.com/executablebooks/github-activity/pull/35) ([@minrk](https://github.com/minrk), [@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
5454

5555
### Documentation improvements
5656

0 commit comments

Comments
 (0)