Skip to content

Commit 17b8183

Browse files
committed
ci: auto-fill PR metadata
1 parent f7945e5 commit 17b8183

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

.github/workflows/pr-metadata.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: pr-metadata
2+
3+
# Keep PR triage fields useful without requiring manual cleanup on every branch.
4+
# This workflow only updates PR metadata; it never checks out or executes PR code.
5+
on:
6+
pull_request_target:
7+
types: [opened, reopened, synchronize, ready_for_review]
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: read
13+
14+
jobs:
15+
triage:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Assign author and label by changed paths
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
const pr = context.payload.pull_request;
23+
const owner = context.repo.owner;
24+
const repo = context.repo.repo;
25+
const issue_number = pr.number;
26+
27+
if (!pr.user?.type?.endsWith('Bot')) {
28+
await github.rest.issues.addAssignees({
29+
owner,
30+
repo,
31+
issue_number,
32+
assignees: [pr.user.login],
33+
});
34+
}
35+
36+
const files = await github.paginate(github.rest.pulls.listFiles, {
37+
owner,
38+
repo,
39+
pull_number: issue_number,
40+
per_page: 100,
41+
});
42+
43+
const labels = new Set();
44+
for (const file of files) {
45+
const path = file.filename;
46+
if (path.startsWith('site/')) labels.add('site');
47+
if (path.startsWith('data/') || path.startsWith('site/public/v1/') || path === 'site/public/openapi.json') labels.add('data');
48+
if (path.startsWith('app/')) labels.add('app');
49+
if (path.startsWith('.github/workflows/')) labels.add('ci');
50+
if (path.startsWith('docs/') || path === 'README.md' || path.endsWith('.md')) labels.add('documentation');
51+
}
52+
53+
if (labels.size) {
54+
await github.rest.issues.addLabels({
55+
owner,
56+
repo,
57+
issue_number,
58+
labels: [...labels],
59+
});
60+
}

0 commit comments

Comments
 (0)