

Emacs Function to Open Magit Log PR at Point
source link: https://dev.to/jeremyf/emacs-function-to-open-magit-log-pr-at-point-56lp
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Emacs Function to Open Magit Log PR at Point
A Quick Hack to Help My Code Spelunking
At Forem, we make extensive use of the Github pull request conversations on the forem codebase. We also use the Squash and Merge strategy for Github.
See What’s the Difference Between the 3 Github Merge Methods? for details on the strategy.
One side-effect of the Squash and Merge is that Github appends the merged pull request number to the commit message. So this evening, I whipped up an Emacs function that I can call from a Magit log to open the pull request in my default browser.
(defun jnf/magit-browse-pull-request ()
"In `magit-log-mode', open the associated pull request at point."
(interactive)
(let* ((remote-url
(car
(git-link--exec
"remote" "get-url"
(format "%s"
(magit-get-current-remote)))))
(beg (line-beginning-position))
(end (line-end-position))
(region (buffer-substring-no-properties beg end)))
(save-match-data
(and (string-match "(\\#\\([0-9]+\\))$" region)
(browse-url-default-macosx-browser
(concat
(s-replace ".git" "" remote-url)
"/pull/"
(match-string 1 region)))))))
This works, and I’m certain there are improvements to my code. The above function relies on the s
, magit
, and git-link
package.
In magit-log-mode
I bound s-6
to jnf/magit-browse-pull-request
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK