Skip to content
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 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build-support/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pex_binary(
sources = ['bootstrap_and_deploy_ci_pants_pex.py'],
)

pex_binary(
name="changelog",
sources=["changelog.py"],
)

pex_binary(
name = 'check_banned_imports',
sources = ['check_banned_imports.py'],
Expand Down Expand Up @@ -80,5 +85,3 @@ pex_binary(
name = "packages",
sources = ["packages.py"],
)

python_tests()
Copy link
Contributor Author

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.

109 changes: 109 additions & 0 deletions build-support/bin/changelog.py
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()
122 changes: 0 additions & 122 deletions build-support/bin/release-changelog-helper.sh

This file was deleted.