Skip to content

Added GitHub Action that adds context-v2 label to every issue, discussion and PR #434

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 2 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
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
71 changes: 71 additions & 0 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Auto Label New Issues, PRs, and Discussions

on:
issues:
types: [opened]
pull_request:
types: [opened]
discussion:
types: [created]

jobs:
add-label:
runs-on: ubuntu-latest

permissions:
issues: write
discussions: write
pull-requests: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Add context-v2 label to new issue
id: label-issue
if: github.event_name == 'issues'
run: |
ISSUE_NUMBER=${{ github.event.issue.number }}
gh issue edit "$ISSUE_NUMBER" --add-label "context-v2"

- name: Add context-v2 label to new PR
id: label-pr
if: github.event_name == 'pull_request'
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
gh pr edit "$PR_NUMBER" --add-label "context-v2"

- name: Get label id for discussion
id: label-data
if: github.event_name == 'discussion'
run: |
res="$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$REPO_OWNER/$REPO_NAME/labels/context-v2 --jq '.node_id')"
echo "label_id=$res" >> $GITHUB_OUTPUT

- name: Add context-v2 label to new discussion
uses: octokit/[email protected]
id: lable-discussion
if: github.event_name == 'discussion'
env:
DISCUSSION_ID: ${{ github.event.discussion.node_id }}
LABEL_ID: ${{ steps.label-data.outputs.label_id }}
with:
query: |
mutation {
addLabelsToLabelable(
input:{
labelableId: "${{env.DISCUSSION_ID}}"
labelIds: ["${{ env.LABEL_ID}}"]
}
) {
clientMutationId
}
}
Loading