-
-
Notifications
You must be signed in to change notification settings - Fork 350
102 lines (90 loc) · 3.06 KB
/
lint-pr.yml
File metadata and controls
102 lines (90 loc) · 3.06 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
name: PR - Lint & Label
on:
pull_request_target:
types:
- opened
- edited
- synchronize
jobs:
lint-and-label:
name: Validate & Auto-label
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: read
steps:
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
i18n
ai
- name: Auto Label PR
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title;
const prNumber = context.payload.pull_request.number;
// Mapping from commit type to label
const typeToLabel = {
'feat': 'feat',
'fix': 'fix',
'docs': 'docs',
'style': 'style',
'refactor': 'refactor',
'perf': 'perf',
'test': 'test',
'build': 'build',
'ci': 'ci',
'chore': 'chore',
'revert': 'revert',
'i18n': 'i18n',
'ai': 'ai'
};
// Extract type from PR title (format: "type: description" or "type(scope): description")
const match = title.match(/^(\w+)(?:\([^)]*\))?(!)?:\s/);
if (match) {
const commitType = match[1];
const hasBreakingMark = match[2] === '!';
const label = typeToLabel[commitType];
// Check for breaking change indicator
const isBreaking = hasBreakingMark || title.toLowerCase().includes('breaking change');
if (label) {
console.log(`Adding label "${label}" to PR #${prNumber} based on type "${commitType}"`);
const labelsToAdd = [label];
// Add breaking-change label if it's a breaking change
if (isBreaking) {
labelsToAdd.push('breaking-change');
console.log(`Also adding "breaking-change" label due to breaking change indicator`);
}
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
console.log(`Successfully added labels: ${labelsToAdd.join(', ')}`);
} catch (error) {
console.error(`Failed to add labels: ${error.message}`);
}
} else {
console.log(`No label mapping found for commit type "${commitType}"`);
}
} else {
console.log(`PR title "${title}" doesn't match conventional commit format`);
}