From 04bd8cc5ceafdb19cd2d0e0ee72fab353c16900d Mon Sep 17 00:00:00 2001 From: jf-cbd Date: Tue, 22 Oct 2024 16:07:47 +0200 Subject: [PATCH] :rocket: Update GitHub actions to improve PR classification --- .github/workflows/action.yml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 46095c66c..70cda2c53 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -10,7 +10,34 @@ jobs: name: Add PR to Combodo Project runs-on: ubuntu-latest steps: - - uses: actions/add-to-project@v1.0.2 + - name: Check if author is a member of the organization + id: check-membership + run: | + ORG="Combodo" + AUTHOR=$(jq -r .pull_request.user.login "$GITHUB_EVENT_PATH") + RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \ + "https://api.github.com/orgs/$ORG/members/$AUTHOR") + if [ "$RESPONSE" == "404" ]; then + echo "project_url=https://github.com/orgs/Combodo/projects/5" >> $GITHUB_ENV + echo "is_member=false" >> $GITHUB_ENV + else + echo "project_url=https://github.com/orgs/Combodo/projects/4" >> $GITHUB_ENV + echo "is_member=true" >> $GITHUB_ENV + + fi + + - name: Add internal tag if member + if: env.is_member == 'true' + run: | + curl -X POST -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/Combodo/combodo-wikit-integration/issues/${{ github.event.pull_request.number }}/labels \ + -d '{"labels":["internal"]}' + env: + is_member: ${{ env.is_member }} + + - name: Add PR to the appropriate project + uses: actions/add-to-project@v1.0.2 with: - project-url: https://github.com/orgs/Combodo/projects/5 - github-token: ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }} + project-url: ${{ env.project_url }} + github-token: ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }} \ No newline at end of file