forked from sofa-framework/sofa
-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (40 loc) · 1.45 KB
/
pr-timing-checker.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
name: Check PR Age
on:
pull_request:
types:
- synchronize
- opened
- reopened
- labeled
- unlabeled
jobs:
check_labels:
name: Check labels
runs-on: ubuntu-latest
steps:
- name: Check Labels and Add Age
id: check_labels_and_comment
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get PR labels
const labels = context.payload.pull_request.labels.map(label => label.name);
// Define the fast merge label
const fastMergeFlag = ['pr: fast merge'];
// Check if any label fits fast merge
const isFastMerge = labels.some(label => fastMergeFlag.includes(label));
// If regular PR (not fast merge), check PR age
if (!isFastMerge) {
console.log('is NOT fast merge');
const creationDate = new Date(context.payload.pull_request.created_at);
const currentDate = new Date();
// Check if the PR is more than 7 days old
const daysDiff = Math.floor((currentDate - creationDate) / (1000 * 60 * 60 * 24));
if (daysDiff < 7) {
console.log('is NOT 7');
core.setFailed('Invalid PR label');
}
}
// Add all PR labels in log
console.log('Labels:', labels.join(', '));