forked from Hirni-Meshram2/pants
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite changelog helper to Python and use markdown for changelog (pa…
…ntsbuild#11224) Some changes: * You now specify the `--prior` and `--new` versions as CLI args, e.g. `--prior 2.1.0 --new 2.2.0.dev0`. Before, it asked for the prior Git tag as an `input()` once the script was running. * We use markdown, which is simpler to work with. * We don't need to worry about compat with the v1 site. * It says which file to modify. * The version header is generated. * We represent the date as `(Nov 20, 2020)`, rather than `(11/20/20)`. This avoids any confusion for non-US users. * We no longer include related PRs and issues. It was a bit confusing what those meant, and the user should open the original PR to get more info anyways. [ci skip-rust] [ci skip-build-wheels]
- Loading branch information
1 parent
82fc6ca
commit 8bb2c31
Showing
3 changed files
with
114 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
import argparse | ||
import datetime | ||
import re | ||
import subprocess | ||
from textwrap import dedent | ||
from typing import List | ||
|
||
|
||
def create_parser() -> argparse.ArgumentParser: | ||
parser = argparse.ArgumentParser(description="Prepare the changelog for a release.") | ||
parser.add_argument( | ||
"--prior", | ||
required=True, | ||
type=str, | ||
help="The version of the prior release, e.g. `2.0.0.dev0` or `2.0.0rc1`.", | ||
) | ||
parser.add_argument( | ||
"--new", | ||
required=True, | ||
type=str, | ||
help="The version for the new release, e.g. `2.0.0.dev0` or `2.0.0rc1`.", | ||
) | ||
return parser | ||
|
||
|
||
def relevant_shas(prior: str) -> List[str]: | ||
prior_tag = f"release_{prior}" | ||
return ( | ||
subprocess.run( | ||
["git", "log", "--format=format:%H", "HEAD", f"^{prior_tag}"], | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
) | ||
.stdout.decode() | ||
.splitlines() | ||
) | ||
|
||
|
||
def prepare_sha(sha: str) -> str: | ||
subject = ( | ||
subprocess.run( | ||
["git", "log", "-1", "--format=format:%s", sha], | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
) | ||
.stdout.decode() | ||
.strip() | ||
) | ||
pr_num_match = re.search(r"\(#(\d{4,5})\)\s*$", subject) | ||
if not pr_num_match: | ||
return f"* {subject}" | ||
pr_num = pr_num_match.groups()[0] | ||
pr_url = f"https://github.com/pantsbuild/pants/pull/{pr_num}" | ||
subject_with_url = subject.replace(f"(#{pr_num})", f"([#{pr_num}]({pr_url}))") | ||
return f"* {subject_with_url.capitalize()}" | ||
|
||
|
||
def instructions(new_version: str) -> str: | ||
date = datetime.date.today().strftime("%b %d, %Y") | ||
version_components = new_version.split(".", maxsplit=4) | ||
major, minor = version_components[0], version_components[1] | ||
return dedent( | ||
f"""\ | ||
Copy the below headers into `src/python/notes/{major}.{minor}.x.md`. Then, put each commit | ||
into the relevant category. You can tweak descriptions to be more descriptive or to fix | ||
typos, and you can reorder based on relative importance to end users. Delete any unused | ||
headers. | ||
--------------------------------------------------------------------- | ||
# {new_version} ({date}) | ||
## New Features | ||
## User API Changes | ||
## Plugin API Changes | ||
## Bug fixes | ||
## Documentation | ||
## Internal only (Copy into the PR description, rather than the release notes) | ||
-------------------------------------------------------------------- | ||
""" | ||
) | ||
|
||
|
||
def main() -> None: | ||
args = create_parser().parse_args() | ||
print(instructions(args.new)) | ||
entries = [prepare_sha(sha) for sha in relevant_shas(args.prior)] | ||
print("\n\n".join(entries)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.