-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (89 loc) · 3.34 KB
/
pr-link-check.yml
File metadata and controls
110 lines (89 loc) · 3.34 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
name: PR Issue Link Check
on:
pull_request:
types: [opened, edited]
permissions:
pull-requests: write
issues: read
jobs:
check-issue-link:
runs-on: ubuntu-latest
steps:
- name: Check for linked issue
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const body = pr.body || '';
const title = pr.title || '';
// Check for issue references (Fixes #123, Closes #456, etc.)
const issueKeywords = /\b(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#\d+/gi;
const hasIssueLink = issueKeywords.test(body) || issueKeywords.test(title);
// Also check for standalone issue numbers
const issueNumbers = body.match(/#\d+/g) || [];
if (!hasIssueLink && issueNumbers.length === 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: `⚠️ **No linked issue found**
Please link this PR to an issue using keywords like:
- \`Fixes #123\`
- \`Closes #456\`
- \`Resolves #789\`
This helps us track changes and automatically close related issues when the PR is merged.
If this PR doesn't address a specific issue, please explain the context in the PR description.`
});
} else {
console.log('Issue link found or PR references issues');
}
label-by-files:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Label PR based on changed files
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
// Get list of files changed in PR
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
const labels = new Set();
for (const file of files.data) {
const path = file.filename;
// Add labels based on file paths
if (path.startsWith('plugins/')) {
labels.add('plugin');
// Detect specific plugin
const match = path.match(/plugins\/([^\/]+)\//);
if (match) {
labels.add(`plugin:${match[1]}`);
}
}
if (path.includes('CLAUDE.md') || path.includes('README.md') || path.includes('.md')) {
labels.add('docs');
}
if (path.includes('test') || path.includes('.github/workflows')) {
labels.add('testing');
}
if (path.includes('.github/')) {
labels.add('ci/cd');
}
if (path.includes('marketplace.json')) {
labels.add('marketplace');
}
}
// Add labels if any detected
if (labels.size > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: Array.from(labels)
});
}