forked from agentscope-ai/QwenPaw
-
Notifications
You must be signed in to change notification settings - Fork 0
45 lines (41 loc) · 1.57 KB
/
pr-label.yml
File metadata and controls
45 lines (41 loc) · 1.57 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
name: PR Labeler
on:
pull_request_target:
types: [opened]
jobs:
first-time-contributor:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Check if first-time contributor
uses: actions/github-script@v7
with:
script: |
const author = context.payload.pull_request.user.login;
let isFirstTime = false;
try {
const { data: searchResult } = await github.rest.search.issuesAndPullRequests({
q: `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${author} is:closed`,
});
isFirstTime = searchResult.total_count === 0;
if (!isFirstTime) {
core.info(`${author} has ${searchResult.total_count} closed PRs, skipping label`);
}
} catch (err) {
if (err.status === 422 && err.message && err.message.includes('cannot be searched')) {
core.warning(`Search API cannot look up author ${author}, skipping first-time label`);
return;
}
throw err;
}
if (isFirstTime) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['first-time-contributor'],
});
core.info(`Labeled PR #${context.payload.pull_request.number} as first-time-contributor`);
}