-
Notifications
You must be signed in to change notification settings - Fork 34
171 lines (151 loc) · 4.91 KB
/
prLinter.yml
File metadata and controls
171 lines (151 loc) · 4.91 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: PR Linter
on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
- closed
branches:
- main
jobs:
label:
name: Label
runs-on: ubuntu-latest
steps:
- name: Apply Label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: >-
const prefixes = [
'INFRA:',
'PROVISIONS:',
'RELEASES:',
'DATA:',
'BROKERS:',
'FOUNDATIONS:',
'PROCESSINGS:',
'ORCHESTRATIONS:',
'COORDINATIONS:',
'MANAGEMENTS:',
'AGGREGATIONS:',
'CONTROLLERS:',
'CLIENTS:',
'EXPOSERS:',
'PROVIDERS:',
'BASE:',
'COMPONENTS:',
'VIEWS:',
'PAGES:',
'ACCEPTANCE:',
'INTEGRATIONS:',
'CODE RUB:',
'MINOR FIX:',
'MEDIUM FIX:',
'MAJOR FIX:',
'DOCUMENTATION:',
'CONFIG:',
'STANDARD:',
'DESIGN:',
'BUSINESS:'
];
const pullRequest = context.payload.pull_request;
if (!pullRequest) {
console.log('No pull request context available.');
return;
}
const title = context.payload.pull_request.title;
const existingLabels = context.payload.pull_request.labels.map(label => label.name);
for (const prefix of prefixes) {
if (title.startsWith(prefix)) {
const label = prefix.slice(0, -1);
if (!existingLabels.includes(label)) {
console.log(`Applying label: ${label}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: [label]
});
}
break;
}
}
permissions:
contents: read
pull-requests: write
requireIssueOrTask:
name: Require Issue Or Task Association
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Get PR Information
id: get_pr_info
uses: actions/github-script@v6
with:
script: >2-
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const prOwner = pr.data.user.login || "";
const prBody = pr.data.body || "";
core.setOutput("prOwner", prOwner);
core.setOutput("description", prBody);
console.log(`PR Owner: ${prOwner}`);
console.log(`PR Body: ${prBody}`);
- name: Check For Associated Issues Or Tasks
id: check_for_issues_or_tasks
if: ${{ steps.get_pr_info.outputs.prOwner != 'dependabot[bot]' }}
env:
PR_BODY: ${{ steps.get_pr_info.outputs.description }}
run: >2-
if [[ -z "${PR_BODY:-}" ]]; then
echo "Error: PR description does not contain any links to issue(s)/task(s) (e.g., 'closes #123' / 'closes AB#123' / 'fixes #123' / 'fixes AB#123')."
exit 1
fi
NORMALIZED_PR_BODY=$(printf '%s' "$PR_BODY" | tr '\r\n' ' ' | tr -s ' ')
if printf '%s' "$NORMALIZED_PR_BODY" | grep -Piq "(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s*(\[#[0-9]+\]|#[0-9]+|\[AB#[0-9]+\]|AB#[0-9]+)"; then
echo "Valid PR description."
else
echo "Error: PR description does not contain any links to issue(s)/task(s) (e.g., 'closes #123' / 'closes AB#123' / 'fixes #123' / 'fixes AB#123')."
exit 1
fi
shell: bash
permissions:
contents: read
pull-requests: read
setAuthorAsPrAssignee:
name: Set Author As PR Assignee
runs-on: ubuntu-latest
steps:
- name: Set Author As PR Assignee
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: >
const pr = context.payload.pull_request;
if (!pr) {
console.log('No pull request context available.');
return;
}
const author = pr.user.login;
if (author.endsWith('[bot]')) {
console.log(`Skipping bot author: ${author}`);
return;
}
console.log(`Assigning PR to author: ${author}`);
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
assignees: [author]
});
permissions:
contents: read
issues: write
pull-requests: write