Skip to main content

Add a script to open GitHub pull requests

ID
f53b4c2
date
2024-04-07 19:23:50+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
11d4dd2
message
Add a script to open GitHub pull requests
changed files
4 files, 42 additions, 7 deletions

Changed files

git/README.md (7234) → git/README.md (7624)

diff --git a/git/README.md b/git/README.md
index 7906abd..83dd2e4 100644
--- a/git/README.md
+++ b/git/README.md
@@ -85,6 +85,12 @@ scripts = [
         """
     },
     {
+        "usage": "gpr",
+        "description": """
+        open a GitHub <strong>p</strong>ull <strong>r</strong>equest for the current branch
+        """
+    },
+    {
         "usage": "groot",
         "description": """
         alias for <code>git rev-parse --show-toplevel</code>, which prints the root of the current repository
@@ -214,6 +220,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
   </dd>
 
   <dt>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/git/gpr">
+      <code>gpr</code>
+    </a>
+  </dt>
+  <dd>
+    open a GitHub <strong>p</strong>ull <strong>r</strong>equest for the current branch
+  </dd>
+
+  <dt>
     <a href="https://github.com/alexwlchan/scripts/blob/main/git/groot">
       <code>groot</code>
     </a>
@@ -253,4 +268,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
     open the current Git repo in <a href="https://gitup.co/">GitUp</a>, my GUI Git client of choice
   </dd>
 </dl>
-<!-- [[[end]]] (checksum: ce37e30161ddef4f54ee397d664307dd) -->
+<!-- [[[end]]] (checksum: 113cfe8c833dfc74985f3f7dff2bcace) -->

git/_get_github_url (0) → git/_get_github_url (351)

diff --git a/git/_get_github_url b/git/_get_github_url
new file mode 100755
index 0000000..95c748a
--- /dev/null
+++ b/git/_get_github_url
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+# The remote URL will be something of the form
+#
+#     git@github.com:alexwlchan/photo-reviewer.git
+#
+# The tr/awk gets everything after the colon
+REPO_NAME=$(
+  git remote get-url origin \
+    | tr ':' ' ' \
+    | awk '{print $2}' \
+    | sed "s/\.git//g"
+)
+
+printf "https://github.com/$REPO_NAME"

git/gpr (0) → git/gpr (155)

diff --git a/git/gpr b/git/gpr
new file mode 100755
index 0000000..b153387
--- /dev/null
+++ b/git/gpr
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# Open a GitHub pull request for the current branch.
+
+set -o errexit
+set -o nounset
+
+open "$(_get_github_url)/compare/$(gcb)?expand=1"

git/gub (388) → git/gub (155)

diff --git a/git/gub b/git/gub
index ecb816e..ba6e5b6 100755
--- a/git/gub
+++ b/git/gub
@@ -4,9 +4,4 @@
 set -o errexit
 set -o nounset
 
-# The remote URL will be something of the form
-#
-#     git@github.com:alexwlchan/photo-reviewer.git
-#
-# The tr/awk gets everything after the colon, then prepends github.com.
-open https://github.com/$(git remote get-url origin | tr ':' ' ' | awk '{print $2}')
+open "$(_get_github_url)"