From f88eabd99ac2b722b5f97bc0151a5ae1618bac1c Mon Sep 17 00:00:00 2001 From: SafetyQuincyF Date: Thu, 19 Dec 2024 16:55:29 -0800 Subject: [PATCH] fix --- .github/workflows/contributor.yml | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/contributor.yml b/.github/workflows/contributor.yml index d8152877..d6e05d70 100644 --- a/.github/workflows/contributor.yml +++ b/.github/workflows/contributor.yml @@ -20,28 +20,40 @@ jobs: ACTOR: ${{ github.actor }} run: | check_membership() { - local user=$1 - RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ - "https://api.github.com/orgs/$ORG/teams/$TEAM/memberships/$user") - - # Use jq for JSON parsing - if echo "$RESPONSE" | jq -e '.state == "active"' > /dev/null; then + local user=$1 + + # Fetch membership details from GitHub API + RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + "https://api.github.com/orgs/$ORG/teams/$TEAM/memberships/$user") + + # Validate API response and check membership status + if [ -z "$RESPONSE" ]; then + echo "Error: No response received from GitHub API. Please check your token or API settings." >&2 + return 2 + fi + + # Use jq to parse and validate the response + if echo "$RESPONSE" | jq -e '.state == "active"' > /dev/null 2>&1; then echo "$user is a member of the $TEAM team." return 0 - else + elif echo "$RESPONSE" | jq -e '.message == "Not Found"' > /dev/null 2>&1; then + echo "Error: Team or organization not found. Please verify ORG and TEAM names." >&2 + return 2 + else echo "$user is NOT a member of the $TEAM team." return 1 - fi + fi } + # Main logic for checking PR author membership echo "Checking PR author: $PR_AUTHOR" if check_membership "$PR_AUTHOR"; then - echo "proceed=true" >> $GITHUB_ENV + echo "proceed=true" >> $GITHUB_ENV else - echo "proceed=false" >> $GITHUB_ENV - fi + echo "proceed=false" >> $GITHUB_ENV fi + test: needs: check-author if: needs.check-author.outputs.proceed == 'true'