1
Fork 0

git cpr: work without .git in remote

This commit is contained in:
Alan Faubert 2019-07-15 10:44:08 -04:00
parent 220a38f1ac
commit 3b53702f4f
1 changed files with 2 additions and 2 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash
set -e
[ $# = 1 ]
[[ "$(git remote get-url origin)" =~ [/@]github\.com[/:]([^/:]+)\/([^/]+)\.git$ ]]
read REMOTE BRANCH < <(curl -s -H "Authorization: bearer $(cat "$(dirname "$0")"/github_token)" -X POST -d "{\"query\":\"{ repository(owner: \\\"${BASH_REMATCH[1]}\\\", name: \\\"${BASH_REMATCH[2]}\\\") { pullRequest(number: $1) { headRef { name } headRepository { nameWithOwner } } } }\"}" https://api.github.com/graphql | jq -r '.data.repository.pullRequest | "https://github.com/\(.headRepository.nameWithOwner).git \(.headRef.name)"')
[[ "$(git remote get-url origin)" =~ [/@]github\.com[/:]([^/:]+)\/([^/]+)$ ]]
read REMOTE BRANCH < <(curl -s -H "Authorization: bearer $(cat "$(dirname "$0")"/github_token)" -X POST -d "{\"query\":\"{ repository(owner: \\\"${BASH_REMATCH[1]}\\\", name: \\\"${BASH_REMATCH[2]%.git}\\\") { pullRequest(number: $1) { headRef { name } headRepository { nameWithOwner } } } }\"}" https://api.github.com/graphql | jq -r '.data.repository.pullRequest | "https://github.com/\(.headRepository.nameWithOwner) \(.headRef.name)"')
git fetch $REMOTE $BRANCH:pr/$1
git config branch.pr/$1.remote $REMOTE
git config branch.pr/$1.merge refs/heads/$BRANCH