Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SafetyQuincyF committed Dec 20, 2024
1 parent 57c6a1f commit f88eabd
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions .github/workflows/contributor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f88eabd

Please sign in to comment.