Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed the organisation permissions and adds authorized members.txt #6146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
issue_comment:
types: [created]

permissions:
contents: write
issues: write

jobs:
manage-labels:
Expand All @@ -24,26 +27,23 @@ jobs:
# Extract comment on body and issue number
COMMENT_BODY=$(jq -r '.comment.body' "$GITHUB_EVENT_PATH")
ISSUE_NUMBER=$(jq -r '.issue.number // .pull_request.number' "$GITHUB_EVENT_PATH")
COMMENT_AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")

ORG_NAME="devtron-labs"

AUTHORIZED_MEMBERS=$(cat .github/workflows/members.txt)

# checks if the person is authorized to add labels or not
ORG_MEMBERSHIP_STATUS=$(gh api "orgs/$ORG_NAME/members/$COMMENT_AUTHOR" --silent --exit-status)

if [[ $? -ne 0 ]]; then
gh issue comment "$ISSUE_NUMBER" --body "Hi @$COMMENT_AUTHOR, you must be a member of the organization '$ORG_NAME' to add or remove labels."

echo "User '$COMMENT_AUTHOR' is not a member of the organization '$ORG_NAME'. Exiting."
if ! echo "$AUTHORIZED_MEMBERS" | grep -qw "$COMMENT_AUTHOR"; then
gh issue comment "$ISSUE_NUMBER" --body "Hi @$COMMENT_AUTHOR, you must be an authorized member to add or remove labels."
echo "User '$COMMENT_AUTHOR' is not authorized to add or remove labels. Exiting."
exit 1
fi

echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Adding label"
echo "User '$COMMENT_AUTHOR' is an authorized member."


# Get the existing labels on the issue
# Get the existing labels on the issue
EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name')

# Add Label
# Add label
if [[ "$COMMENT_BODY" =~ ^/([^ ]+)$ ]]; then
LABEL_NAME="${COMMENT_BODY:1}"

Expand All @@ -53,19 +53,19 @@ jobs:
gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL_NAME"
echo "Successfully added label '$LABEL_NAME' to issue #$ISSUE_NUMBER."
else
echo "The label '$LABEL_NAME' doesn't exist in the repository. You may need to create a label first."
echo "The label '$LABEL_NAME' doesn't exist in the repository.You may need to create a label first."
fi
fi

# Remove Label Logic
# Remove Label logic
if [[ "$COMMENT_BODY" =~ ^/remove[[:space:]](.+)$ ]]; then
LABEL_NAME_TO_REMOVE=$(echo "$COMMENT_BODY" | sed -n 's|/remove ||p')

# Remove the specified label
# Remove the specified label
if echo "$EXISTING_LABELS" | grep -q "^$LABEL_NAME_TO_REMOVE$"; then
gh issue edit "$ISSUE_NUMBER" --remove-label "$LABEL_NAME_TO_REMOVE"
echo "Successfully removed label '$LABEL_NAME_TO_REMOVE' from issue #$ISSUE_NUMBER."
else
echo "The label '$LABEL_NAME_TO_REMOVE' is not attached to issue #$ISSUE_NUMBER."
fi
fi
fi
45 changes: 45 additions & 0 deletions .github/workflows/members.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Abhibhaw
Abhinav-26
AbhishekA1509
Ajaydevtron
Akshatsinha007
Aman10000q
Amit24nov2000
Arunjaindev
Ash-exp
Ashokdevtron
ayu-devtron
Badal773
Bhushan-nemade-dt
Deepak-devtron
Elessar1802
Eshankvaish
Gireesh-naidu
Iamayushm
Kamal-devtron
Kartik-579
Kirandevtn
Mayank-devtron
Neha130
Nishant-d
Nitish6660
Pawan-59
Pawan-mehta-dt
Pghildiyal
Prakarsh-dt
Prakash100198
Prkhrkat
RajeevRanjan27
RohitRaj011
rupinSec
satyampsoni
SATYAsasini
Shivam-nagar23
Shivani170
Systemsdt
Tayalrishabh96
uxarya-d
Vikramdevtron
Vishu247
Vivek-devtron
YashasviDevtron
Loading