unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: William Casarin <jb55@jb55.com>
To: Kyle Meyer <kyle@kyleam.com>
Cc: notmuch@notmuchmail.org
Subject: Re: Washing GitHub emails to include inline patch?
Date: Thu, 12 Oct 2017 12:28:22 -0700	[thread overview]
Message-ID: <87zi8w17zd.fsf@jb55.com> (raw)
In-Reply-To: <871smae3zl.fsf@kyleam.com>

[-- Attachment #1: Type: text/plain, Size: 2134 bytes --]

Kyle Meyer <kyle@kyleam.com> writes:

> --8<---------------cut here---------------start------------->8---
>
> (defun km/notmuch-github-pr-number ()
>   "Return the PR number for this message."
>   (let (pr)
>     (with-current-notmuch-show-message
>      (goto-char (point-min))
>      (if (re-search-forward "https://github\\.com/.*/pull/\\([0-9]+\\)" nil t)
>          (setq pr (match-string-no-properties 1))
>        (user-error "Could not find PR number")))
>     pr))
>
> ;; This function could be anything that figures out the project based
> ;; on the current notmuch message.  Or, if you use projectile and
> ;; don't mind getting queried each time, it could just read a project
> ;; from `projectile-relevant-known-projects'.
> (defun km/notmuch-repo-from-message ()
>   "Return the repository that this message is associated with."
>   (let ((fname (notmuch-show-get-filename)))
>     (or (and fname
>              (string-match-p "magit-list" fname)
>              "~/src/emacs/magit")
>         (user-error "Could not determine repo"))))
>
> (defun km/notmuch-visit-pr-in-magit (&optional dont-fetch)
>   "Show the Magit log for this message's PR.
> If DONT-FETCH is non-nil, do not fetch first."
>   (interactive "P")
>   (let* ((pr (km/notmuch-github-pr-number))
>          (repo (km/notmuch-repo-from-message))
>          (default-directory repo))
>     ;; "origin" is hard-coded below, but it could of course be
>     ;; anything.  You could also have an alist that maps repo ->
>     ;; remote.
>     ;;
>     ;; This assumes that you've added
>     ;;
>     ;;    fetch = +refs/pull/*/head:refs/pull/origin/*
>     ;;
>     ;; to origin's in ".git/config".  You could drop that assumption
>     ;; passing a more explicit refspec to the fetch call.
>     (unless dont-fetch
>       (magit-call-git "fetch" "origin"))
>     (magit-log (list (concat "master..refs/pull/origin/" pr)))))
> --8<---------------cut here---------------end--------------->8---

This worked pretty well, I've modified it a bit to support a generic
github repo location which is parsed from the subject, and origin/master
instead of master:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github.diff --]
[-- Type: text/x-patch, Size: 1095 bytes --]

--- kyle1.el	2017-10-12 12:22:01.977663605 -0700
+++ kyle2.el	2017-10-12 12:24:49.644673189 -0700
@@ -14,10 +14,12 @@
 ;; from `projectile-relevant-known-projects'.
 (defun km/notmuch-repo-from-message ()
   "Return the repository that this message is associated with."
-  (let ((fname (notmuch-show-get-filename)))
-    (or (and fname
-             (string-match-p "magit-list" fname)
-             "~/src/emacs/magit")
+  (let ((subject (notmuch-show-get-subject))
+        (repo))
+    (or (and subject
+             (or (and (string-match "\\([^\]]+\\)" subject 1)
+                      (setq repo (match-string-no-properties 1 subject))
+                      (concat "~/dev/github/" repo))))
         (user-error "Could not determine repo"))))
 
 (defun km/notmuch-visit-pr-in-magit (&optional dont-fetch)
@@ -39,4 +41,4 @@
     ;; passing a more explicit refspec to the fetch call.
     (unless dont-fetch
       (magit-call-git "fetch" "origin"))
-    (magit-log (list (concat "master..refs/pull/origin/" pr)))))
+    (magit-log (list (concat "origin/master..refs/pull/origin/" pr)))))

[-- Attachment #3: Type: text/plain, Size: 39 bytes --]


Cheers,
William

-- 
https://jb55.com

  parent reply	other threads:[~2017-10-12 19:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22  1:49 Washing GitHub emails to include inline patch? Kyle Meyer
2017-09-22 14:17 ` Tomi Ollila
2017-09-22 14:57   ` Kyle Meyer
2017-09-22 21:38 ` William Casarin
2017-10-10 17:35 ` William Casarin
2017-10-10 19:54   ` Kyle Meyer
2017-10-11  1:45     ` William Casarin
2017-10-11  3:51       ` Kyle Meyer
2017-10-11  4:38         ` William Casarin
2017-10-12 19:28         ` William Casarin [this message]
2017-10-13  5:24           ` Kyle Meyer
2017-10-13  6:03             ` William Casarin
  -- strict thread matches above, loose matches on Subject: below --
2017-09-21 16:34 William Casarin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zi8w17zd.fsf@jb55.com \
    --to=jb55@jb55.com \
    --cc=kyle@kyleam.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).