diff --git a/.github/workflows/external_pr_labeler.yml b/.github/workflows/external_pr_labeler.yml new file mode 100644 index 000000000000..0be73c9015d8 --- /dev/null +++ b/.github/workflows/external_pr_labeler.yml @@ -0,0 +1,39 @@ +name: External PR labeler + +on: + pull_request_target: +# types: +# - opened + +jobs: + label_prs: + name: Label external PRs + runs-on: ubuntu-latest + permissions: read-all + steps: +# - id: is_member +# name: Check if author is an org member +# run: | +# curl -L \ +# -H "Accept: application/vnd.github+json" \ +# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ +# -H "X-GitHub-Api-Version: 2022-11-28" \ +# https://api.github.com/orgs/uyuni-project/members/${{ github.actor }} + + - id: is_member + name: Check if author is an org member + env: + GH_TOKEN: ${{ secrets.ORG_READ_TOKEN }} + run: | + # The following API call returns 404 if user is not a member of org + # See: https://docs.github.com/rest/orgs/members#check-organization-membership-for-a-user--status-codes + RESULT=`gh api orgs/uyuni-project/members/does_not_exist -i | head -1 | awk '{ print $2 }'` + echo "result=$RESULT" >> "$GITHUB_OUTPUT" + - name: Label the PR + # If not a member of org + if: ${{ steps.is_member.outputs.result == 404 }} + uses: christianvuerings/add-labels@v1 + with: + labels: "external-contrib" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}