Skip to content

Commit fa43335

Browse files
feat(ci): add workflow to remind pull requests to link issues (#1173)
Signed-off-by: undefinedIsMyLife <shinetina169@gmail.com>
1 parent 4f33085 commit fa43335

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = async ({ github, context }) => {
2+
const body = context.payload.pull_request.body || "";
3+
const regex = /\bFixes\s*:?\s*(#\d+)(\s*,\s*#\d+)*/i;
4+
5+
const comments = await github.rest.issues.listComments({
6+
owner: context.repo.owner,
7+
repo: context.repo.repo,
8+
issue_number: context.payload.pull_request.number,
9+
});
10+
11+
const alreadyCommented = comments.data.some(comment =>
12+
comment.body.includes("this is LinkBot")
13+
);
14+
15+
if (alreadyCommented) {
16+
return;
17+
}
18+
19+
if (!regex.test(body)) {
20+
await github.rest.issues.createComment({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
issue_number: context.payload.pull_request.number,
24+
body: [
25+
`Hi @${context.payload.pull_request.user.login}, this is **LinkBot** 👋`,
26+
``,
27+
`Linking pull requests to issues helps us significantly with reviewing pull requests and keeping the repository healthy.`,
28+
``,
29+
`🚨 **This pull request does not have an issue linked.**`,
30+
``,
31+
`Please link an issue using the following format:`,
32+
`- Fixes #123`,
33+
``,
34+
`📖 Guide:`,
35+
`docs/sdk_developers/how_to_link_issues.md`,
36+
``,
37+
`If no issue exists yet, please create one:`,
38+
`docs/sdk_developers/creating_issues.md`,
39+
``,
40+
`Thanks!`
41+
].join('\n')
42+
});
43+
}
44+
};
45+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: PR Missing Linked Issue Reminder
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
check-linked-issue:
13+
runs-on: ubuntu-latest
14+
15+
concurrency:
16+
group: pr-missing-linked-issue-${{ github.event.pull_request.number }}
17+
cancel-in-progress: true
18+
19+
steps:
20+
- name: Harden the runner
21+
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
22+
with:
23+
egress-policy: audit
24+
25+
- name: Checkout repository
26+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
27+
28+
- name: Check PR body for linked issue
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
32+
with:
33+
script: |
34+
const script = require('./.github/scripts/pr_missing_linked_issue.js');
35+
await script({ github, context });

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
99

1010

1111
### Added
12+
- Added a GitHub Actions workflow that reminds contributors to link pull requests to issues.
1213
- Added `__str__` and `__repr__` methods to `AccountInfo` class for improved logging and debugging experience (#1098)
1314
- Added Good First Issue (GFI) management and frequency documentation to clarify maintainer expectations and SDK-level GFI governance.
1415
- Added SDK-level Good First Issue (GFI) guidelines for maintainers to clarify what qualifies as a good first issue.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Creating an issue for your pull request
2+
3+
If your pull request does not yet have an issue:
4+
5+
1. Go to the repository Issues tab
6+
2. Click "New issue"
7+
3. Fill in the issue template with the problem description
8+
4. Assign yourself if applicable
9+
5. Copy the issue number
10+
11+
Then link the issue in your pull request description using:
12+
13+
Fixes #ISSUE_NUMBER
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# How to link an issue to a pull request
2+
3+
To link a pull request to an issue, add one of the following lines
4+
to the **pull request description**:
5+
6+
- Fixes #ISSUE_NUMBER
7+
8+
Example:
9+
10+
Fixes #123
11+
12+
This helps reviewers understand the context of the change and allows
13+
GitHub to automatically manage issue state.

0 commit comments

Comments
 (0)