Skip to content
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
1 change: 1 addition & 0 deletions .changes/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
24 changes: 24 additions & 0 deletions .changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,27 @@ Then commit the changelog and the `.changes` directory:
```sh
> git add CHANGELOG.md .changes
```

## Development

The changelog tool is a python project managed by [uv](https://docs.astral.sh/uv/).
While most usage doesn't require worrying about the underlying python code
due to a lack of dependencies, developers must make use of `uv` to lint and
format code before committing.

```sh
> uv sync
> uv run ruff check --fix
> uv run ruff format
> uv run pyright
```

uv will manage keeping a virtual python environment up to date and ensure that the
right versions of these tools is used.

uv can also be used to run scripts:

```sh
> uv sync
> uv run render
```
55 changes: 1 addition & 54 deletions .changes/amend
Original file line number Diff line number Diff line change
@@ -1,60 +1,7 @@
#! /usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from argparse import ArgumentParser

from tool.amend import amend


def main() -> None:
parser = ArgumentParser(
description="""\
Amend recently-introduced changelog entries to include a pull request \
link. This is intended to be run in GitHub as an action, but can be run \
manually by specifying parameters GitHub would otherwise provide in \
environment variables.

This only checks entries that have been staged in the current branch, \
using git to get a list of newly introduced files. If the entry already \
has one or more associated pull requests, it is not amended.""",
)
parser.add_argument(
"-n",
"--pull-request-number",
required=True,
help="The numeric identifier for the pull request.",
)
parser.add_argument(
"-r",
"--repository",
help="""\
The name of the repository, defaulting to 'smithy-lang/smithy'. This is \
provided by GitHub in the GITHUB_REPOSITORY environment variable.""",
)
parser.add_argument(
"-b",
"--base",
help="""\
The name of the base branch to diff against, defaulting to 'main'. This \
is provided by GitHub in the GITHUB_BASE_REF environment variable.""",
)
parser.add_argument(
"-c",
"--review-comment",
action="store_true",
default=False,
help="""\
Instead of amending the local files on disk, post a review comment on the \
PR. This will also post a normal comment if no changelog entry is found.""",
)

args = parser.parse_args()
amend(
base=args.base,
repository=args.repository,
pr_number=args.pull_request_number,
review_comment=args.review_comment,
)
from tool.amend import main


if __name__ == "__main__":
Expand Down
41 changes: 1 addition & 40 deletions .changes/new-change
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
#! /usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from argparse import ArgumentParser

from tool import ChangeType
from tool.new import new_change


def main() -> None:
parser = ArgumentParser(
description="""\
Create a new changelog entry to be staged for the next release. Required \
values not provided on the command line will be prompted for.""",
)
parser.add_argument(
"-t",
"--type",
choices=[t.name.lower() for t in ChangeType],
help="The type of change being logged.",
)
parser.add_argument(
"-d", "--description", type=str, help="A concise description of the change."
)
parser.add_argument(
"-p",
"--pull-requests",
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(
change_type=ChangeType[args.type.upper()],
description=args.description,
pull_requests=args.pull_requests,
repository=args.repository,
)
from tool.new import main


if __name__ == "__main__":
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

44 changes: 44 additions & 0 deletions .changes/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[project]
name = "changelog"
version = "0.1.0"
description = "A staged changelog tool for Smithy."
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[project.scripts]
amend = "tool.amend:main"
render = "tool.render:main"
new-change = "tool.new:main"

[dependency-groups]
lint = [
"ruff>=0.12.3",
"docformatter>=1.7.7",
]
typing = [
"pyright>=1.1.403"
]

[tool.uv]
package = true
required-version = ">=0.7.21"
default-groups = ["lint", "typing"]

[tool.pyright]
typeCheckingMode = "strict"

[tool.docformatter]
recursive = true
black = true

[tool.ruff]
target-version = "py312"

[tool.ruff.lint]
select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "PIE", "RUF", "S", "T", "UP" ]
ignore = [ "T201", "S602", "S324", "S310" ]

[tool.ruff.format]
docstring-code-format = true

43 changes: 1 addition & 42 deletions .changes/render
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
#! /usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from argparse import ArgumentParser

from tool.release import release
from tool.render import render


def main() -> None:
parser = ArgumentParser(
description="""\
Render the changelog as markdown, optionally including pending features \
as a new release.""",
)
release_group = parser.add_argument_group(
"release",
description="""\
These arguments allow for releasing all pending features in the \
next-release folder as a new release. If not set, the exisiting releases \
will be re-rendered.""",
)
release_group.add_argument(
"-v",
"--release-version",
type=str,
help="""\
The version to use for the staged changelog release. If set, all pending \
features will be compiled into a release.""",
)
release_group.add_argument(
"-d",
"--release-date",
type=str,
help="""\
The date of the release in ISO format (e.g. 2024-11-13). If not set, \
today's date, according to your local time zone, will be used.""",
)

args = parser.parse_args()

if args.release_version:
release(args.release_version, args.release_date)

render()
from tool.render import main


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion .changes/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __lt__(self, other: Self) -> bool:
class Change:
type: ChangeType
description: str
pull_requests: list[str] = field(default_factory=list)
pull_requests: list[str] = field(default_factory=list[str])

@classmethod
def from_json(cls, data: dict[str, Any]) -> Self:
Expand Down
52 changes: 52 additions & 0 deletions .changes/tool/amend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
from argparse import ArgumentParser
from pathlib import Path

from . import REPO_ROOT, Change
Expand All @@ -11,6 +12,57 @@
GITHUB_URL = os.environ.get("GITHUB_SERVER_URL", "https://github.com")


def main() -> None:
parser = ArgumentParser(
description="""\
Amend recently-introduced changelog entries to include a pull request \
link. This is intended to be run in GitHub as an action, but can be run \
manually by specifying parameters GitHub would otherwise provide in \
environment variables.

This only checks entries that have been staged in the current branch, \
using git to get a list of newly introduced files. If the entry already \
has one or more associated pull requests, it is not amended.""",
)
parser.add_argument(
"-n",
"--pull-request-number",
required=True,
help="The numeric identifier for the pull request.",
)
parser.add_argument(
"-r",
"--repository",
help="""\
The name of the repository, defaulting to 'smithy-lang/smithy'. This is \
provided by GitHub in the GITHUB_REPOSITORY environment variable.""",
)
parser.add_argument(
"-b",
"--base",
help="""\
The name of the base branch to diff against, defaulting to 'main'. This \
is provided by GitHub in the GITHUB_BASE_REF environment variable.""",
)
parser.add_argument(
"-c",
"--review-comment",
action="store_true",
default=False,
help="""\
Instead of amending the local files on disk, post a review comment on the \
PR. This will also post a normal comment if no changelog entry is found.""",
)

args = parser.parse_args()
amend(
base=args.base,
repository=args.repository,
pr_number=args.pull_request_number,
review_comment=args.review_comment,
)


def amend(
*,
pr_number: str,
Expand Down
9 changes: 4 additions & 5 deletions .changes/tool/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import os
import re
import time
from collections.abc import Generator
from dataclasses import dataclass
from http.client import HTTPResponse
from pathlib import Path
from typing import Generator, Literal, NotRequired, Required, Self, TypedDict
from typing import Literal, NotRequired, Required, Self, TypedDict
from urllib import request
from urllib.error import HTTPError

Expand Down Expand Up @@ -111,8 +112,7 @@ def get_review_comments(
raise ValueError(
f"Expected list body, but found {type(response.body)}: {response.body}"
)
for comment in response.body:
yield comment # type: ignore
yield from response.body # type: ignore


# https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment
Expand Down Expand Up @@ -147,8 +147,7 @@ def get_comments(
raise ValueError(
f"Expected list body, but found {type(response.body)}: {response.body}"
)
for comment in response.body:
yield comment # type: ignore
yield from response.body # type: ignore


@dataclass
Expand Down
Loading
Loading