Skip to content

Commit

Permalink
automate extracting the contributors (#9288)
Browse files Browse the repository at this point in the history
* script to generate the release string

* use the new script in the release guide

* include `toolz` in the deps
  • Loading branch information
keewis authored Jul 29, 2024
1 parent af12604 commit 470d1e8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
11 changes: 5 additions & 6 deletions HOW_TO_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ upstream https://github.com/pydata/xarray (push)
```sh
git fetch upstream --tags
```
This will return a list of all the contributors since the last release:
Then run
```sh
git log "$(git tag --sort=v:refname | tail -1).." --format=%aN | sort -u | perl -pe 's/\n/$1, /'
```
This will return the total number of contributors:
```sh
git log "$(git tag --sort=v:refname | tail -1).." --format=%aN | sort -u | wc -l
python ci/release_contributors.py
```
(needs `gitpython` and `toolz` / `cytoolz`)

and copy the output.
3. Write a release summary: ~50 words describing the high level features. This
will be used in the release emails, tweets, GitHub release notes, etc.
4. Look over whats-new.rst and the docs. Make sure "What's New" is complete
Expand Down
49 changes: 49 additions & 0 deletions ci/release_contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re
import textwrap

import git
from tlz.itertoolz import last, unique

co_author_re = re.compile(r"Co-authored-by: (?P<name>[^<]+?) <(?P<email>.+)>")


def main():
repo = git.Repo(".")

most_recent_release = last(repo.tags)

# extract information from commits
contributors = {}
for commit in repo.iter_commits(f"{most_recent_release.name}.."):
matches = co_author_re.findall(commit.message)
if matches:
contributors.update({email: name for name, email in matches})
contributors[commit.author.email] = commit.author.name

# deduplicate and ignore
# TODO: extract ignores from .github/release.yml
ignored = ["dependabot", "pre-commit-ci"]
unique_contributors = unique(
contributor
for contributor in contributors.values()
if contributor.removesuffix("[bot]") not in ignored
)

sorted_ = sorted(unique_contributors)
if len(sorted_) > 1:
names = f"{', '.join(sorted_[:-1])} and {sorted_[-1]}"
else:
names = "".join(sorted_)

statement = textwrap.dedent(
f"""\
Thanks to the {len(sorted_)} contributors to this release:
{names}
""".rstrip()
)

print(statement)


if __name__ == "__main__":
main()

0 comments on commit 470d1e8

Please sign in to comment.