Skip to content

Commit

Permalink
Use consistent phrasing in changelog tool
Browse files Browse the repository at this point in the history
This updates naming of variables and extension points to be
consistent across the changelog tools.
  • Loading branch information
JordonPhillips committed Nov 13, 2024
1 parent cb6dd31 commit 80223ce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
12 changes: 11 additions & 1 deletion .changes/new-change
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ def main() -> None:
nargs="*",
help="The pull request that implements the change.",
)
parser.add_argument(
"-r",
"--repository",
help="The name of the repository, defaulting to 'smithy-lang/smithy'.",
)

args = parser.parse_args()
new_change(ChangeType[args.type.upper()], args.description, args.pull_requests)
new_change(
change_type=ChangeType[args.type.upper()],
description=args.description,
pull_requests=args.pull_requests,
repository=args.repository,
)


if __name__ == "__main__":
Expand Down
20 changes: 12 additions & 8 deletions .changes/tool/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,31 @@
pull request: {pull_requests}
# A brief description of the change. You can use GitHub style references to issues such
# as "fixes #489", "boto/boto3#100", etc. These will get automatically replaced with
# the correct link.
# as "fixes #489", "smithy-lang/smithy#100", etc. These will get automatically replaced
# with the correct link.
description: {description}
"""


def new_change(
change_type: ChangeType | None,
description: str | None,
pull_requests: list[str] | None,
change_type: ChangeType | None = None,
description: str | None = None,
pull_requests: list[str] | None = None,
repository: str | None = None,
):
if change_type is not None and description is not None:
change = Change(type=change_type, description=description)
if pull_requests:
change.pull_requests = pull_requests
else:
print("Missing required parameters, prompting for what remains")
parsed = get_values_from_editor(change_type, description, pull_requests)
if not parsed:
return
change = parsed

write_new_change(change)
repository = repository or "smithy-lang/smithy"
write_new_change(change, repository)


def get_values_from_editor(
Expand Down Expand Up @@ -89,10 +92,12 @@ def linkify(match: re.Match[str]):
]


def write_new_change(change: Change):
def write_new_change(change: Change, repo_name: str):
if not NEXT_RELEASE_DIR.is_dir():
os.makedirs(NEXT_RELEASE_DIR)

replace_issue_references(change, repo_name)

contents = change.write()
contents_digest = hashlib.sha1(contents.encode("utf-8")).hexdigest()
filename = f"{change.type.name.lower()}-{contents_digest}.json"
Expand All @@ -102,7 +107,6 @@ def write_new_change(change: Change):


def parse_filled_in_contents(contents: str) -> Change | None:
"""Parse filled in file contents and returns parsed dict."""
if not contents.strip():
return

Expand Down
18 changes: 12 additions & 6 deletions .changes/tool/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@


def release(version: str, release_date: str | None) -> None:
print("Gathering staged changes for release")
release_date = release_date or date.today().isoformat()
entries: list[Change] = []
changes: list[Change] = []
for entry in NEXT_RELEASE_DIR.glob("*.json"):
entries.append(Change.read(entry))
print(f"Found staged changelog entry: {entry}")
changes.append(Change.read(entry))
entry.unlink()

if not entries:
if not changes:
raise ValueError(
"To conduct a release, there must be at least one changelog entry."
"""\
To conduct a release, there must be at least one staged changelog entry \
in the next-release folder."""
)

result = Release(version=version, date=release_date, changes=entries)
result = Release(version=version, date=release_date, changes=changes)

if not RELEASES_DIR.is_dir():
os.makedirs(RELEASES_DIR)

result.write(RELEASES_DIR / f"{version}.json")
release_file = RELEASES_DIR / f"{version}.json"
print(f"Writing combined release to {release_file}")
result.write(release_file)
2 changes: 1 addition & 1 deletion .changes/tool/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
from . import RELEASES_DIR, Change, Release

TITLE = "Smithy Changelog"
TITLE = "Changelog"


def render() -> None:
Expand Down

0 comments on commit 80223ce

Please sign in to comment.