Gnus development mailing list
 help / color / mirror / Atom feed
* GitLab integration take two, light edition
@ 2020-08-28 21:15 Adam Sjøgren
  2020-08-29 18:45 ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Sjøgren @ 2020-08-28 21:15 UTC (permalink / raw)
  To: ding

A while back I mumbled about creating an nngitlab backend, and I got a
prototype working¹.

However, as predicted, it was quite slow, because checking for new
issues and comments meant an http-request per issue.

I kind of gave up on that (I should probably have tried if I could use
the GitLab API to ask for "changes since last update", but I ran out of
steam and was a little discouraged by a remark in the API documentation).

So today I lowered my level of ambition, and started by simply
implementing a function that gives a "thumbs up" to a comment, when
reading the notification email for the comment:

  (defun asjo-gitlab-give-thumbsup ()
    "Give thumbsup to current comment on a GitLab issue"
    (interactive)
    (with-current-buffer gnus-original-article-buffer
      (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")))
        (string-match "<note_\\([0-9]+\\)" message-id)
        (ghub-request "POST" (format "/projects/%s/issues/%s/notes/%s/award_emoji?name=thumbsup" project-id issue-iid (match-string 1 message-id)) nil :auth 'nngitlab :host "very.secret.gitlab.instance/api/v4" :username "asjo" :forge 'gitlab)
        (message "👍"))))

The new thing I wanted to do was to implement a "washing" function to
check what "award emojis" the comment I'm reading already has.

I found a comment in the manual saying that I can use
gnus-part-display-hook to add custom washing functions.

But I need some help. My feeble attempt was this:

  (defun asjo-article-treat-gitlab ()
    "Show thumbsup on GitLab comments"
    (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 project-id
        (string-match "<note_\\([0-9]+\\)" message-id)
        (ignore-errors
          (let ((emoji (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 "very.secret.gitlab.instance/api/v4" :username "asjo" :forge 'gitlab)))
            (message-goto-eoh)
            (insert "GitLab-Emoji: 👍\n")
            (message "👍"))))))

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

There's a lot wrong here. It does a request for each part, so 3 or 4
(these are emails with both text and html MIME parts), and it puts in
the fake header in multiple places. I'm sure there are nice functions to
call to do what I want. Finding them is my issue.

Also, the request actually returns a list of the various emojis, which
ideally would be iterated over, and added to the header instead of the
hardcoded thumbs up.

Oh, and the ghub-request errors out with a 404 when there are no emojis
(funky API design), which really ought to insert an empty GitLab-Emoji:
fake header instead of just being ignored.

So the question is: how do I write a proper washing function for
"decorating" emails with the relevant X-GitLab-* headers which only does
one request per article?

Even with all the ailments of my code, it actually didn't feel slow, so
this "type" of "integration" might be a more viable way to spend less
time opening GitLab webpages and clicking various buttons.


  Best regards,

    Adam


¹ https://koldfront.dk/git/nngitlab/

-- 
 "En pessimist i sitt livs form"                            Adam Sjøgren
                                                       asjo@koldfront.dk



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-09-08 17:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28 21:15 GitLab integration take two, light edition 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
2020-09-08 16:58         ` Eric Abrahamsen
2020-09-08 17:28           ` Adam Sjøgren

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).