Skip to content
6 changes: 6 additions & 0 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide multiple contributors? If so could you document that? (e.g. do you pass the flag multiple times, do you do a comma separated list, space-separated list, etc?) what if you have a long list and have it all in a file, could we show that as a demo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
24 changes: 17 additions & 7 deletions github_activity/github_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@
}

# exclude known bots from contributor lists
# TODO: configurable? Everybody's got their own bots.
# Also see 'ignore-contributor' flag/configuration option.
BOT_USERS = {
"changeset-bot",
"codecov",
"codecov-io",
"dependabot",
"github-actions",
"github-actions[bot]",
"henchbot",
"jupyterlab-dev-mode",
"lgtm-com",
Expand Down Expand Up @@ -349,6 +351,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 @@ -421,6 +424,13 @@ def generate_activity_md(
all_contributors = []
# add column for participants in each issue (not just original author)
data["contributors"] = [[]] * len(data)

def ignored_user(username):
return (username in BOT_USERS) or (username 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_commentors = []
item_contributors = []
Expand All @@ -434,12 +444,12 @@ def generate_activity_md(
item_contributors.append(row.author)

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

Expand All @@ -451,7 +461,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 Down Expand Up @@ -615,7 +625,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 +673,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()
set(filter_ignored(all_contributors)), key=lambda a: str(a).lower()
)
all_contributor_links = []
for iauthor in all_contributors:
Expand Down