Skip to content

Commit

Permalink
ci: Add workflow to notify issues for released fixes (#2988)
Browse files Browse the repository at this point in the history
* Add workflow to notify issues for released fixes
  • Loading branch information
provinzkraut authored Jan 15, 2024
1 parent 38b0cb9 commit b9bedbe
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/notify-released-issues.yml
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 .github/workflows/notify_released_issues/get_closed_issues.py
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
34 changes: 34 additions & 0 deletions .github/workflows/notify_released_issues/notify.js
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,
})
}
}
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ jobs:

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

notify-issues:
name: Notify issues
uses: ./.github/workflows/notify-released-issues.yml
with:
release_tag: ${{ github.event.release.tag_name }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repos:
rev: v0.17.1
hooks:
- id: slotscheck
exclude: "test_*|docs"
exclude: "test_*|docs|.github"
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.9.1"
hooks:
Expand Down

0 comments on commit b9bedbe

Please sign in to comment.