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

Label matching #145

Merged
merged 2 commits into from
Feb 5, 2024
Merged
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
86 changes: 86 additions & 0 deletions .github/workflows/match_labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---


name: "Match Labels for Changelog"

"on":
pull_request_target:
branches: [develop, main]
types: [opened, closed]

# Configure the project specific variables
env:
ORGANIZATION: theteamworks
PROJECT_NUMBER: 3
PR_URL: ${{ github.event.pull_request.html_url }}
PR_ID: ${{ github.event.pull_request.node_id }}
GH_TOKEN: ${{ secrets.GH_NEW_CARD_TO_PROJECT }}
USER: ${{ github.actor }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
label-match:
name: "Matches issue labels to PRs"
runs-on: ubuntu-latest
permissions: write-all
steps:

- name: "Get linked issue id and state"
id: linked-issue
env:
GH_TOKEN: ${{ secrets.GH_NEW_CARD_TO_PROJECT }}
run: |
gh api graphql -f query='
query($pr_url: URI!) {
resource(url: $pr_url) {
... on PullRequest {
closingIssuesReferences(last: 1) {
nodes {
id
url
}
}
}
}
}' -f pr_url=$PR_URL > data.json
echo 'LINKED_ISSUE_ID='$(jq '.data.resource.closingIssuesReferences.nodes[] | .id' data.json) >> $GITHUB_ENV
echo 'LINKED_ISSUE_URL='$(jq '.data.resource.closingIssuesReferences.nodes[] | .url' data.json) >> $GITHUB_ENV

- name: "Get issues labels"
id: get-issue-labels
if: |
env.LINKED_ISSUE_ID != ''
run: |
gh api graphql -f query='
resource(url: $issue_url) {
... on Issue {
labels(last: 10) {
nodes {
id
name
}
}
}
}' -f issue_url=$LINKED_ISSUE_URL
echo 'BUG='$(jq '.data.resource.labels.nodes[] | select(.name== "bug") | .id' data.json) >> $GITHUB_ENV
echo 'BREAKING='$(jq '.data.resource.labels.nodes[] | select(.name== "breaking-change") | .id' data.json) >> $GITHUB_ENV
echo 'DEPRECATE='$(jq '.data.resource.labels.nodes[] | select(.name== "deprecation") | .id' data.json) >> $GITHUB_ENV
echo 'VULNERABILITY='$(jq '.data.resource.labels.nodes[] | select(.name== "vulnerability") | .id' data.json) >> $GITHUB_ENV
echo 'ENHANCE='$(jq '.data.resource.labels.nodes[] | select(.name== "enhancement") | .id' data.json) >> $GITHUB_ENV
echo 'FEATURE='$(jq '.data.resource.labels.nodes[] | select(.name== "feature") | .id' data.json) >> $GITHUB_ENV

- name: "Add bug label"
id: check-labels
if: |
env.BUG = true
run: |
gh api graphql -f query='
mutation($user:String!, $pr:ID!) {
addLabelsToLabelable(input: {clientMutationId: $user, labelableId: $pr, labelIds: [env.BUG]}) {
clientMutationId
}
}' -f pr=$PR_ID -f user=$USER

Loading