Skip to content
13 changes: 13 additions & 0 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ To include Issues and Pull Requests that were _opened_ in a time period, use the

(use:token)=

## Remove bots from the changelog

`github-activity` ships with a known list of bot usernames, but your project may use ones not on our list.
To ignore additional usernames from the changelog, use the `--ignore-contributor` flag:

```
github-activity ... --ignore-contributor robot-one --ignore-contributor 'robot-two*'
```

(Wildcards are matched as per [filename matching semantics](https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch)).

If this is a generic bot username, consider contributing it back to [our list](https://github.com/executablebooks/github-activity/blob/main/github_activity/github_activity.py#L73).

## Use a GitHub API token

`github-activity` uses the GitHub API to pull information about a repository's activity.
Expand Down
7 changes: 7 additions & 0 deletions github_activity/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"include-opened": False,
"strip-brackets": False,
"all": False,
"ignore-contributor": [],
}

parser = argparse.ArgumentParser(description=DESCRIPTION)
Expand Down Expand Up @@ -130,6 +131,11 @@
action="store_true",
help=("""Whether to include all the GitHub tags"""),
)
parser.add_argument(
"--ignore-contributor",
action="append",
help="Do not include this GitHub username as a contributor in the changelog",
)

# Hidden argument so that target can be optionally passed as a positional argument
parser.add_argument(
Expand Down Expand Up @@ -214,6 +220,7 @@ def main():
include_opened=bool(args.include_opened),
strip_brackets=bool(args.strip_brackets),
branch=args.branch,
ignored_contributors=args.ignore_contributor,
)

if args.all:
Expand Down
96 changes: 57 additions & 39 deletions github_activity/github_activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Use the GraphQL api to grab issues/PRs that match a query."""
import datetime
import fnmatch
import os
import re
import shlex
Expand Down Expand Up @@ -69,25 +70,26 @@
}

# exclude known bots from contributor lists
# TODO: configurable? Everybody's got their own bots.
# Also see 'ignore-contributor' flag/configuration option.
BOT_USERS = {
"codecov",
"codecov-io",
"dependabot",
"github-actions",
"henchbot",
"jupyterlab-dev-mode",
"lgtm-com",
"meeseeksmachine",
"names",
"now",
"pre-commit-ci",
"renovate",
"review-notebook-app",
"support",
"stale",
"todo",
"welcome",
"changeset-bot*",
"codecov*",
"codecov-io*",
"dependabot*",
"github-actions*",
"henchbot*",
"jupyterlab-dev-mode*",
"lgtm-com*",
"meeseeksmachine*",
"names*",
"now*",
"pre-commit-ci*",
"renovate*",
"review-notebook-app*",
"support*",
"stale*",
"todo*",
"welcome*",
}


Expand Down Expand Up @@ -225,6 +227,7 @@ def generate_all_activity_md(
include_opened=False,
strip_brackets=False,
branch=None,
ignored_contributors: list[str] = None,
):
"""Generate a full markdown changelog of GitHub activity of a repo based on release tags.

Expand Down Expand Up @@ -259,6 +262,8 @@ def generate_all_activity_md(
E.g., [MRG], [DOC], etc.
branch : string | None
The branch or reference name to filter pull requests by.
ignored_contributors : list
List of usernames not to include in the changelog.

Returns
-------
Expand Down Expand Up @@ -322,6 +327,7 @@ def filter(datum):
include_opened=include_opened,
strip_brackets=strip_brackets,
branch=branch,
ignored_contributors=ignored_contributors,
)

if not md:
Expand Down Expand Up @@ -349,6 +355,7 @@ def generate_activity_md(
strip_brackets=False,
heading_level=1,
branch=None,
ignored_contributors: list[str] = None,
):
"""Generate a markdown changelog of GitHub activity within a date window.

Expand Down Expand Up @@ -418,30 +425,40 @@ def generate_activity_md(
comment_response_cutoff = 6 # Comments on a single issue
comment_others_cutoff = 2 # Comments on issues somebody else has authored
comment_helpers = []
all_contributors = []
all_contributors = set()
# add column for participants in each issue (not just original author)
data["contributors"] = [[]] * len(data)

def ignored_user(username):
return any(fnmatch.fnmatch(username, bot) for bot in BOT_USERS) or any(
fnmatch.fnmatch(username, user) for user in ignored_contributors
)

def filter_ignored(userlist):
return {user for user in userlist if not ignored_user(user)}

for ix, row in data.iterrows():
item_contributors = set()

# This is a list, since we *want* duplicates in here—they
# indicate number of times a contributor commented
item_commentors = []
item_contributors = []

# contributor order:
# - author
# - committers
# - merger
# - reviewers

item_contributors.append(row.author)
item_contributors.add(row.author)

if row.kind == "pr":
for committer in row.committers:
if committer not in row.committers and committer not in BOT_USERS:
item_contributors.append(committer)
for committer in filter_ignored(row.committers):
item_contributors.add(committer)
if row.mergedBy and row.mergedBy != row.author:
item_contributors.append(row.mergedBy)
for reviewer in row.reviewers:
if reviewer not in item_contributors:
item_contributors.append(reviewer)
item_contributors.add(row.mergedBy)
for reviewer in filter_ignored(row.reviewers):
item_contributors.add(reviewer)

for icomment in row["comments"]["edges"]:
comment_author = icomment["node"]["author"]
Expand All @@ -451,7 +468,7 @@ def generate_activity_md(
continue

comment_author = comment_author["login"]
if comment_author in BOT_USERS:
if ignored_user(comment_author):
# ignore bots
continue

Expand All @@ -463,24 +480,25 @@ def generate_activity_md(
item_commentors.append(comment_author)

# count all comments on a PR as a contributor
if comment_author not in item_contributors:
item_contributors.append(comment_author)
item_contributors.add(comment_author)

# Count any commentors that had enough comments on the issue to be a contributor
item_commentors_counts = pd.Series(item_commentors).value_counts()
item_commentors_counts = item_commentors_counts[
item_commentors_counts >= comment_response_cutoff
].index.tolist()
for person in item_commentors_counts:
all_contributors.append(person)
all_contributors.add(person)

# record contributor list (ordered, unique)
data.at[ix, "contributors"] = item_contributors
data.at[ix, "contributors"] = sorted(item_contributors)

comment_contributor_counts = pd.Series(comment_helpers).value_counts()
all_contributors += comment_contributor_counts[
comment_contributor_counts >= comment_others_cutoff
].index.tolist()
all_contributors |= set(
comment_contributor_counts[
comment_contributor_counts >= comment_others_cutoff
].index.tolist()
)

# Filter the PRs by branch (or ref) if given
if branch is not None:
Expand Down Expand Up @@ -517,7 +535,7 @@ def generate_activity_md(
closed_prs = closed_prs.query("state != 'CLOSED'")

# Add any contributors to a merged PR to our contributors list
all_contributors += closed_prs["contributors"].explode().unique().tolist()
all_contributors |= set(closed_prs["contributors"].explode().unique().tolist())

# Define categories for a few labels
if tags is None:
Expand Down Expand Up @@ -615,7 +633,7 @@ def generate_activity_md(
[
f"[@{user}](https://github.com/{user})"
for user in irowdata.contributors
if user not in BOT_USERS
if not ignored_user(user)
]
)
this_md = f"- {ititle} [#{irowdata['number']}]({irowdata['url']}) ({contributor_list})"
Expand Down Expand Up @@ -663,7 +681,7 @@ def generate_activity_md(

# Add a list of author contributions
all_contributors = sorted(
set(all_contributors) - BOT_USERS, key=lambda a: str(a).lower()
filter_ignored(all_contributors), key=lambda a: str(a).lower()
)
all_contributor_links = []
for iauthor in all_contributors:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ def test_cli_all(tmpdir, file_regression):
md = path_output.read_text()
index = md.index("## v0.2.0")
file_regression.check(md[index:], extension=".md")


def test_cli_ignore_user(tmpdir):
"""Test that a full changelog is created"""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -o {path_output}"
run(cmd.split(), check=True)
md = path_output.read_text()
assert not "@choldgraf" in md
6 changes: 3 additions & 3 deletions tests/test_cli/cli_def_branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## New features added

- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))

## Enhancements made

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

Expand All @@ -23,7 +23,7 @@

## Documentation improvements

- 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))
- 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))

## Contributors to this release

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli/cli_no_target.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## New features added

- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))

## Enhancements made

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

Expand All @@ -23,7 +23,7 @@

## Documentation improvements

- 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))
- 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))

## Contributors to this release

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli/cli_no_target_pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
###### New features added

- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))

###### Enhancements made

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

Expand All @@ -23,7 +23,7 @@

###### Documentation improvements

- 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))
- 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))

###### Contributors to this release

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli/cli_w_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## New features added

- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))

## Enhancements made

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

Expand All @@ -23,7 +23,7 @@

## Documentation improvements

- 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))
- 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))

## Contributors to this release

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli/cli_w_url.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## New features added

- adding contributors list [#10](https://github.com/executablebooks/github-activity/pull/10) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@consideRatio](https://github.com/consideRatio), [@choldgraf](https://github.com/choldgraf))
- Support git references etc. [#6](https://github.com/executablebooks/github-activity/pull/6) ([@choldgraf](https://github.com/choldgraf), [@consideRatio](https://github.com/consideRatio))

## Enhancements made

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

Expand All @@ -23,7 +23,7 @@

## Documentation improvements

- 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))
- 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))

## Contributors to this release

Expand Down
Loading