Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workflow for welcoming first-time contributors #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/comment_on_first_contribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Comment on first contribution

on:
workflow_call:
inputs:
pull_request_message:
description: >
The Markdown message to comment when a contributor creates their first
pull request.
type: string
required: false
issue_message:
description: >
The Markdown message to comment when a contributor creates their first
issue.
type: string
required: false
Comment on lines +6 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide a default message for both? Would avoid every repo to define its own custom message. Maybe even going one step further do we want each repo to customise this really? If so how do you expect them to customise this?


jobs:
comment:
if: >
(
(github.event_name == 'pull_request_target' && inputs.pull_request_message) ||
(github.event_name == 'issues' && inputs.issue_message)
) &&
github.event.action == 'opened' &&
contains(
fromJSON('["FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR"]'),
ahoppen marked this conversation as resolved.
Show resolved Hide resolved
github.event_name == 'issues'
&& github.event.issue.author_association
|| github.event.pull_request.author_association
)
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
env:
# Pass the message via an environment variable rather than
# interpolating to prevent code injection.
message: >-
${{
github.event_name == 'issues'
&& inputs.issue_message
|| inputs.pull_request_message
}}
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.message
})
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,36 @@ pre_build_command: "apt-get update -y -q && apt-get install -y -q example"

macOS and Windows platform support will be available soon.

### Welcome a first-time contributor

This is example of a recommended workflow for creating a comment with the
specified Markdown text when a first-time contributor opens an issue or pull
request:
AnthonyLatsis marked this conversation as resolved.
Show resolved Hide resolved

```yaml
name: Comment on first contribution

on:
pull_request_target:
types: [opened]
issues:
types: [opened]

jobs:
comment:
uses: swiftlang/github-workflows/.github/workflows/comment_on_first_contribution.yml@main
with:
pull_request_message: <Markdown message>
issue_message: <Markdown message>
```

The `pull_request_message` or `issue_message` inputs are optional.
If omitted, comments will not be created on pull requests or issues,
respectively.
If you only want to greet first-time contributors on either pull requests or
issues, adjust the events that cause the workflow to run under the `on` keyword
besides omitting the corresponding input.

## Running workflows locally

You can run the Github Actions workflows locally using
Expand Down