Skip to content

Instantly share code, notes, and snippets.

@mbuczko
Created November 8, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbuczko/b8d674ce037736d9c0e236aacd052bab to your computer and use it in GitHub Desktop.
Save mbuczko/b8d674ce037736d9c0e236aacd052bab to your computer and use it in GitHub Desktop.
emacs / visit github issue or PR
;; requires git-link package
(defun github--goto-issue-or-pr (id type)
"Opens a browser with issue or PR (denoted by TYPE) of given ID."
(let* ((origin-url (car (git-link--exec "config" "--get" "remote.origin.url")))
(repo-match (string-match "^git@github.com:\\([^\\.]+\\)" origin-url))
(repo-url (concat "https://github.com/" (match-string 1 origin-url)))
(sub-path (cond ((eq 'issue type) "/issues")
((eq 'pr type) "/pull"))))
(message (concat repo-url sub-path "/" id))
(browse-url
(concat repo-url sub-path "/" id))))
(defun github--goto-issue (id)
"Opens in a browser issue with given ID or with a one found at current line."
(interactive
(let* ((at-point (github--get-issue-or-pr-at-point))
(default (if at-point (concat "Issue (" at-point ") #") "Issue #"))
(str (read-string default nil nil at-point)))
(list str)))
(github--goto-issue-or-pr id 'issue))
(defun github--goto-pr (id)
"Opens in a browser pull request with given ID or with a one found at current line."
(interactive
(let* ((at-point (github--get-issue-or-pr-at-point))
(default (if at-point (concat "Pull-Request (" at-point ") #") "Pull-Request #"))
(str (read-string default nil nil at-point)))
(list str)))
(github--goto-issue-or-pr id 'pr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment