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

Allow multiple summaries per pull request #53

Merged
merged 17 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: test

on: [push, pull_request]

jobs:
pytest:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [ubuntu]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]

- name: Test
run: pytest --cov
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@ ignored_user_logins = [
]

# If this regex matches a pull requests description, the captured content
# is included instead of the pull request title.
# is included instead of the pull request title. The regex is allowed to match
# more than once in which case a single pull request may result in multiple
# items. Each summary can optionally be prefixed with a `Label:` which takes
# precedence over the pull requests labels. This is useful if one pull request
# should be summarized in different sections.
# E.g. the default regex below is matched by
#
# ```release-note
# An ideally expressive description of the change that is included as a single
# bullet point. Newlines are removed.
# Label: An ideally expressive description of the change that is included as
# a single bullet point. Newlines are removed.
# ```
#
# If you modify this regex, make sure to match the content with a capture
# group named "summary".
pr_summary_regex = "^```release-note\\s*(?P<summary>[\\s\\S]*?\\w[\\s\\S]*?)\\s*^```"
pr_summary_regex = "^```release-note\\s*((?P<label>[^:]*):)?(?P<summary>[\\s\\S]*?\\w[\\s\\S]*?)\\s*^```"

# If any of a pull request's labels matches one of the regexes on the left side
# its summary will appear in the appropriate section with the title given on
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "changelist"
version = "0.5rc0.dev0"
# TODO add slots=True, kw_only=True to dataclasses starting with >=3.10
requires-python = ">=3.9"
readme = "README.md"
license = {file = "LICENSE.txt"}
Expand Down Expand Up @@ -33,6 +34,7 @@ changelist = "changelist.__main__:main"

[project.optional-dependencies]
lint = ["pre-commit == 3.5.0"]
test = ["pytest", "pytest-cov"]

[tool.ruff]
line-length = 88
Expand All @@ -46,3 +48,8 @@ select = [
"I",
"UP",
]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--doctest-modules"
testpaths = ["src", "test"]
21 changes: 12 additions & 9 deletions src/changelist/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tqdm import tqdm

from ._config import add_config_defaults, local_config, remote_config
from ._format import MdFormatter, RstFormatter
from ._format import ChangeNote, Contributor, MdFormatter, RstFormatter
from ._query import commits_between, contributors, pull_requests_from_commits

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -152,18 +152,23 @@ def main(
pull_requests=lazy_tqdm(pull_requests, desc="Fetching reviewers"),
)

print("Formatting notes...", file=sys.stderr)
change_notes = ChangeNote.from_pull_requests(
pull_requests,
pr_summary_regex=re.compile(config["pr_summary_regex"], flags=re.MULTILINE),
)

Formatter = {"md": MdFormatter, "rst": RstFormatter}[format]
formatter = Formatter(
repo_name=org_repo.split("/")[-1],
pull_requests=pull_requests,
authors=authors,
reviewers=reviewers,
change_notes=change_notes,
authors=Contributor.from_named_users(authors),
reviewers=Contributor.from_named_users(reviewers),
version=version,
title_template=config["title_template"],
intro_template=config["intro_template"],
outro_template=config["outro_template"],
label_section_map=config["label_section_map"],
pr_summary_regex=re.compile(config["pr_summary_regex"], flags=re.MULTILINE),
ignored_user_logins=config["ignored_user_logins"],
)

Expand All @@ -174,7 +179,5 @@ def main(
io.writelines(formatter.iter_lines())
else:
print()
for line in formatter.iter_lines():
assert line.endswith("\n")
assert line.count("\n") == 1
print(line, end="", file=sys.stdout)
notes = str(formatter)
print(notes, file=sys.stdout)
Loading