summaryrefslogtreecommitdiff
path: root/.config/emacs/site-lisp
diff options
context:
space:
mode:
authorThomas Voss <thomas.voss@humanwave.nl> 2025-12-11 14:09:13 +0100
committerThomas Voss <thomas.voss@humanwave.nl> 2025-12-11 14:09:13 +0100
commit6200092afe794866017a87db2c4b0967e1135b19 (patch)
tree646412b80650bed30c9218c30168bfef7f2bfb5c /.config/emacs/site-lisp
parent48c0bcb851f67589ed922c87b8caa74252afc779 (diff)
emacs: Add ‘gh-open-previous-pr’
Diffstat (limited to '.config/emacs/site-lisp')
-rw-r--r--.config/emacs/site-lisp/gh.el22
1 files changed, 21 insertions, 1 deletions
diff --git a/.config/emacs/site-lisp/gh.el b/.config/emacs/site-lisp/gh.el
index 0461b18..23086e5 100644
--- a/.config/emacs/site-lisp/gh.el
+++ b/.config/emacs/site-lisp/gh.el
@@ -36,4 +36,24 @@ via `gh-get-labels'."
(apply #'call-process "gh" nil t nil "pr" "create" flags)
(message (buffer-string)))))
-(provide 'gh) \ No newline at end of file
+(defvar gh-pr-regexp
+ "\\`https://\\(?:www\\.\\)?github\\.com/[^/]+/[^/]+/pull/[[:digit:]]+\\'")
+
+(defun gh--pr-link-p (s)
+ (declare (pure t) (side-effect-free t))
+ (string-match-p gh-pr-regexp s))
+
+(defun gh-open-previous-pr ()
+ "Open the previous GitHub pull request.
+Opens the previous pull request created by `gh-create-pr' by searching
+for the echoed URL in the `*Messages*' buffer."
+ (interactive)
+ (with-current-buffer "*Messages*"
+ (goto-char (point-max))
+ (while (not (gh--pr-link-p (buffer-substring-no-properties
+ (pos-bol) (pos-eol))))
+ (unless (line-move -1 :noerror)
+ (user-error "No previous pull request found.")))
+ (browse-url-at-point)))
+
+(provide 'gh)