-
Notifications
You must be signed in to change notification settings - Fork 82
144 lines (133 loc) · 5.86 KB
/
welcome.yml
File metadata and controls
144 lines (133 loc) · 5.86 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
135
136
137
138
139
140
141
142
143
144
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Purpose: welcome first-time human issue and PR authors.
# Contract: skips bot users and checks existing comments before posting so
# reruns do not create duplicate welcome messages. PR welcomes run from trusted
# pull-request/[0-9]+ branches copied by copy-pr-bot.
name: Welcome First-Time Contributors
on:
issues:
types: [opened]
push:
branches:
- "pull-request/[0-9]+"
workflow_dispatch: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
welcome:
name: Welcome new contributor
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu8
permissions:
issues: write
pull-requests: write
timeout-minutes: 5
steps:
- name: Welcome first-time issue author
if: github.event_name == 'issues'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const author = context.payload.issue.user;
const creator = author.login;
if (author.type === 'Bot' || creator.endsWith('[bot]')) {
return;
}
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
creator,
per_page: 100,
});
const authoredIssues = issues.filter((issue) => !issue.pull_request);
const currentIssue = context.payload.issue;
const earlierIssue = authoredIssues.some((issue) => {
const issueCreated = new Date(issue.created_at).getTime();
const currentCreated = new Date(currentIssue.created_at).getTime();
return issueCreated < currentCreated ||
(issueCreated === currentCreated && issue.number < currentIssue.number);
});
if (!earlierIssue) {
const body = [
`Welcome to NVSentinel, @${creator}! Thanks for opening your first issue.`,
'',
'A maintainer will triage this shortly. In the meantime:',
`- Check the [Contributing Guide](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md) for project conventions`,
`- Browse existing [labels](https://github.com/${context.repo.owner}/${context.repo.repo}/labels) for related topics`,
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
if (!comments.some((comment) => comment.body.includes(body.split('\n')[0]))) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
}
- name: Welcome first-time PR author
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/pull-request/')
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const prNumber = Number(process.env.GITHUB_REF_NAME.replace('pull-request/', ''));
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const author = pr.user;
const creator = author.login;
if (author.type === 'Bot' || creator.endsWith('[bot]')) {
return;
}
const { data: { total_count } } = await github.rest.search.issuesAndPullRequests({
q: `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${creator}`,
});
if (total_count === 1) {
const body = [
`Welcome to NVSentinel, @${creator}! Thanks for your first pull request.`,
'',
'Before review, please ensure:',
`- All commits are signed off per the [DCO](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md)`,
'- CI checks pass',
'- The PR description explains the reason for the change',
'',
'A maintainer will review this soon.',
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
if (!comments.some((comment) => comment.body.includes(body.split('\n')[0]))) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}
}