aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-07-27 01:28:23 +0200
committerTeddy Wing2023-07-27 01:28:23 +0200
commitc214aeac877f9d3043f28d6f8215d5c5f0809f8e (patch)
treec61a18e497f78a9083170e8eac6853c2ad2e5973
parentf8e1d32f122ea1f8d51e53062a4b2a974d868a86 (diff)
downloadcode-review-c214aeac877f9d3043f28d6f8215d5c5f0809f8e.tar.bz2
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.
-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)"