Skip to content

Commit df9bb53

Browse files
committed
Add PR labeler workflow to label PRs modifying workflows
1 parent abde333 commit df9bb53

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: PR Labeler
2+
3+
on:
4+
pull_request_target:
5+
paths:
6+
- ".github/workflows/**"
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
label-workflow-changes:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- name: Label PR with workflow changes
16+
uses: actions/github-script@v6
17+
with:
18+
script: |
19+
const labelName = 'workflow-modified';
20+
21+
// Check if the label exists
22+
try {
23+
const labels = await github.rest.issues.listLabelsForRepo({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo
26+
});
27+
28+
const labelExists = labels.data.some(label => label.name === labelName);
29+
30+
if (!labelExists) {
31+
// Create the label if it doesn't exist
32+
await github.rest.issues.createLabel({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
name: labelName,
36+
color: '#f9d0c4',
37+
description: 'This PR modifies GitHub Actions workflows'
38+
});
39+
console.log(`Label "${labelName}" created`);
40+
} else {
41+
console.log(`Label "${labelName}" already exists`);
42+
}
43+
} catch (error) {
44+
console.error(`Failed to check or create label: ${error.message}`);
45+
throw error;
46+
}
47+
48+
// Add the label to the PR
49+
await github.rest.issues.addLabels({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
labels: [labelName]
54+
});
55+
console.log(`Label "${labelName}" added to the PR.`);

0 commit comments

Comments
 (0)