返回 DeepSeek-Reasonix
pr-version-label.yml
根目录 / .github / workflows / pr-version-label.yml
1 name: Label PR version
2
3 # Contributors (especially from forks) can't set labels themselves — that needs
4 # triage rights. A PR's version line is fully determined by its base branch, so
5 # this reads base.ref and applies v1/v2/v3 on their behalf. pull_request_target runs
6 # in the base repo's context so it has write access even for fork PRs; it only
7 # reads trusted metadata (the base ref) and never checks out or runs PR code.
8 on:
9 pull_request_target:
10 types: [opened, reopened, edited]
11
12 permissions:
13 pull-requests: write
14
15 concurrency:
16 group: pr-version-${{ github.event.pull_request.number }}
17 cancel-in-progress: true
18
19 jobs:
20 label:
21 runs-on: ubuntu-latest
22 steps:
23 - uses: actions/github-script@v9
24 with:
25 script: |
26 const lineByBase = { v1: 'v1', 'main-v2': 'v2', studio: 'v3' };
27 const lines = Object.values(lineByBase);
28 const base = context.payload.pull_request.base.ref;
29 const label = lineByBase[base] || null;
30 if (!label) {
31 core.info(`Base branch '${base}' isn't a release line; skipping.`);
32 return;
33 }
34 await github.rest.issues.addLabels({
35 ...context.repo,
36 issue_number: context.payload.pull_request.number,
37 labels: [label],
38 });
39 // Drop other line labels if the base was changed after opening.
40 for (const other of lines.filter((l) => l !== label)) {
41 try {
42 await github.rest.issues.removeLabel({
43 ...context.repo,
44 issue_number: context.payload.pull_request.number,
45 name: other,
46 });
47 } catch (e) {
48 core.info(`No ${other} label to remove.`);
49 }
50 }
51
51 lines YAML