-
Notifications
You must be signed in to change notification settings - Fork 8
49 lines (40 loc) · 1.64 KB
/
pr-title-check.yml
File metadata and controls
49 lines (40 loc) · 1.64 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
name: PR Title Check
on: [pull_request]
permissions:
contents: read
pull-requests: write
jobs:
check-pr-title:
runs-on: ubuntu-latest
steps:
- name: Check PR Title
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Fetch the current PR data
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const title = pr.data.title;
const pattern = /^\[AV-\d+\]\s+[A-Z][A-Za-z\s].+/;
if (!pattern.test(title)) {
const errorMessage = `🚨 PR title "${title}" does not match the required format.
Requirements:
- Must start with [AV-XXXXX] where X is any number of digits
- After the bracket, must start with a Verb (Add, Update, Fix, etc.)
- The Verb must start with an uppercase letter
Expected format: [AV-XXXXX] Verb ...
Example: [AV-98659] Implement Cluster On/Off feature
Valid verbs: Add, Update, Fix, Implement, Remove, Refactor, etc.`;
// Add comment to the PR
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: errorMessage
});
core.setFailed(errorMessage);
}