Endless Parentheses

Concise ramblings on Emacs productivity.

Support on Gratipay
profile for Malabarba on Stack Exchange

Easily Create Github PRs from Magit

In contrast with fetching pull requests, which either requires a minor-mode or some long-named branches, creating pull requests is as easy as a one-key deal.

*If you’re reading this now, note that this code was written for an older Magit version. An up-to-date version of the code (working with latest Magit) can be found on this other post.*

Because sx.el (a package which I really ought to blog about) was developed as a group effort, Sean and I decided early on to use PRs for everything. Predictably, the need arose for a quick way to create them, and I promptly asked Emacs.StackExchange for help. The solution below is a courtesy of Constantine.

(defun endless/visit-pull-request-url ()
"Visit the current branch's PR on Github."
(interactive)
(browse-url
(format "https://github.com/%s/pull/new/%s"
(replace-regexp-in-string
"\\`.+github\\.com:\\(.+\\)\\.git\\'" "\\1"
(magit-get "remote"
(magit-get-current-remote)
"url"))
(magit-get-current-branch))))

(eval-after-load 'magit
'(define-key magit-mode-map "V"
#'endless/visit-pull-request-url))

After hitting V, you just need to press the big green button at the Github page.

Tags: magit, init.el, emacs

Support on Gratipay
comments powered by Disqus