Commit c35b83c5f7d5

Vincent Demeester <vincent@sbr.pm>
2025-02-25 11:12:17
tools/emacs: extract checkout-github-pr in `lisp`
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 849790d
Changed files (2)
tools/emacs/config/config-projects.el
@@ -71,29 +71,6 @@ One reason for this is to be able to run commands that needs a TTY."
 
   (add-hook 'project-find-functions #'vde/project-try-local)
 
-  (defun fetch-github-prs ()
-    "Fetch GitHub PRs synchronously."
-    (let* ((output (shell-command-to-string "gh pr list --limit=5000 --json number,title,author"))
-           (prs (json-read-from-string output)))
-      prs))
-
-  (defun format-pr-candidates (prs)
-    "Format PR data into candidates for completion."
-    (mapcar (lambda (pr)
-              (let-alist pr
-		(cons (format "#%d %s (by @%s)" .number .title .author.login)
-                      .number)))
-            prs))
-
-  (defun checkout-github-pr ()
-    "Interactive function to select and checkout a GitHub PR."
-    (interactive)
-    (let* ((prs (fetch-github-prs))
-           (candidates (format-pr-candidates prs))
-           (selected (cdr (assoc (completing-read "Checkout PR: " candidates)
-				 candidates))))
-      (when selected
-	(shell-command (format "gh pr checkout %d" selected)))))
   :init
   (setq-default project-compilation-buffer-name-function 'project-prefixed-buffer-name)
   (defun vde-project-magit-status ()
tools/emacs/lisp/project-func.el
@@ -2,6 +2,32 @@
 ;;; Commentary:
 ;;; Code:
 (require 'project)
+(require 'json)
+
+(defun fetch-github-prs ()
+  "Fetch GitHub PRs synchronously."
+  (let* ((output (shell-command-to-string "gh pr list --limit=5000 --json number,title,author,url,baseRefName,labels"))
+         (prs (json-read-from-string output)))
+    prs))
+
+(defun format-pr-candidates (prs)
+  "Format PR data into candidates for completion."
+  (mapcar (lambda (pr)
+            (let-alist pr
+	      (cons (format "#%d %s (by @%s) on %s" .number .title .author.login .baseRefName)
+                    .number)))
+          prs))
+
+;;;###autoload
+(defun checkout-github-pr ()
+  "Interactive function to select and checkout a GitHub PR."
+  (interactive)
+  (let* ((prs (fetch-github-prs))
+         (candidates (format-pr-candidates prs))
+         (selected (cdr (assoc (completing-read "Checkout PR: " candidates)
+			       candidates))))
+    (when selected
+      (shell-command (format "gh pr checkout %d" selected)))))
 
 ;;;###autoload
 (defun vde-project--project-current ()