Skip to content

Commit

Permalink
VAULT-33693: actions: fix push event PR labels
Browse files Browse the repository at this point in the history
Fix pull request label metadata when triggered `push` event types.
We now use Github's `associatedPullRequests()` connection on the
`Commit` associated with the SHA to resolve the labels.

Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed Jan 31, 2025
1 parent 6a87419 commit b9ded55
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions .github/actions/metadata/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,32 @@ runs:
labels=$(gh api "/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" | jq -erc '. | map(.name)')
else
# We can assume we're being triggered for a 'push' (a merge)
is_draft='false'
# Look up the labels for the pull request that is associated with the last commit. If
# there are none set it as a JSON encoded empty array.
if pr_number=$(gh api "/repos/${{ github.repository }}/commits/${{ github.ref }}/pulls" | jq -erc '.[0].number'); then
if ! labels=$(gh api "/repos/${{ github.repository }}/issues/${pr_number}/labels" | jq -erc '. | map(.name)'); then
labels='[]'
fi
else
# Look up the pull request labels for the PR that is associated with
# the commit. If there are none set it as a JSON encoded empty array.
repo=$(printf ${{ github.repository }} | cut -d "/" -f2)
if ! labels=$(gh api graphql -F repo="$repo" -f query='
query prLabels($repo: String!){
repository(name: $repo, owner: "hashicorp") {
commit: object(expression: "${{ steps.vault-metadata.outputs.vault-revision }}") {
... on Commit {
associatedPullRequests(first:1){
edges{
node{
labels(first: 10) {
nodes {
name
}
}
}
}
}
}
}
}' | jq -erc '.data.repository.commit.associatedPullRequests.edges[0].node.labels.nodes | map(.name)');
then
labels='[]'
fi
fi
Expand Down

0 comments on commit b9ded55

Please sign in to comment.