Repository navigation
134 lines (119 loc) · 5.16 KB
/
Copy pathpr-management.yml
File metadata and controls
134 lines (119 loc) · 5.16 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: PR management
# Two lightweight, no-build jobs that run only on PR metadata (never on PR code),
# mirroring practices from larger OSS projects:
# * contributor-label: tag a PR from a returning community contributor so
# maintainers can see community work at a glance.
# * pr-standards: nudge PR titles toward the conventional-commit format the
# changelog and release notes are built from (non-blocking; comment + label).
# Both skip maintainers listed in .github/TEAM_MEMBERS and all bots.
# pull_request_target is used so the token can label/comment on PRs from forks;
# neither job checks out or executes PR code, so this is safe.
on:
pull_request_target:
types: [opened, edited, synchronize]
permissions:
pull-requests: write
issues: write
jobs:
contributor-label:
# Only needs to run once, when the PR is opened.
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const login = pr.user.login;
if (login.endsWith('[bot]')) return;
// author_association is CONTRIBUTOR only once a prior commit by this
// user has landed in the repo (our authorship-preserving cherry-picks
// count), so this flags returning community contributors and never a
// first-PR author or a maintainer (who reports MEMBER / OWNER).
if (pr.author_association !== 'CONTRIBUTOR') return;
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['contributor'],
});
pr-standards:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const login = pr.user.login;
if (login.endsWith('[bot]')) return;
// Exempt maintainers listed in .github/TEAM_MEMBERS (read from the
// base repo, never from the PR branch).
let members = [];
try {
const { data: file } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: '.github/TEAM_MEMBERS',
});
members = Buffer.from(file.content, 'base64')
.toString()
.split('\n')
.map((l) => l.trim())
.filter(Boolean);
} catch (e) {
// No TEAM_MEMBERS file: treat everyone as a community contributor.
}
if (members.includes(login)) return;
const LABEL = 'needs:title';
const MARKER = '<!-- pr-standards:title -->';
// feat:, fix(scope):, docs (scope):, chore!: ... (conventional commits)
const titleOk = /^(feat|fix|docs|chore|refactor|test|perf|build|ci|style|revert)(\([a-zA-Z0-9 _-]+\))?!?:\s+\S/.test(
pr.title,
);
async function hasLabel() {
const { data } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});
return data.some((l) => l.name === LABEL);
}
if (titleOk) {
if (await hasLabel()) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: LABEL,
}).catch(() => {});
}
return;
}
// Non-conforming title: label it and post one gentle, non-blocking note.
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [LABEL],
});
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});
if (comments.some((c) => c.body && c.body.includes(MARKER))) return;
const body =
MARKER +
'\n' +
`Thanks @${login}! One small thing: our changelog and release notes are ` +
'built from PR titles, so we use the [conventional-commits](https://www.conventionalcommits.org) ' +
'format, for example:\n\n' +
'```\nfix(python): resolve a bare stdlib import correctly\n```\n\n' +
'Prefixes we use: `feat`, `fix`, `docs`, `chore`, `refactor`, `test`, `perf`, `build`, `ci`. ' +
'Editing the PR title clears this automatically. This is just a nudge and does not block review.';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body,
});