-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add workflow to notify issues for released fixes (#2988)
* Add workflow to notify issues for released fixes
- Loading branch information
1 parent
38b0cb9
commit b9bedbe
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
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,32 @@ | ||
name: Notify released issues | ||
on: | ||
workflow_call: | ||
inputs: | ||
release_tag: | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Get released issues | ||
id: get-released-issues | ||
run: | ||
echo "issues=$(python ./.github/workflows/notify_released_issues/get_closed_issues.py ${{ inputs.release_tag }})" >> "$GITHUB_OUTPUT" | ||
|
||
- uses: actions/github-script@v7 | ||
env: | ||
CLOSED_ISSUES: ${{ steps.get-released-issues.outputs.issues }} | ||
with: | ||
script: | | ||
const script = require('./.github/workflows/notify_released_issues/notify.js') | ||
await script({github, context, core}) |
38 changes: 38 additions & 0 deletions
38
.github/workflows/notify_released_issues/get_closed_issues.py
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,38 @@ | ||
from __future__ import annotations | ||
|
||
import itertools | ||
import json | ||
import pathlib | ||
import re | ||
import sys | ||
|
||
__all__ = ( | ||
"find_resolved_issues", | ||
"main", | ||
) | ||
|
||
|
||
def find_resolved_issues(source: str, tag: str) -> list[str]: | ||
version = tag.split("v", maxsplit=1)[-1] | ||
changelog_line = f".. changelog:: {version}" | ||
stop_line = ".. changelog::" | ||
return list( | ||
{ | ||
issue | ||
for line in itertools.takewhile( | ||
lambda l: stop_line not in l, # noqa: E741 | ||
source.split(changelog_line, maxsplit=1)[1].splitlines(), | ||
) | ||
if re.match(r"\s+:issue: [\d ,]+", line) | ||
for issue in re.findall(r"\d+", line) | ||
} | ||
) | ||
|
||
|
||
def main(tag: str) -> str: | ||
source = pathlib.Path("docs/release-notes/changelog.rst").read_text() | ||
return json.dumps(find_resolved_issues(source, tag)) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(main(sys.argv[1])) # noqa: T201 |
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,34 @@ | ||
module.exports = async ({github, context, core}) => { | ||
|
||
const issues = JSON.parse(process.env.CLOSED_ISSUES) | ||
const releaseURL = context.payload.release.url | ||
const releaseName = context.payload.release.name | ||
const baseBody = "A fix for this issue has been released in" | ||
const body = baseBody + ` [${releaseName}](${releaseURL})` | ||
|
||
for (const issueNumber of issues) { | ||
const opts = github.rest.issues.listComments.endpoint.merge({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
}); | ||
|
||
const comments = await github.paginate(opts) | ||
for (const comment of comments) { | ||
if (comment.user.id === 41898282 && comment.body.startsWith(baseBody)) { | ||
await github.rest.issues.deleteComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: comment.id | ||
}) | ||
} | ||
} | ||
|
||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: body, | ||
}) | ||
} | ||
} |
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