-
Notifications
You must be signed in to change notification settings - Fork 173
60 lines (53 loc) · 1.98 KB
/
enforce-linking-issues.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Enforce linking issues
on:
pull_request_target:
types: [opened, edited, labeled]
workflow_call:
defaults:
run:
shell: bash
jobs:
main:
name: Enforce referencing a closing issue
runs-on: ubuntu-latest
steps:
- name: Count closing issue references
id: has-closing-issue
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const query = `query ($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
closingIssuesReferences(first: 100) {
totalCount
}
}
}
}`;
const reply = await github.graphql(query, {
owner: context.repo.owner,
name: context.repo.repo,
number: context.payload.pull_request.number
});
return reply
.repository
.pullRequest
.closingIssuesReferences
.totalCount > 0;
- if: ${{ steps.has-closing-issue.outputs.result != 'true' }}
name: Suggest that the contributor link an issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}
script: |
const login = "${{ github.event.pull_request.user.login }}";
const syntaxUrl = "https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue";
const message = `@${login} If this pull request contains a bugfix or a new feature, then please consider using \`Closes #ISSUE-NUMBER\` [syntax](${syntaxUrl}) to link it to an issue.`
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: message,
});