Gnus development mailing list
 help / color / mirror / Atom feed
From: "Adam Sjøgren" <asjo@koldfront.dk>
To: ding@gnus.org
Subject: Re: GitLab integration take two, light edition
Date: Mon, 07 Sep 2020 19:28:11 +0200	[thread overview]
Message-ID: <87sgbtzec4.fsf@tullinup.koldfront.dk> (raw)
In-Reply-To: <87tuwashjf.fsf@ericabrahamsen.net>

Eric writes:

> `mapconcat' is what you're looking for there, something like:

Yes, exactly what I needed - thanks!

This is what I have ended up with, so far, also showing Milestone,
Labels and State:

  (defun asjo-article-treat-gitlab ()
    "Show thumbsup on GitLab comments"
    (when (and gnus-treat-type (string= gnus-treat-type "text/html"))
      (let ((project-id (gnus-fetch-field "X-GitLab-Project-Id"))
            (issue-iid (gnus-fetch-field "X-GitLab-Issue-IID"))
            (message-id (gnus-fetch-field "Message-ID")))
        (when (and project-id issue-iid message-id)
          (let ((issue (ghub-request "GET" (format "/projects/%s/issues/%s" project-id issue-iid) nil :auth 'nngitlab :host "gitlab.example.org/api/v4" :username "asjo" :forge 'gitlab)))
            (let ((milestone (cdr (or (assoc "milestone" issue) '("default" . nil))))
                  (state (cdr (or (assoc-string "state" issue) '("default" . "unknown"))))
                  (labels (cdr (or (assoc-string "labels" issue) '("default" . nil)))))
              (widen)
              (message-goto-eoh)
              (when milestone
                (insert "GitLab-Milestone: " (cdr (or (assoc-string "title" milestone) '("default" . "unknown"))) "\n"))
              (when labels
                (insert "GitLab-Labels: " (mapconcat 'identity labels ", ") "\n"))
              (insert "GitLab-State: " state "\n")
              (string-match "<note_\\([0-9]+\\)" message-id)
              (ignore-errors
                (let ((emojis (ghub-request "GET" (format "/projects/%s/issues/%s/notes/%s/award_emoji" project-id issue-iid (match-string 1 message-id)) nil :auth 'nngitlab :host "gitlab.example.org/api/v4" :username "asjo" :forge 'gitlab))
                      (name-to-emoji '(("thumbsup" . "👍")
                                       ("thumbsdown" . "👎")
                                       ("smiley" . "😃"))))
                  (when emojis
                    (insert "GitLab-Emoji: " (mapconcat
                                              (lambda (x)
                                                (let ((name (cdr (assoc-string "name" x))))
                                                  (cdr (or (assoc-string name name-to-emoji) `("default" . ,name))))) emojis ", ") "\n"))))))))))

  (add-hook 'gnus-part-display-hook 'asjo-article-treat-gitlab)

and I'm pretty happy with that, it's even quite snappy, I don't notice
it running.

>> No, I just don't know (e)lisp, neither the vocabulary of functions nor
>> the idioms :-)
>
> Could have fooled me, you do pretty well with bug-hunting on this list!

That's just experience, which is much easier than knowledge.

> mapconcat takes a third argument, the string to insert between all the
> elements.

... and that was just what I needed!


  Thanks!

   Adam

-- 
 "the interview is very good, this man is smart and         Adam Sjøgren
  does not ask us idiot questions."                    asjo@koldfront.dk



  parent reply	other threads:[~2020-09-07 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28 21:15 Adam Sjøgren
2020-08-29 18:45 ` Eric Abrahamsen
2020-09-06 17:58   ` Adam Sjøgren
2020-09-06 21:48     ` Eric Abrahamsen
2020-09-06 22:22       ` Eric Abrahamsen
2020-09-07 17:28       ` Adam Sjøgren [this message]
2020-09-08 16:58         ` Eric Abrahamsen
2020-09-08 17:28           ` Adam Sjøgren

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

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

  git send-email \
    --in-reply-to=87sgbtzec4.fsf@tullinup.koldfront.dk \
    --to=asjo@koldfront.dk \
    --cc=ding@gnus.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.
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 NNTP newsgroup(s).