Skip to content

Instantly share code, notes, and snippets.

@itkrt2y
Created November 29, 2019 03:44
Show Gist options
  • Save itkrt2y/066ee4de3e00cb28e960a9e6a9334869 to your computer and use it in GitHub Desktop.
Save itkrt2y/066ee4de3e00cb28e960a9e6a9334869 to your computer and use it in GitHub Desktop.
Open Pull Request associated with a commit id
#!/bin/sh
# Required: hub, jq
commit=$1
pr=$(hub api graphql -F query="
{
repository(name: \"{repo}\", owner: \"{owner}\") {
commit: object(expression: \"$commit\") {
... on Commit {
associatedPullRequests(first: 1) {
edges {
node {
number
}
}
}
}
}
}
}" | jq '.data.repository.commit.associatedPullRequests.edges[].node.number')
if [ ! -z "$pr" ]; then
hub browse -- pull/$pr
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment