-
Notifications
You must be signed in to change notification settings - Fork 553
feat: Adds Github actions to add the label using slash command #6126
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a133113
adds github actions to add the label
satyampsoni eb6e6bd
modified the actions to use CLI
satyampsoni de4fcc9
Removes extra step of cli and adds a step that verifes org membership
satyampsoni e6cc8b7
Excludes PR related comments
satyampsoni 43efc9e
simplifed token authentication
satyampsoni d5474d3
correct syntax
satyampsoni cca406e
corrected syntax
satyampsoni 67b1c7b
Merge branch 'main' into label
abhibhaw 090e9a8
Merge branch 'main' into label
badal773 2099dea
Merge branch 'main' into label
badal773 da4a624
Merge branch 'main' into label
badal773 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: Devtron-auto-labeller | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
|
|
||
| jobs: | ||
| manage-labels: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Install GitHub CLI | ||
satyampsoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| run: | | ||
| sudo apt-get install -y jq | ||
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | ||
| 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 | ||
| sudo apt update && sudo apt install gh -y | ||
|
|
||
| - name: Authenticate with GitHub CLI | ||
satyampsoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| run: | | ||
| echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token | ||
|
|
||
| - name: Parse and manage labels | ||
| run: | | ||
| set -e | ||
| set -x # Enable debugging | ||
|
|
||
| # 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") | ||
|
|
||
| # Get the existing labels on the issue | ||
| EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name') | ||
|
|
||
| # Add Label | ||
| if [[ "$COMMENT_BODY" =~ ^/([^ ]+)$ ]]; then | ||
| LABEL_NAME="${COMMENT_BODY:1}" | ||
|
|
||
| # check for already existing labels in reppo | ||
| if gh label list --json name -q '.[].name' | grep -q "^$LABEL_NAME$"; then | ||
| # Add the requested label, keeping existing ones intact | ||
| 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." | ||
| fi | ||
| fi | ||
|
|
||
| # 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 | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.