From c214aeac877f9d3043f28d6f8215d5c5f0809f8e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 27 Jul 2023 01:28:23 +0200 Subject: code-review-gh-start: Get the merge base from the GitHub API Haven't tested this yet, but the idea is to use the `gh` CLI to call the GitHub API and get the list of pulls requests. These are filtered to get the one open for the current branch, and we can then get its merge base and start a `code-review` review using that merge base. --- code-review-gh-start | 24 ++++++++++++++++-------- 1 file 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 . -# 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)" -- cgit v1.2.3