-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First-time contributor github action (#16762)
* First draft of first-time contributor action * Try using the github search api * Minor tweaks
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM debian:stable-slim | ||
|
||
LABEL "name"="First Time Contributor" | ||
LABEL "maintainer"="The WordPress Contributors" | ||
LABEL "version"="1.0.0" | ||
|
||
LABEL "com.github.actions.name"="First Time Contributor" | ||
LABEL "com.github.actions.description"="Assigns the first time contributor label to pull requests" | ||
LABEL "com.github.actions.icon"="award" | ||
LABEL "com.github.actions.color"="green" | ||
|
||
RUN apt-get update && \ | ||
apt-get install --no-install-recommends -y jq curl ca-certificates && \ | ||
apt-get clean -y | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# 1. Get the author and pr number for the pull request. | ||
author=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH) | ||
pr_number=$(jq -r '.number' $GITHUB_EVENT_PATH) | ||
|
||
if [ "$pr_number" = "null" ] || [ "$author" = "null" ]; then | ||
echo "Could not find PR number or author. $pr_number / $author" | ||
exit 78 | ||
fi | ||
|
||
# 2. Fetch the author's commit count for the repo to determine if they're a first-time contributor. | ||
commit_count=$( | ||
curl \ | ||
--silent \ | ||
-H "Accept: application/vnd.github.cloak-preview" \ | ||
"https://github.com/gitapi/search/commits?q=repo:$GITHUB_REPOSITORY+author:$author" \ | ||
| jq -r '.total_count' | ||
) | ||
|
||
# 3. If the response has a commit count of zero, exit early, the author is not a first time contributor. | ||
if [ "$commit_count" != "0" ]; then | ||
echo "Pull request #$pr_number was not created by a first-time contributor ($author)." | ||
exit 78 | ||
fi | ||
|
||
# 4. Assign the 'First Time Contributor' label. | ||
curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"labels":["First-time Contributor"]}' \ | ||
"https://github.com/gitapi/repos/$GITHUB_REPOSITORY/issues/$pr_number/labels" > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters