Skip to content

Commit

Permalink
feat: automate issue linked label (EddieHubCommunity#8581)
Browse files Browse the repository at this point in the history
* automate issue linked label

* check issue assignee matches pr submitter
  • Loading branch information
dan-mba authored Aug 9, 2023
1 parent e80ec69 commit 50075bf
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ name: Label PRs
on:
- pull_request_target

permissions:
contents: read
pull-requests: write

jobs:
label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest

steps:
Expand All @@ -23,3 +24,66 @@ jobs:
dot: true
sync-labels: true

issue-linked:
runs-on: ubuntu-latest

steps:
- uses: octokit/[email protected]
id: get_linked_issue
with:
query: |
query issue($owner:String!,$repo:String!,$pr:Int!) {
repository(owner:$owner,name:$repo) {
pullRequest(number: $pr) {
closingIssuesReferences (first: 1) {
nodes {
number
assignees(first: 1) {
nodes {
login
}
}
}
}
}
}
}
variables: |
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pr: ${{ github.event.pull_request.number}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Count linked issues
id: count_nodes
env:
GH_DETAILS: ${{ steps.get_linked_issue.outputs.data }}
run: |
GH_COUNT=$(echo "$GH_DETAILS" | jq '.repository.pullRequest.closingIssuesReferences.nodes | length')
echo "count=$GH_COUNT" >> "$GITHUB_OUTPUT"
echo "count=$GH_COUNT"
- name: Check assignee count
id: assignee_ct
if: steps.count_nodes.outputs.count > 0
env:
GH_DETAILS: ${{ steps.get_linked_issue.outputs.data }}
run: |
GH_ASSIGNCT=$(echo "$GH_DETAILS" | jq '.repository.pullRequest.closingIssuesReferences.nodes[0].assignees.nodes | length')
echo "count=$GH_ASSIGNCT" >> "$GITHUB_OUTPUT"
echo "count=$GH_ASSIGNCT"
- name: Check assignee
id: assignee
if: steps.count_nodes.outputs.count > 0 && steps.assignee_ct.outputs.count > 0
env:
GH_DETAILS: ${{ steps.get_linked_issue.outputs.data }}
run: |
GH_ASSIGN=$(echo "$GH_DETAILS" | jq -r '.repository.pullRequest.closingIssuesReferences.nodes[0].assignees.nodes[0].login')
echo "name=$GH_ASSIGN" >> "$GITHUB_OUTPUT"
echo "name=$GH_ASSIGN"
echo "${{ github.actor }}"
- name: Add issue-linked label
if: steps.count_nodes.outputs.count > 0 && steps.assignee_ct.outputs.count > 0 && github.actor == steps.assignee.outputs.name
run: |
gh pr edit ${{ github.event.pull_request.number}} --add-label 'issue linked' --repo $GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 50075bf

Please sign in to comment.