From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15564 invoked from network); 29 Aug 2020 18:47:11 -0000 Received: from lists1.math.uh.edu (129.7.128.208) by inbox.vuxu.org with ESMTPUTF8; 29 Aug 2020 18:47:11 -0000 Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.94) (envelope-from ) id 1kC5rs-00AdMg-Dz; Sat, 29 Aug 2020 13:46:24 -0500 Received: from mx1.math.uh.edu ([129.7.128.32]) by lists1.math.uh.edu with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kC5rn-00AdKk-Th for ding@lists.math.uh.edu; Sat, 29 Aug 2020 13:46:19 -0500 Received: from quimby.gnus.org ([95.216.78.240]) by mx1.math.uh.edu with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kC5rl-003g1E-VZ for ding@lists.math.uh.edu; Sat, 29 Aug 2020 13:46:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:Mime-Version:References :Message-ID:Date:Subject:From:To:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oW3l1sSQ0qh7PgGqQObucr5wWuiDzLM3Je4ZzXwMJP8=; b=Sx3/xRWyVPqW5CXo83mgUctQz4 61ztHWN2XFSf2AYCzmdoWf4f9mVuj/Zlr8M/teYYAjdlZB0FndK3e1p+IMBhnp7TdOktEDjQVqs3z U4B8MHI1N2cuwUjWjMIb2wei9nCsZfGdK2bqnr5vtKWdFXIgd68WRDR59XMvz55/HJRM=; Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214] helo=ciao.gmane.io) by quimby with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kC5re-0001MQ-41 for ding@gnus.org; Sat, 29 Aug 2020 20:46:13 +0200 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1kC5rd-0007wa-Ao for ding@gnus.org; Sat, 29 Aug 2020 20:46:09 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: ding@gnus.org From: Eric Abrahamsen Subject: Re: GitLab integration take two, light edition Date: Sat, 29 Aug 2020 11:45:55 -0700 Message-ID: <87wo1hffz0.fsf@ericabrahamsen.net> References: <87k0xi79qt.fsf@tullinup.koldfront.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cancel-Lock: sha1:VGmPGJuqspBHvXt8msDUktCou6Q= List-ID: Precedence: bulk Adam Sjøgren writes: > A while back I mumbled about creating an nngitlab backend, and I got a > prototype working¹. [...] > (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 " (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. I don't have any experience doing this so I'm also shooting in the dark but... It looks like the dynamic variable `gnus-treat-type' is bound while `gnus-part-display-hook' is being run, so you should be able to examine that to see if you're currently displaying "text/html" or what have you (it could also be nil) and only run your function once. Another approach would be to add your function to `gnus-treatment-function-alist'. > 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. These two issues shouldn't be hard, right? What is the actual elisp return value of `ghub-request'? If it's a list of codepoints, you can just apply `string' to the list. If it's a list of strings, apply `concat'. And wrap the whole thing in a `condition-case' to catch whatever actual error represents a 404, and use a dummy string instead. Is it more complicated than that for some reason? (I'd also be curious to see where you gave up with the actual Gitlab API -- do you have a relevant link you can share?)