Skip to content

Commit

Permalink
Hide issue/PR list on backports (#206)
Browse files Browse the repository at this point in the history
* Hide issue/PR list on backports

* Fix tests? Stop running CI on non-master branch commits

* Ok that clearly didn't work

* Ahhh

Python dev on Mac is weird so here we are, pushing one-liners

* fixup rebase

* tryfix

* add test

---------

Co-authored-by: Ian Butterworth <[email protected]>
  • Loading branch information
christopher-dG and IanButterworth authored Aug 22, 2024
1 parent b412dc9 commit 7d86458
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Run Tests
on:
- push
- pull_request
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,28 @@ inputs:
{{ custom }}
{% endif %}
{% if backport %}
This release has been identified as a backport.
Automated changelogs for backports tend to be wildly incorrect.
Therefore, the list of issues and pull requests is hidden.
<!--
{% endif %}
{% if pulls %}
**Merged pull requests:**
{% for pull in pulls %}
- {{ pull.title }} (#{{ pull.number }}) (@{{ pull.author.username }})
{% endfor %}
{% endif %}
{% if issues %}
**Closed issues:**
{% for issue in issues %}
- {{ issue.title }} (#{{ issue.number }})
{% endfor %}
{% endif %}
{% if backport %}
-->
{% endif %}
changelog_ignore:
description: Labels for issues and pull requests to be ignored (comma-delimited)
Expand Down
17 changes: 17 additions & 0 deletions tagbot/action/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def _previous_release(self, version_tag: str) -> Optional[GitRelease]:
prev_ver = ver
return prev_rel

def _is_backport(self, version: str) -> bool:
"""Determine whether or not the version is a backport."""
cur_ver = VersionInfo.parse(version[1:])
for r in self._repo._repo.get_releases():
if not r.tag_name.startswith("v"):
continue
try:
ver = VersionInfo.parse(r.tag_name[1:])
except ValueError:
continue
if ver.prerelease or ver.build:
continue
if ver > cur_ver:
return True
return False

def _issues_and_pulls(
self, start: datetime, end: datetime
) -> List[Union[Issue, PullRequest]]:
Expand Down Expand Up @@ -189,6 +205,7 @@ def _collect_data(self, version_tag: str, sha: str) -> Dict[str, object]:
return {
"compare_url": compare,
"custom": self._custom_release_notes(version_tag),
"backport": self._is_backport(version_tag),
"issues": [self._format_issue(i) for i in issues],
"package": self._repo._project("name"),
"previous_release": prev_tag,
Expand Down
55 changes: 55 additions & 0 deletions test/action/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def test_collect_data():
None,
]
)
c._is_backport = Mock(return_value=False)
commit = Mock(author=Mock(date=datetime.now(timezone.utc)))
c._repo._repo.get_commit = Mock(return_value=Mock(commit=commit))
# TODO: Put stuff here.
Expand All @@ -226,6 +227,7 @@ def test_collect_data():
assert c._collect_data("v1.2.3", "abcdef") == {
"compare_url": "https://github.com/A/B.jl/compare/v1.2.2...v1.2.3",
"custom": "custom",
"backport": False,
"issues": [],
"package": "B",
"previous_release": "v1.2.2",
Expand Down Expand Up @@ -261,6 +263,59 @@ def test_render():
data = {
"compare_url": "https://github.com/Me/PkgName.jl/compare/v1.2.2...v1.2.3",
"custom": "Custom release notes",
"backport": False,
"issues": [{"number": 1, "title": "Issue title", "labels": []}],
"package": "PkgName",
"previous_release": "v1.2.2",
"pulls": [
{
"number": 3,
"title": "Pull title",
"labels": [],
"author": {"username": "author"},
},
],
"version": "v1.2.3",
"version_url": "https://github.com/Me/PkgName.jl/tree/v1.2.3",
}
assert c._render(data) == textwrap.dedent(expected).strip()
del data["pulls"]
assert "**Merged pull requests:**" not in c._render(data)
del data["issues"]
assert "**Closed issues:**" not in c._render(data)
data["previous_release"] = None
assert "Diff since" not in c._render(data)


def test_render_backport():
path = os.path.join(os.path.dirname(__file__), "..", "..", "action.yml")
with open(path) as f:
action = yaml.safe_load(f)
default = action["inputs"]["changelog"]["default"]
c = _changelog(template=default)
expected = """
## PkgName v1.2.3
[Diff since v1.2.2](https://github.com/Me/PkgName.jl/compare/v1.2.2...v1.2.3)
Custom release notes
This release has been identified as a backport.
Automated changelogs for backports tend to be wildly incorrect.
Therefore, the list of issues and pull requests is hidden.
<!--
**Merged pull requests:**
- Pull title (#3) (@author)
**Closed issues:**
- Issue title (#1)
-->
"""
data = {
"compare_url": "https://github.com/Me/PkgName.jl/compare/v1.2.2...v1.2.3",
"custom": "Custom release notes",
"backport": True,
"issues": [{"number": 1, "title": "Issue title", "labels": []}],
"package": "PkgName",
"previous_release": "v1.2.2",
Expand Down

0 comments on commit 7d86458

Please sign in to comment.