From 00e9d626712dc1b201eb2380cf21ebe2169121d7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 27 Jul 2023 00:24:17 +0200 Subject: code-review-gh-start: Idea to get merge base from GitHub pull request To alleviate dealing with repositories that don't use "master" as their master branch. --- code-review-gh-start | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 code-review-gh-start diff --git a/code-review-gh-start b/code-review-gh-start new file mode 100755 index 0000000..2bfa980 --- /dev/null +++ b/code-review-gh-start @@ -0,0 +1,25 @@ +#!/bin/sh + +# Copyright (c) 2023 Teddy Wing +# +# This file is part of Code Review. +# +# Code Review is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Code Review is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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' + +code-review-start "$merge_base" -- cgit v1.2.3 From f8e1d32f122ea1f8d51e53062a4b2a974d868a86 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 27 Jul 2023 01:18:26 +0200 Subject: code-review-gh-start: Idea to get merge base from GitHub API via gh CLI --- code-review-gh-start | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code-review-gh-start b/code-review-gh-start index 2bfa980..4b6adea 100755 --- a/code-review-gh-start +++ b/code-review-gh-start @@ -22,4 +22,9 @@ merge_base='TODO' +# 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" + code-review-start "$merge_base" -- cgit v1.2.3 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 From 761e29c5fc91bda6776bac9e196da695d9038629 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 8 Aug 2023 20:20:31 +0200 Subject: code-review.bash-completion: Add `gh-start` to subcommands Realistically I should match based on the executable files available that start with "code-review-", but this is how it works currently, so it's less effort to add to what's already here. --- code-review.bash-completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-review.bash-completion b/code-review.bash-completion index 89bc0ab..658d251 100644 --- a/code-review.bash-completion +++ b/code-review.bash-completion @@ -17,7 +17,7 @@ function _code_review () { local cur - local subcommands="changed-files commits diff difftool log start stat" + local subcommands="changed-files commits diff difftool gh-start log start stat" COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} -- cgit v1.2.3 From 8690ad16795bf6caa95ae88feb7ee19eab7b83e0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 8 Aug 2023 20:26:03 +0200 Subject: code-review.bash-completion: Update copyright year --- code-review.bash-completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-review.bash-completion b/code-review.bash-completion index 658d251..6eaa59a 100644 --- a/code-review.bash-completion +++ b/code-review.bash-completion @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Teddy Wing +# Copyright (c) 2019, 2023 Teddy Wing # # This file is part of Code Review. # -- cgit v1.2.3