reddit / emacs

help with elisp to jump to a pr

mogorman84 · 2022-07-22 18:15
I started using https://github.com/redguardtoo/vc-msg which is awesome. But often I would like to jump to the pr not just the commit. I found a way to do so by taking the data from git-commit-link and running it through a simple bash script #!/usr/bin/env bash git_url=$1 echo $git_url | sed 's/https:\/\/github.com/repos/' | sed 's/commit/commits/' | sed 's/$/\/pulls/' | xargs gh api | jq -r .[].html_url | xargs xdg-open but I can't figure out how to write the elisp so i can call it from the ui. (eval-after-load 'vc-msg-git '(progn (push '("p" "[p]r open pr on github" (lambda () (let* ((info vc-msg-previous-commit-info)) (with-temp-buffer (insert (plist-get info :id)) (call-interactively 'git-link-commit))))) vc-msg-git-extra))) i have that written i feel like i just need to wrap part of it in a (shell-command) but havent been able to get it working.
ieure · 2022-07-22 18:52
You might want to look at magit-forge.
mogorman84 · 2022-07-22 19:39
I use magit-forge to get updates about prs. I didn't think it had anyway to jump to a pr from a git blame line though.
mogorman84 · 2022-07-23 14:28
I was able to get it working bash #!/usr/bin/env bash git_hash=$1 quick() { owner_repo=`git remote show origin 2> /dev/null |grep "Fetch URL:"| sed 's/:/\//g' | rev| cut -c5- | cut -f1,2 -d'/'|rev` gh api "/repos/${owner_repo}/commits/$git_hash/pulls" 2> /dev/null | jq -r .[].html_url 2> /dev/null | xargs xdg-open 2>/dev/null 1>&2 } quick & disown echo "opening pr" lisp (eval-after-load 'vc-msg-git '(progn (push '("p" "[p]r open pr on github" (lambda () (let* ((info vc-msg-previous-commit-info)) (with-temp-buffer (insert (plist-get info :id)) (shell-command (concat "pr_from_git_link " (format "%s" (buffer-string)))) )))) vc-msg-git-extra)))