Skip to content

Commit 63eceda

Browse files
committed
chore: pr label check
1 parent 5a1cbab commit 63eceda

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: PR Label Check
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, labeled, unlabeled, synchronize]
6+
branches: [main]
7+
8+
permissions:
9+
pull-requests: write
10+
11+
jobs:
12+
check-labels:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const pr = context.payload.pull_request;
19+
const labels = pr.labels;
20+
const prNumber = pr.number;
21+
const owner = context.repo.owner;
22+
const repo = context.repo.repo;
23+
const marker = "<!-- LABEL_CHECK_BOT -->";
24+
25+
if (labels.length === 0) {
26+
const { data: comments } = await github.rest.issues.listComments({
27+
owner, repo, issue_number: prNumber,
28+
});
29+
const existing = comments.filter(
30+
c => c.user?.type === "Bot" && c.body?.includes(marker)
31+
);
32+
if (existing.length === 0) {
33+
await github.rest.issues.createComment({
34+
owner, repo, issue_number: prNumber,
35+
body: `${marker}
36+
⚠️ This PR has no labels. Please add one to help categorize this change.
37+
38+
cc @${pr.user.login}`,
39+
});
40+
}
41+
} else {
42+
const { data: comments } = await github.rest.issues.listComments({
43+
owner, repo, issue_number: prNumber,
44+
});
45+
const botComments = comments.filter(
46+
c => c.user?.type === "Bot" && c.body?.includes(marker)
47+
);
48+
for (const c of botComments) {
49+
await github.rest.issues.deleteComment({
50+
owner, repo, comment_id: c.id,
51+
});
52+
}
53+
}

0 commit comments

Comments
 (0)