Skip to content

Improve token service graphql queries #182

Improve token service graphql queries

Improve token service graphql queries #182

Workflow file for this run

name: On PR Closed - Copy Issue Labels
on:
pull_request:
types:
- closed
jobs:
copy-labels:
name: Copy linked issue labels
runs-on: ubuntu-latest
steps:
- name: copy labels
env:
GITHUB_TOKEN: ${{ secrets.GH_CLI_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
run: |
org=${{ github.repository_owner }}
repo=psibase
pr_number=$PR_NUMBER
issue_number=$(gh api graphql -F owner="$org" -F repo="$repo" -F pr=$pr_number -f query='
query ($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
closingIssuesReferences(first: 1) {
nodes {
number
}
}
}
}
}' --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[].number')
if [ -z "${issue_number}" ]; then
echo "No issue linked to this PR"
exit 0
fi
labels=$(gh api "repos/$org/$repo/issues/$issue_number/labels" --jq 'map(.name) | join(",")')
if [ -z "${labels}" ]; then
echo "No labels on linked issue"
exit 0
fi
json_labels="[\"$(echo "$labels" | sed 's/,/","/g')\"]"
echo "{\"labels\":$json_labels}" > input.json
gh api "repos/$org/$repo/issues/$pr_number/labels" -X POST --input input.json
rm input.json