made necessary changes #1
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
name: Add Tags to PRs for New Contributors | |
on: | |
pull_request: | |
types: | |
- opened | |
jobs: | |
add_tags: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if contributor is new | |
id: check_new_contributor | |
run: | | |
contributor_username=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH) | |
labels=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${GITHUB_REPOSITORY}/contributors?anon=true") | |
if [[ $(echo $labels | jq --arg contributor "$contributor_username" \ | |
'.[] | select(.login==$contributor)') == "" ]]; then | |
echo "New contributor detected." | |
echo "::set-output name=new_contributor::true" | |
else | |
echo "Existing contributor." | |
echo "::set-output name=new_contributor::false" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Add tags for new contributors | |
if: steps.check_new_contributor.outputs.new_contributor == 'true' | |
run: | | |
pr_number=$(jq -r '.pull_request.number' $GITHUB_EVENT_PATH) | |
tag_name="new-contributor" | |
curl -X POST -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-d "{\"labels\":[\"$tag_name\"]}" \ | |
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/$pr_number/labels" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |