Skip to content

Commit de4fcc9

Browse files
committed
Removes extra step of cli and adds a step that verifes org membership
1 parent eb6e6bd commit de4fcc9

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

.github/workflows/auto-label.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ jobs:
1313
- name: Checkout Repository
1414
uses: actions/checkout@v3
1515

16-
- name: Install GitHub CLI
17-
run: |
18-
sudo apt-get install -y jq
19-
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
20-
echo "deb [signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
21-
sudo apt update && sudo apt install gh -y
22-
2316
- name: Authenticate with GitHub CLI
2417
run: |
2518
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
@@ -33,6 +26,21 @@ jobs:
3326
COMMENT_BODY=$(jq -r '.comment.body' "$GITHUB_EVENT_PATH")
3427
ISSUE_NUMBER=$(jq -r '.issue.number // .pull_request.number' "$GITHUB_EVENT_PATH")
3528
29+
ORG_NAME="devtron-labs"
30+
31+
# checks if the person is authorized to add labels or not
32+
ORG_MEMBERSHIP_STATUS=$(gh api "orgs/$ORG_NAME/members/$COMMENT_AUTHOR" --silent --exit-status)
33+
34+
if [[ $? -ne 0 ]]; then
35+
gh issue comment "$ISSUE_NUMBER" --body "Hi @$COMMENT_AUTHOR, you must be a member of the organization '$ORG_NAME' to add or remove labels."
36+
37+
echo "User '$COMMENT_AUTHOR' is not a member of the organization '$ORG_NAME'. Exiting."
38+
exit 1
39+
fi
40+
41+
echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Adding label"
42+
43+
3644
# Get the existing labels on the issue
3745
EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name')
3846

0 commit comments

Comments
 (0)