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

VAULT-33693 actions: fix push event PR labels #29476

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 25 additions & 7 deletions .github/actions/metadata/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,33 @@ 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 sha="${{ steps.vault-metadata.outputs.vault-revision }}" -f query='
query($repo: String!, $sha: String!){
repository(name: $repo, owner: "hashicorp") {
commit: object(expression: $sha) {
... 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
Loading