-
-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite changelog helper to Python and use markdown for changelog #11224
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was already a python_tests target with default globs.