4
4
issue_comment :
5
5
types : [created]
6
6
7
-
8
7
jobs :
9
8
manage-labels :
10
9
if : ${{ !github.event.issue.pull_request }}
@@ -16,40 +15,37 @@ jobs:
16
15
17
16
- name : Parse and manage labels
18
17
env :
19
- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
18
+ GH_TOKEN : ${{ secrets.ORG_MEMBERSHIP_SECRET }}
20
19
run : |
21
20
set -e
22
21
set -x # Enable debugging
23
22
24
- # Extract comment on body and issue number
23
+ # Extract comment body, issue number, and author
25
24
COMMENT_BODY=$(jq -r '.comment.body' "$GITHUB_EVENT_PATH")
26
25
ISSUE_NUMBER=$(jq -r '.issue.number // .pull_request.number' "$GITHUB_EVENT_PATH")
26
+ COMMENT_AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
27
27
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"
32
29
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
33
32
if [[ $? -ne 0 ]]; then
34
33
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
-
36
34
echo "User '$COMMENT_AUTHOR' is not a member of the organization '$ORG_NAME'. Exiting."
37
35
exit 1
38
36
fi
39
37
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."
42
39
43
- # Get the existing labels on the issue
40
+ # Get the existing labels on the issue
44
41
EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name')
45
42
46
- # Add Label
43
+ # Add Label Logic
47
44
if [[ "$COMMENT_BODY" =~ ^/([^ ]+)$ ]]; then
48
45
LABEL_NAME="${COMMENT_BODY:1}"
49
46
50
- # check for already existing labels in reppo
47
+ # Check if the label exists in the repository
51
48
if gh label list --json name -q '.[].name' | grep -q "^$LABEL_NAME$"; then
52
- # Add the requested label, keeping existing ones intact
53
49
gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL_NAME"
54
50
echo "Successfully added label '$LABEL_NAME' to issue #$ISSUE_NUMBER."
55
51
else
0 commit comments