-
Notifications
You must be signed in to change notification settings - Fork 1.3k
60 lines (53 loc) · 2.49 KB
/
pr-title-check.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: PR Title Check
on:
pull_request_target:
types:
- opened
- edited
- reopened
- ready_for_review
permissions:
pull-requests: write
jobs:
check-pr-title:
if: github.event.pull_request.draft == false
name: Check PR Title
runs-on: ubuntu-latest
steps:
- name: Check PR Title and Manage Review
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const title = context.payload.pull_request.title;
// This should match https://github.com/filecoin-project/lotus/blob/master/README.md#pr-title-conventions
// 202408: Beyond Conventional Commit conventions, we also optionally suport the "scope" outside of paranenthesis for a transitionary period from legacy conventions per https://github.com/filecoin-project/lotus/pull/12340
const pattern = /^(\[skip changelog\]\s)?(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([\w.]+\))?!?:?\s(\w+:)?\s?[a-z].+$/;
if (!pattern.test(title)) {
await github.rest.pulls.createReview({
...context.repo,
pull_number: context.payload.pull_request.number,
body: 'Please update the PR title to match https://github.com/filecoin-project/lotus/blob/master/CONTRIBUTING.md#pr-title-conventions',
event: 'REQUEST_CHANGES'
});
core.setFailed('PR title does not match the required format');
} else if (context.payload.action === 'edited' && context.payload.changes.title) {
// Only proceed with dismissal if the title was just edited
await new Promise(resolve => setTimeout(resolve, 5000)); // 5 second delay
const reviews = await github.rest.pulls.listReviews({
...context.repo,
pull_number: context.payload.pull_request.number
});
const botReview = reviews.data.find(review =>
review.user.type === 'Bot' &&
review.state === 'CHANGES_REQUESTED'
);
if (botReview) {
await github.rest.pulls.dismissReview({
...context.repo,
pull_number: context.payload.pull_request.number,
review_id: botReview.id,
message: 'PR title now matches the required format.'
});
}
}