Skip to content

Commit b7ada49

Browse files
added the token that contains the permissions to read the org members (#6164)
Co-authored-by: Abhibhaw Asthana <[email protected]>
1 parent 5929632 commit b7ada49

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

.github/workflows/auto-label.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
issue_comment:
55
types: [created]
66

7-
87
jobs:
98
manage-labels:
109
if: ${{ !github.event.issue.pull_request }}
@@ -16,40 +15,37 @@ jobs:
1615

1716
- name: Parse and manage labels
1817
env:
19-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
GH_TOKEN: ${{ secrets.ORG_MEMBERSHIP_SECRET }}
2019
run: |
2120
set -e
2221
set -x # Enable debugging
2322
24-
# Extract comment on body and issue number
23+
# Extract comment body, issue number, and author
2524
COMMENT_BODY=$(jq -r '.comment.body' "$GITHUB_EVENT_PATH")
2625
ISSUE_NUMBER=$(jq -r '.issue.number // .pull_request.number' "$GITHUB_EVENT_PATH")
26+
COMMENT_AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
2727
28-
ORG_NAME="devtron-labs"
29-
30-
# checks if the person is authorized to add labels or not
31-
ORG_MEMBERSHIP_STATUS=$(gh api "orgs/$ORG_NAME/members/$COMMENT_AUTHOR" --silent --exit-status)
28+
ORG_NAME="satyam-tests"
3229
30+
# Check if the person is authorized to add labels
31+
curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/orgs/$ORG_NAME/members/$COMMENT_AUTHOR" > /dev/null
3332
if [[ $? -ne 0 ]]; then
3433
gh issue comment "$ISSUE_NUMBER" --body "Hi @$COMMENT_AUTHOR, you must be a member of the organization '$ORG_NAME' to add or remove labels."
35-
3634
echo "User '$COMMENT_AUTHOR' is not a member of the organization '$ORG_NAME'. Exiting."
3735
exit 1
3836
fi
3937
40-
echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Adding label"
41-
38+
echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Proceeding with label management."
4239
43-
# Get the existing labels on the issue
40+
# Get the existing labels on the issue
4441
EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name')
4542
46-
# Add Label
43+
# Add Label Logic
4744
if [[ "$COMMENT_BODY" =~ ^/([^ ]+)$ ]]; then
4845
LABEL_NAME="${COMMENT_BODY:1}"
4946
50-
# check for already existing labels in reppo
47+
# Check if the label exists in the repository
5148
if gh label list --json name -q '.[].name' | grep -q "^$LABEL_NAME$"; then
52-
# Add the requested label, keeping existing ones intact
5349
gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL_NAME"
5450
echo "Successfully added label '$LABEL_NAME' to issue #$ISSUE_NUMBER."
5551
else

0 commit comments

Comments
 (0)