-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from dcastil/other/480/make-label-name-in-lab…
…el-workflow-configurable Make label name in label workflow configurable
- Loading branch information
Showing
1 changed file
with
58 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,68 +1,69 @@ | ||
name: Auto Label New Issues, PRs, and Discussions | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
pull_request_target: | ||
types: [opened] | ||
discussion: | ||
types: [created] | ||
issues: | ||
types: [opened] | ||
pull_request_target: | ||
types: [opened] | ||
discussion: | ||
types: [created] | ||
|
||
jobs: | ||
add-label: | ||
runs-on: ubuntu-latest | ||
add-label: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
issues: write | ||
discussions: write | ||
pull-requests: write | ||
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@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO_OWNER: ${{ github.repository_owner }} | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
LABEL_NAME: context-v2 | ||
|
||
- name: Add context-v2 label to new issue | ||
if: github.event_name == 'issues' | ||
run: | | ||
ISSUE_NUMBER=${{ github.event.issue.number }} | ||
gh issue edit "$ISSUE_NUMBER" --add-label "context-v2" | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Add context-v2 label to new PR | ||
if: github.event_name == 'pull_request_target' | ||
run: | | ||
PR_NUMBER=${{ github.event.pull_request.number }} | ||
gh pr edit "$PR_NUMBER" --add-label "context-v2" | ||
- name: Add label to new issue | ||
if: github.event_name == 'issues' | ||
run: | | ||
ISSUE_NUMBER=${{ github.event.issue.number }} | ||
gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL_NAME" | ||
- 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 label to new PR | ||
if: github.event_name == 'pull_request_target' | ||
run: | | ||
PR_NUMBER=${{ github.event.pull_request.number }} | ||
gh pr edit "$PR_NUMBER" --add-label "$LABEL_NAME" | ||
- name: Add context-v2 label to new discussion | ||
uses: octokit/[email protected] | ||
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 | ||
} | ||
} | ||
- 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/$LABEL_NAME --jq '.node_id')" | ||
echo "label_id=$res" >> $GITHUB_OUTPUT | ||
- name: Add label to new discussion | ||
uses: octokit/[email protected] | ||
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 | ||
} | ||
} |