Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created April 22, 2016 11:10
Show Gist options
  • Select an option

  • Save sideshowcoder/febdd8793ce1f9d810d6206e51c3da43 to your computer and use it in GitHub Desktop.

Select an option

Save sideshowcoder/febdd8793ce1f9d810d6206e51c3da43 to your computer and use it in GitHub Desktop.
Visit and Create GitHub PRs quickly from Emacs
;; URL for current branch PR should
;; look like this:
;; https://github.com/sideshowcoder/tbrokersetip/compare/master...sideshowcoder-patch-1?quick_pull=1
;; (requires magit)
(defun coder/string-remove-until (string seperator)
(nth 1 (split-string string seperator)))
(defun coder/string-remove-after (string seperator)
(nth 0 (split-string string seperator)))
(defun coder/git-origin-url-host ()
"Get the origin host part of the remote origin url, where the
url is in the format git@somehost:org/repo.git"
(let ((url (magit-get "remote.origin.url")))
(coder/string-remove-after (coder/string-remove-until url "@") ":")))
(defun coder/git-origin-org-repo ()
(let ((url (magit-get "remote.origin.url")))
(coder/string-remove-after (coder/string-remove-until url ":") ".git")))
(defun coder/visit-pr-url ()
"Visit current branch PR url"
(interactive)
(let ((remote-branch (magit-get-current-branch)))
(browse-url
(format "https://%s/%s/pull/new/master...%s?quick_pull=1"
(coder/git-origin-url-host)
(coder/git-origin-org-repo)
(magit-get-current-branch)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment