I use git browse
a lot. If there's an existing PR for this branch, github will show it in a button, e.g.:
Is there was a way to have browse
or similar to go directly to the PR url, if exists?
If not, does this sound like a good idea for a feature?
This would be welcome! See #1451 #1107 #897 #867. Closing due to duplicate.
There is already a hub pr
subcommand in master branch. Maybe there could be a hub pr open
command for this? I don't want to extend the hub browse
command further because I want to deprecate it.
Coming soon to a hub near you 馃槃
any updates on the hub pr show
mentioned above?
@eibrahim No, but you can list open PRs for the current branch using hub api
and a shell script like the following:
existing-pr() {
local branch
if branch="$(git rev-parse --symbolic-full-name @{upstream} 2>/dev/null)"; then
branch="${branch#refs/remotes/}"
branch="${branch#*/}"
else
branch="$(git rev-parse --symbolic-full-name HEAD)"
branch="${branch#refs/heads/}"
fi
hub api -t graphql -fbranch="$branch" -fquery='
query($branch: String!) {
repository(owner: "{owner}", name: "{repo}") {
pullRequests(headRefName: $branch, states: OPEN, first: 10) {
edges {
node {
url
repository {
owner {
login
}
}
headRepository {
owner {
login
}
}
}
}
}
}
}
' | group_edges 3 | while read -r url base_owner head_owner; do
[ "$base_owner" != "$head_owner" ] || printf '%s\n' "$url"
done | head -1
}
group_edges() {
grep -F '[' | cut -f2 | xargs -L${1?}
}
existing-pr
It might look complicated, but in reality it's straightforward: it detects the current branch (taking into account upstream configuration), then lists the URLs to PRs that have the current branch as the "head" branch, _excluding_ PRs that come from forks.
Looks like hub pr show
is in!
Many thanks!
Most helpful comment
Coming soon to a hub near you 馃槃