aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcode-review-gh-start24
1 files changed, 16 insertions, 8 deletions
diff --git a/code-review-gh-start b/code-review-gh-start
index 4b6adea..64a5339 100755
--- a/code-review-gh-start
+++ b/code-review-gh-start
@@ -17,14 +17,22 @@
# You should have received a copy of the GNU General Public License
# along with Code Review. If not, see <https://www.gnu.org/licenses/>.
-# Like code-review-start, but get the merge base from the associate GitHub pull
-# request.
-merge_base='TODO'
+# Like code-review-start, but get the merge base from the associated GitHub
+# pull request.
-# Filter pull requests with .head.ref corresponding to current branch name, and
-# get the .base.ref as the merge base.
-#
-# gh api repos/:owner/:repo/pulls --jq=".[] | [.head.ref, .base.ref] | @tsv"
+current_branch_name() {
+ git rev-parse --abbrev-ref HEAD
+}
+
+github_merge_base() {
+ # Find a pull request with a HEAD branch matching the name of the current
+ # branch. Get that pull request's base (merge target) branch.
+ gh api \
+ repos/:owner/:repo/pulls \
+ --jq=".[]
+ | select(.head.ref == \"$(current_branch_name)\")
+ | .base.ref"
+}
-code-review-start "$merge_base"
+code-review-start "$(github_merge_base)"