This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Create dependabot changelogs at release time #15481
Merged
Merged
Changes from 3 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 was deleted.
Oops, something went wrong.
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 @@ | ||
Create dependabot changelogs at release time. |
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
import urllib.request | ||
from os import path | ||
from tempfile import TemporaryDirectory | ||
from typing import Any, List, Optional | ||
from typing import Any, List, Match, Optional, Union | ||
|
||
import attr | ||
import click | ||
|
@@ -233,7 +233,7 @@ def _prepare() -> None: | |
subprocess.check_output(["poetry", "version", new_version]) | ||
|
||
# Generate changelogs. | ||
generate_and_write_changelog(current_version, new_version) | ||
generate_and_write_changelog(synapse_repo, current_version, new_version) | ||
|
||
# Generate debian changelogs | ||
if parsed_new_version.pre is not None: | ||
|
@@ -814,7 +814,7 @@ class VersionSection: | |
|
||
|
||
def generate_and_write_changelog( | ||
current_version: version.Version, new_version: str | ||
repo: Repo, current_version: version.Version, new_version: str | ||
) -> None: | ||
# We do this by getting a draft so that we can edit it before writing to the | ||
# changelog. | ||
|
@@ -827,6 +827,10 @@ def generate_and_write_changelog( | |
new_changes = new_changes.replace( | ||
"No significant changes.", f"No significant changes since {current_version}." | ||
) | ||
new_changes += build_dependabot_changelog( | ||
repo, | ||
current_version, | ||
) | ||
|
||
# Prepend changes to changelog | ||
with open("CHANGES.md", "r+") as f: | ||
|
@@ -841,5 +845,47 @@ def generate_and_write_changelog( | |
os.remove(filename) | ||
|
||
|
||
def build_dependabot_changelog(repo: Repo, current_version: version.Version) -> str: | ||
"""Summarise dependabot commits between `current_version` and `release_branch`. | ||
|
||
Returns an empty string if there have been no such commits; otherwise outputs a | ||
third-level markdown header followed by an unordered list.""" | ||
last_release_commit = repo.tag("v" + str(current_version)).commit | ||
rev_spec = f"{last_release_commit.hexsha}.." | ||
commits = list(git.objects.Commit.iter_items(repo, rev_spec)) | ||
messages = [] | ||
for commit in reversed(commits): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we pass (Err this should have been on the line below this, sorry!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I could see from https://gitpython.readthedocs.io/en/stable/reference.html?highlight=iter_items#git.objects.commit.Commit.iter_items, but maybe it would pass it through to |
||
if commit.author.name == "dependabot[bot]": | ||
message: Union[str, bytes] = commit.message | ||
if isinstance(message, bytes): | ||
message = message.decode("utf-8") | ||
messages.append(message.split("\n", maxsplit=1)[0]) | ||
|
||
if not messages: | ||
print(f"No dependabot commits in range {rev_spec}", file=sys.stderr) | ||
return "" | ||
|
||
messages.sort() | ||
|
||
def replacer(match: Match[str]) -> str: | ||
desc = match.group(1) | ||
number = match.group(2) | ||
return f"* {desc}. ([\\#{number}](https://github.com/matrix-org/synapse/issues/{number}))" | ||
|
||
for i, message in enumerate(messages): | ||
messages[i] = re.sub(r"(.*) \(#(\d+)\)$", replacer, message) | ||
messages.insert(0, "### Dependabot updates\n") | ||
DMRobertson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "\n".join(messages) | ||
|
||
|
||
@cli.command() | ||
@click.argument("since") | ||
def test_dependabot_changelog(since: str) -> None: | ||
"""Test building the dependabot changelog. | ||
|
||
Summarises all dependabot commits between the SINCE tag and the current git HEAD.""" | ||
print(build_dependabot_changelog(git.Repo("."), version.Version(since))) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
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.
Would it make more sense to just give these all a
.bump
extension and handle them as a separate type of changelog file using towncrier?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.
Meaning: get the release script to generate .bump files before it runs towncrier? That's a neat idea!
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.
Not really, no. I mean modify the current thing that creates the newsfragments on GHA to create a
.bump
file instead of a.misc
file. Then update the towncrier config to handle.bump
files and it should all just work by putting them into a separate section at the end? Hopefully...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.
That'd solve the "misc section looks ugly", but I'm really trying to solve "you have to look at the CI for the commit before the changelog".
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.
Ah, well in that case... I'm not sure processing the git log to then make changelog files to then process with towncrier is any better then what you have -- it sounds just more complicated.