Skip to content

Commit 8d31115

Browse files
committed
Add a workflow for welcoming first-time contributors
1 parent 995fc73 commit 8d31115

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Comment on first contribution
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pull_request_message:
7+
description: >
8+
The Markdown message to comment when a contributor creates their first
9+
pull request.
10+
type: string
11+
required: false
12+
issue_message:
13+
description: >
14+
The Markdown message to comment when a contributor creates their first
15+
issue.
16+
type: string
17+
required: false
18+
19+
jobs:
20+
comment:
21+
if: >
22+
(
23+
(github.event_name == 'pull_request_target' &&
24+
inputs.pull_request_message) ||
25+
(github.event_name == 'issues' && inputs.issue_message)
26+
) &&
27+
github.event.action == 'opened' &&
28+
contains(
29+
fromJSON('["FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR"]'),
30+
github.event_name == 'issues'
31+
&& github.event.issue.author_association
32+
|| github.event.pull_request.author_association
33+
)
34+
runs-on: ubuntu-latest
35+
permissions:
36+
issues: write
37+
pull-requests: write
38+
steps:
39+
- uses: actions/github-script@v7
40+
env:
41+
# Pass the message via an environment variable rather than
42+
# interpolating to prevent code injection.
43+
message: >-
44+
${{
45+
(github.event_name == 'issues')
46+
&& inputs.issue_message
47+
|| inputs.pull_request_message
48+
}}
49+
with:
50+
script: |
51+
await github.rest.issues.createComment({
52+
issue_number: context.issue.number,
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
body: process.env.message
56+
})

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ pre_build_command: "apt-get update -y -q && apt-get install -y -q example"
7373

7474
macOS and Windows platform support will be available soon.
7575

76+
### Welcome a first-time contributor
77+
78+
This is example of a recommended workflow for creating a comment with the
79+
specified Markdown text when a first-time contributor opens an issue or pull
80+
request:
81+
82+
```yaml
83+
name: Comment on first contribution
84+
85+
on:
86+
pull_request_target:
87+
types: [opened]
88+
issues:
89+
types: [opened]
90+
91+
jobs:
92+
comment:
93+
uses: swiftlang/github-workflows/.github/workflows/comment_on_first_contribution.yml@main
94+
with:
95+
pull_request_message: <Markdown message>
96+
issue_message: <Markdown message>
97+
```
98+
7699
## Running workflows locally
77100

78101
You can run the Github Actions workflows locally using

0 commit comments

Comments
 (0)