Skip to content

Instantly share code, notes, and snippets.

@42milez
Last active December 12, 2017 08:59
Show Gist options
  • Save 42milez/8179683638be13cffc4e5f3b84737c6f to your computer and use it in GitHub Desktop.
Save 42milez/8179683638be13cffc4e5f3b84737c6f to your computer and use it in GitHub Desktop.
This script reveals the pull requests which contain the unmerged commits between two branches.
#!/usr/bin/env bash
url_prefix='https://github.com/USER_NAME/REPOSITORY_NAME/pull/'
src_branch='branch-a'
dest_branch='branch-b'
pull_requests=()
# 1. Find the commit hashes which are only included in dest_branch.
# 2. Search the pull requests which contain the commit hashes.
for commit_hash in $(git log --no-merges --right-only $src_branch..$dest_branch | grep -Eo ' [a-f0-9]+$')
do
# Find only merge logs to reveal the pull request number
pr=`git log --merges --oneline --reverse --ancestry-path $commit_hash...$dest_branch |
grep 'Merge pull request #' |
head -n 1 |
cut -f5 -d ' ' |
sed -e 's%#%%'`
pull_requests+=($pr)
done
IFS=$'\n'
pull_requests=(`echo "${pull_requests[*]}" | sort | uniq`)
for item in ${pull_requests[@]}; do
echo $url_prefix$item
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment