g backport: fix a temp file leak

And make the pull request query a bit more generic, so this can be
reused for other repos as well.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ic231367bcf50f86b41430b48f752bb05d4e8d25f
pull/834/head
Miklos Vajna 2020-11-27 08:57:17 +01:00
parent 947781ddd6
commit a4becf39ab
1 changed files with 8 additions and 5 deletions

13
g
View File

@ -92,18 +92,21 @@ if [ "$1" == "backport" ]; then
CUSTOM_BRANCH=$4
JSON=$(mktemp)
gh api graphql -f query='
gh api graphql --field owner=":owner" --field repo=":repo" -f query='
query($owner: String!, $repo: String!)
{
repository(owner: "CollaboraOnline", name:"online")
repository(owner: $owner, name: $repo)
{
pullRequest(number: '$PRNUM'){
baseRefOid
headRefOid
pullRequest(number: '$PRNUM')
{
baseRefOid
headRefOid
}
}
}' > $JSON
BASE_COMMIT=$(cat $JSON | jq --raw-output ".data.repository.pullRequest.baseRefOid")
HEAD_COMMIT=$(cat $JSON | jq --raw-output ".data.repository.pullRequest.headRefOid")
rm $JSON
COMMIT_RANGE=$BASE_COMMIT..$HEAD_COMMIT
# Create local branch if needed.