see. あるcommitが含まれるPullRequestをシェルから開く
git-find-pr.sh <commit>
or
git find-pr
| [alias] | |
| find-pr = "!git-find-pr.sh $(git log --oneline | fzf | awk '{ print $1 }') " |
see. あるcommitが含まれるPullRequestをシェルから開く
git-find-pr.sh <commit>
or
git find-pr
| #!/bin/sh | |
| # | |
| # あるcommitが含まれるPullRequestをシェルから開く https://zenn.dev/nekoya/articles/5cf5037c8d23b3 | |
| # ...をちょっと修正 | |
| # | |
| # Usage: find-pr.sh <commit> | |
| default_branch=$(git symbolic-ref --short refs/remotes/origin/HEAD | awk -F '/' '{print $NF}') | |
| pr_number=$(git log --merges --ancestry-path --oneline "$1".."$default_branch" | grep -i 'merge pull request' | tail -1 | awk '{print $5}' | cut -d# -f2) | |
| if [ -z "$pr_number" ]; then | |
| echo "PR番号が見つからんかったわ。" | |
| exit 1 | |
| fi | |
| repo_url=$(git remote get-url origin | sed -E 's/^.+@github\.com[:\/](.*).git/https:\/\/github.com\/\1/') | |
| if [ -z "$repo_url" ]; then | |
| echo "リポジトリのURLが取れんかったわ。" | |
| exit 1 | |
| fi | |
| pr_url="${repo_url}/pull/${pr_number}" | |
| echo "$pr_url" | |
| open "$pr_url" |
see. あるcommitが含まれるPullRequestをシェルから開く