From patchwork Mon Feb 20 01:41:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 47132 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2853716A3F; Mon, 20 Feb 2023 01:43:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E7FCE16744 for ; Mon, 20 Feb 2023 01:43:22 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTvCt-0002yT-T5; Sun, 19 Feb 2023 20:43:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTvCo-0002y9-Rp for guix-patches@gnu.org; Sun, 19 Feb 2023 20:43:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTvCo-0001Mp-CU for guix-patches@gnu.org; Sun, 19 Feb 2023 20:43:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pTvCo-00069D-86 for guix-patches@gnu.org; Sun, 19 Feb 2023 20:43:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [PATCH mumi 1/1] client: Add CLI client to search for issues. References: <20230220013821.27440-1-arunisaac@systemreboot.net> In-Reply-To: <20230220013821.27440-1-arunisaac@systemreboot.net> Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Feb 2023 01:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61645 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 61645@debbugs.gnu.org Cc: Ricardo Wurmus , Arun Isaac Received: via spool by 61645-submit@debbugs.gnu.org id=B61645.167685732323552 (code B ref 61645); Mon, 20 Feb 2023 01:43:02 +0000 Received: (at 61645) by debbugs.gnu.org; 20 Feb 2023 01:42:03 +0000 Received: from localhost ([127.0.0.1]:50042 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTvBq-00067o-Cz for submit@debbugs.gnu.org; Sun, 19 Feb 2023 20:42:03 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:34600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTvBn-00067L-At for 61645@debbugs.gnu.org; Sun, 19 Feb 2023 20:42:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ukW1xmfnSUSsflOM0WMl6nRrYCP8/qpgq0792wdwKq0=; b=IQyC4hvK3X2YYraQCw4owi7Q/t ehvo9A9qpQb+RZsrB79+bgcfnykB3PUgcDHDqdYKPEa15PdsxQnsg6nayMpZWHD7IPVDvt6KsaEm/ vrdetVPKpbHeWGfoTMMphQ7q3cwCByfmDUJN6biNJ6qWvDimVx4rbsa0dpWrz2NpwXUY5jJOxoWq9 7pS/QRQpBqVYR99P520Tk7JrAeJLyEcUMY3tNsnKKCj5hf6DoSWd3a15WtKyJzyDBt9xAS1w0efzr XESqMpYwyCUPC8DnNirqIW+gED6Sbr5s+QomCKFr49Qgisrj1/9aU7kLSFR3/P1zLSYA7bqtvUzPX kXgoqg/w==; Received: from [192.168.2.1] (port=55598 helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pTvBh-0007D5-1v; Mon, 20 Feb 2023 07:11:54 +0530 From: Arun Isaac Date: Mon, 20 Feb 2023 01:41:39 +0000 Message-Id: <20230220014139.27804-1-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * mumi/client.scm: New file. * scripts/mumi.in: Import (mumi client). (show-mumi-usage): Document search subcommand. (main): Add search subcommand. * Makefile.am (SOURCES): Add mumi/client.scm. --- Makefile.am | 1 + mumi/client.scm | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/mumi.in | 8 +++- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 mumi/client.scm diff --git a/Makefile.am b/Makefile.am index 8182fc3..a8c11a1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,6 +49,7 @@ SOURCES = \ mumi/messages.scm \ mumi/jobs.scm \ mumi/send-email.scm \ + mumi/client.scm \ mumi/config.scm \ mumi/debbugs.scm \ mumi/test-utils.scm \ diff --git a/mumi/client.scm b/mumi/client.scm new file mode 100644 index 0000000..e4a0123 --- /dev/null +++ b/mumi/client.scm @@ -0,0 +1,108 @@ +;;; mumi -- Mediocre, uh, mail interface +;;; Copyright © 2023 Arun Isaac +;;; +;;; This file is part of mumi. +;;; +;;; mumi is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; mumi is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with mumi. If not, see . + +(define-module (mumi client) + #:use-module (srfi srfi-19) + #:use-module (srfi srfi-43) + #:use-module (term ansi-color) + #:use-module (web uri) + #:use-module (kolam http) + #:use-module (mumi config) + #:use-module (mumi web view utils) + #:export (search)) + +(define (git-top-level) + "Return the top-level directory of the current git repository." + (let loop ((curdir (getcwd))) + (cond + ((file-exists? (string-append curdir "/.git")) + curdir) + ((string=? curdir "/") + (error "No git top level found")) + (else + (loop (dirname curdir)))))) + +(define (client-config-directory) + "Return client configuration directory." + (string-append (git-top-level) "/.mumi")) + +(define (client-config key) + "Return client configuration value corresponding to KEY." + (or (assq-ref (call-with-input-file (string-append (client-config-directory) + "/config") + read) + key) + (case key + ((mumi-scheme) 'https) + (else (format (current-error-port) + "Key '~a not configured for mumi client.~%" + key))))) + +(define (graphql-endpoint) + "Return GraphQL endpoint." + (uri->string + (build-uri (client-config 'mumi-scheme) + #:host (client-config 'mumi-host) + #:path "/graphql"))) + +(define (iso8601->date str) + "Convert ISO-8601 date/time+zone string to date object." + (string->date str "~Y-~m-~dT~H:~M:~S~z")) + +(define (list-issue issue) + "List issue described by ISSUE association list." + (display (colorize-string + (string-append "#" + (number->string (assoc-ref issue "number"))) + 'YELLOW)) + (display " ") + (unless (assoc-ref issue "open") + (display (colorize-string "✓" 'BOLD 'GREEN)) + (display " ")) + (display (colorize-string + (assoc-ref issue "title") + 'MAGENTA 'UNDERLINE)) + (newline) + (display (string-append + "opened " + (colorize-string (time->string + (iso8601->date (assoc-ref issue "date"))) + 'CYAN) + " by " + (colorize-string + (let ((submitter (assoc-ref issue "submitter"))) + (if (eq? (assoc-ref submitter "name") 'null) + (assoc-ref submitter "address") + (assoc-ref submitter "name"))) + 'CYAN))) + (newline)) + +(define (search query) + "Search for issues with QUERY and list results." + (vector-for-each (lambda (_ issue) + (list-issue issue)) + (assoc-ref + (graphql-http-get (graphql-endpoint) + `(document + (query (#(issues #:search ,query) + number + title + open + date + (submitter name address))))) + "issues"))) diff --git a/scripts/mumi.in b/scripts/mumi.in index 755dfb3..9b61729 100644 --- a/scripts/mumi.in +++ b/scripts/mumi.in @@ -4,7 +4,7 @@ !# ;;; mumi -- Mediocre, uh, mail interface ;;; Copyright © 2016, 2017, 2019, 2020 Ricardo Wurmus -;;; Copyright © 2018, 2021 Arun Isaac +;;; Copyright © 2018, 2021, 2023 Arun Isaac ;;; ;;; This file is part of mumi. ;;; @@ -26,6 +26,7 @@ (system repl server) (ice-9 match) (ice-9 format) + ((mumi client) #:prefix client:) (mumi config) ((mumi debbugs) #:select (extract-bug-numbers)) @@ -116,6 +117,9 @@ (define (show-mumi-usage) (format (current-error-port) " + `mumi search QUERY': + search mumi for issues. + `mumi web [--address=address] [--port=port] [--listen-repl[=port]] [--disable-mailer]': start the application web server. @@ -132,6 +136,8 @@ (exit 1)) (match (cdr (program-arguments)) + (("search" . query-strings) + (client:search (string-join query-strings))) (("mailer" . rest) (let* ((opts (parse-options rest)) (sender (assoc-ref opts 'sender)) From patchwork Tue Feb 21 00:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 47180 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 82B491680C; Tue, 21 Feb 2023 00:34:30 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CB94516606 for ; Tue, 21 Feb 2023 00:34:28 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUGbc-0001ZE-OB; Mon, 20 Feb 2023 19:34:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUGba-0001YR-LZ for guix-patches@gnu.org; Mon, 20 Feb 2023 19:34:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUGba-0005E4-B0 for guix-patches@gnu.org; Mon, 20 Feb 2023 19:34:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pUGba-0002rF-6v for guix-patches@gnu.org; Mon, 20 Feb 2023 19:34:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [PATCH v2 2/4] client: Support checking in to a specific issue. References: <20230220013821.27440-1-arunisaac@systemreboot.net> In-Reply-To: <20230220013821.27440-1-arunisaac@systemreboot.net> Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Feb 2023 00:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61645 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 61645@debbugs.gnu.org Cc: Ricardo Wurmus , Arun Isaac Received: via spool by 61645-submit@debbugs.gnu.org id=B61645.167693962010933 (code B ref 61645); Tue, 21 Feb 2023 00:34:02 +0000 Received: (at 61645) by debbugs.gnu.org; 21 Feb 2023 00:33:40 +0000 Received: from localhost ([127.0.0.1]:53935 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGbE-0002qH-BG for submit@debbugs.gnu.org; Mon, 20 Feb 2023 19:33:40 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:53700) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGbC-0002q6-AX for 61645@debbugs.gnu.org; Mon, 20 Feb 2023 19:33:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qfNWu0Oop1RcJ7QtPPWyuUgNlOZOlR0cGxSPLP4LHjU=; b=RyiyifZU5LRSV/YANr5c4jOory Rsq20rS2x+rnDbYDKwFbZ4svLJCJ1LIEVQr2LKMUERPF01APmESImFBR10yITcJnsD5P7LXSLWB7+ j1dWZlNxPWP1wgcZmEV80wqK8Gf8u/3tDxlZQEEBDnwzVlzz79FVsU/E8+vv9/Ku+kUbcxEPG2zWN /XbNutyJTRIRBOacRDyZ5roIDcCzyqOfcdf2LYw8IR6+4Y5r4OakOC7MeF8NZQ9uJFtM8JD1v7VB7 T4YZ2DpUCrWt2Rbb7FuNgNf0dgNi0nl/r3Xw6ssoEIfCPo1CuL/NQP9duJioAf2yeR5HvK6tUwEHv Sno/CcUA==; Received: from [192.168.2.1] (port=36420 helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pUGb7-0009Ub-1c; Tue, 21 Feb 2023 06:03:34 +0530 From: Arun Isaac Date: Tue, 21 Feb 2023 00:33:26 +0000 Message-Id: <20230221003326.5353-1-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * mumi/client.scm: Import (srfi srfi-26). (current-issue-file, current-issue-number): New functions. (print-current-issue, set-current-issue!, clear-current-issue!): New public functions. * scripts/mumi.in (show-mumi-usage): Document current and new subcommands. (main): Add current and new subcommands. --- mumi/client.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++++- scripts/mumi.in | 20 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/mumi/client.scm b/mumi/client.scm index e4a0123..ae3a0a9 100644 --- a/mumi/client.scm +++ b/mumi/client.scm @@ -18,13 +18,17 @@ (define-module (mumi client) #:use-module (srfi srfi-19) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-43) #:use-module (term ansi-color) #:use-module (web uri) #:use-module (kolam http) #:use-module (mumi config) #:use-module (mumi web view utils) - #:export (search)) + #:export (search + print-current-issue + set-current-issue! + clear-current-issue!)) (define (git-top-level) "Return the top-level directory of the current git repository." @@ -106,3 +110,45 @@ date (submitter name address))))) "issues"))) + +(define (current-issue-file) + "Return path to current issue number file." + (string-append (client-config-directory) "/current-issue")) + +(define (current-issue-number) + "Return current issue number." + (let ((issue-file (current-issue-file))) + (and (file-exists? issue-file) + (call-with-input-file issue-file + read)))) + +(define (print-current-issue) + "Print current issue." + (let ((issue-number (current-issue-number))) + (if issue-number + (list-issue + (assoc-ref + (graphql-http-get (graphql-endpoint) + `(document + (query (#(issue #:number ,issue-number) + number + title + open + date + (submitter name address))))) + "issue")) + (begin + (format (current-error-port) "No current issue!~%") + (exit #f))))) + +(define (set-current-issue! issue-number) + "Set current issue number." + ;; TODO: Write file atomically. + (call-with-output-file (current-issue-file) + (cut write issue-number <>))) + +(define (clear-current-issue!) + "Clear current issue." + (let ((issue-file (current-issue-file))) + (when (file-exists? issue-file) + (delete-file issue-file)))) diff --git a/scripts/mumi.in b/scripts/mumi.in index 9b61729..dfd082d 100644 --- a/scripts/mumi.in +++ b/scripts/mumi.in @@ -120,6 +120,12 @@ `mumi search QUERY': search mumi for issues. + `mumi current [ISSUE-NUMBER]': + print or set current issue. + + `mumi new': + clear current issue presumably to open a new one. + `mumi web [--address=address] [--port=port] [--listen-repl[=port]] [--disable-mailer]': start the application web server. @@ -138,6 +144,20 @@ (match (cdr (program-arguments)) (("search" . query-strings) (client:search (string-join query-strings))) + (("current") + (client:print-current-issue)) + (("current" issue-number-string) + (let ((issue-number (string->number issue-number-string))) + (if issue-number + (client:set-current-issue! issue-number) + (begin + (format (current-error-port) + "Invalid issue number `~a'~%" + issue-number-string) + (exit #f)))) + (client:print-current-issue)) + (("new") + (client:clear-current-issue!)) (("mailer" . rest) (let* ((opts (parse-options rest)) (sender (assoc-ref opts 'sender)) From patchwork Tue Feb 21 00:33:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 47183 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 71C7016AFC; Tue, 21 Feb 2023 00:35:33 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AA14916653 for ; Tue, 21 Feb 2023 00:35:31 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUGcb-0001zR-6Q; Mon, 20 Feb 2023 19:35:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUGcZ-0001yh-6Q for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUGcY-0005NQ-St for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pUGcY-0002tI-If for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [PATCH v2 3/4] client: Support sending email to issues. References: <20230220013821.27440-1-arunisaac@systemreboot.net> In-Reply-To: <20230220013821.27440-1-arunisaac@systemreboot.net> Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Feb 2023 00:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61645 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 61645@debbugs.gnu.org Cc: Ricardo Wurmus , Arun Isaac Received: via spool by 61645-submit@debbugs.gnu.org id=B61645.167693964311012 (code B ref 61645); Tue, 21 Feb 2023 00:35:02 +0000 Received: (at 61645) by debbugs.gnu.org; 21 Feb 2023 00:34:03 +0000 Received: from localhost ([127.0.0.1]:53941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGba-0002rX-Oo for submit@debbugs.gnu.org; Mon, 20 Feb 2023 19:34:03 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:49220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGbX-0002qg-Aw for 61645@debbugs.gnu.org; Mon, 20 Feb 2023 19:34:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Adyq9Dvy/1wccjId62/qluNhdCKUvEw3LL9tRKzE9b0=; b=Ww8J79yZldHDMHYwARM9pG4Fc4 bOedpKOPynkwvu4dUoAvqprRc9UVNx+Mj8cPOTP8F+M6fxKRdoU5C8xYAFM7eYxP3H+meoZhC5d1O bOBajN5xMzGxErIfcjLGGW5Ad20UjaQIqaLzsHKQ3rhmIM9dvlLQXMDjLFcZfJU+qMKR8EVSDpg0i Yp5vDlIQdmGwSlHCsK34FO+KDzh6yap3/kdlcAityz2TvNzFszN1AkVn138l/H5FH0A6hi4788sBP ONmHdwG3Dk+oYzFuMhhRS2yKiufUoJPFpAMjHF2TYuIfgDSBzf+yL5+Ea+F84WqXsbp6ZtCRPQgHF KA1dajew==; Received: from [192.168.2.1] (port=45752 helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pUGbR-0009Uh-2Y; Tue, 21 Feb 2023 06:03:55 +0530 From: Arun Isaac Date: Tue, 21 Feb 2023 00:33:36 +0000 Message-Id: <20230221003336.5374-1-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * mumi/client.scm: Import (rnrs io ports), (srfi srfi-71), (srfi srfi-171), (ice-9 match), (ice-9 popen), (web client), (web response) and (email email). (issue-number-of-message, call-with-input-pipe, git-send-email): New functions. (send-email): New public function. * scripts/mumi.in (show-mumi-usage): Document send-email subcommand. (main): Add send-email subcommand. * tests/client.scm: New file. * Makefile.am (SCM_TESTS): Add tests/client.scm. --- Makefile.am | 1 + mumi/client.scm | 105 ++++++++++++++++++++++++++++++++++++++++++++++- scripts/mumi.in | 5 +++ tests/client.scm | 93 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 tests/client.scm diff --git a/Makefile.am b/Makefile.am index a8c11a1..86ba4f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -58,6 +58,7 @@ SOURCES = \ TEST_EXTENSIONS = .scm SCM_TESTS = \ + tests/client.scm \ tests/debbugs.scm \ tests/xapian.scm diff --git a/mumi/client.scm b/mumi/client.scm index ae3a0a9..09f83ee 100644 --- a/mumi/client.scm +++ b/mumi/client.scm @@ -17,18 +17,27 @@ ;;; along with mumi. If not, see . (define-module (mumi client) + #:use-module (rnrs io ports) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (srfi srfi-43) + #:use-module (srfi srfi-71) + #:use-module (srfi srfi-171) + #:use-module (ice-9 match) + #:use-module (ice-9 popen) #:use-module (term ansi-color) + #:use-module (web client) + #:use-module (web response) #:use-module (web uri) + #:use-module (email email) #:use-module (kolam http) #:use-module (mumi config) #:use-module (mumi web view utils) #:export (search print-current-issue set-current-issue! - clear-current-issue!)) + clear-current-issue! + send-email)) (define (git-top-level) "Return the top-level directory of the current git repository." @@ -152,3 +161,97 @@ (let ((issue-file (current-issue-file))) (when (file-exists? issue-file) (delete-file issue-file)))) + +(define* (issue-number-of-message message-id #:optional (retries 15)) + "Return issue number that MESSAGE-ID belongs to. Retry RETRIES number +of times with an interval of 60 seconds between retries." + ;; TODO: Re-implement this using our GraphQL endpoint once it + ;; supports retrieving the issue from a message ID. Later, + ;; re-implement this using a GraphQL subscription when kolam + ;; supports it. + (define (poll-issue-number-of-message message-id) + (let ((response _ (http-get (build-uri (client-config 'mumi-scheme) + #:host (client-config 'mumi-host) + #:path (string-append "/msgid/" message-id))))) + (and (>= (response-code response) 300) + (< (response-code response) 400) + (match (split-and-decode-uri-path + (uri-path (response-location response))) + (("issue" issue-number) + (string->number issue-number)))))) + + (let loop ((i retries)) + (if (zero? i) + (begin + (format (current-error-port) + "Mail not acknowledged by issue tracker. Giving up.~%") + (exit #f)) + (or (poll-issue-number-of-message message-id) + (begin + (let ((retry-interval 60)) + (format (current-error-port) + "Trial ~a/~a: Server has not yet received our email. Will retry in ~a seconds.~%" + (1+ i) retries retry-interval) + (sleep retry-interval)) + (loop (1- retries))))))) + +(define (call-with-input-pipe command proc) + "Call PROC with input pipe to COMMAND. COMMAND is a list of program +arguments." + (match command + ((prog args ...) + (let ((port #f)) + (dynamic-wind + (lambda () + (set! port (apply open-pipe* OPEN_READ prog args))) + (cut proc port) + (cut close-pipe port)))))) + +(define (git-send-email to patch) + "Send email using git send-email and return the message ID of the sent +email." + (let ((command (list "git" "send-email" + (string-append "--to=" to) + patch))) + (display (string-join command)) + (newline) + (call-with-input-pipe command + (lambda (port) + ;; FIXME: This messes up the order of stdout and stderr. + (let ((message-id + ;; Read till you get the Message ID. + (port-transduce (tlog (lambda (_ line) + (display line) + (newline))) + (rany (lambda (line) + (and (string-prefix-ci? "Message-ID:" line) + (assq-ref + (parse-email-headers + (string-append line "\n")) + 'message-id)))) + get-line + port))) + ;; Pass through the rest. + (display (get-string-all port)) + message-id))))) + +(define (send-email patches) + "Send PATCHES via email." + (match patches + ((first-patch other-patches ...) + ;; If an issue is current, send patches to that issue's email + ;; address. Else, send first patch to the patch email address and + ;; get an issue number. Then, send the remaining patches to that + ;; issue's email address. + (for-each (cute git-send-email + (string-append (number->string + (or (current-issue-number) + (issue-number-of-message + (git-send-email (client-config 'patch-email-address) + first-patch)))) + "@" + (client-config 'debbugs-host)) + <>) + (if (current-issue-number) + patches + other-patches))))) diff --git a/scripts/mumi.in b/scripts/mumi.in index dfd082d..2295328 100644 --- a/scripts/mumi.in +++ b/scripts/mumi.in @@ -126,6 +126,9 @@ `mumi new': clear current issue presumably to open a new one. + `mumi send-email': + send patches to debbugs. + `mumi web [--address=address] [--port=port] [--listen-repl[=port]] [--disable-mailer]': start the application web server. @@ -158,6 +161,8 @@ (client:print-current-issue)) (("new") (client:clear-current-issue!)) + (("send-email" . patches) + (client:send-email patches)) (("mailer" . rest) (let* ((opts (parse-options rest)) (sender (assoc-ref opts 'sender)) diff --git a/tests/client.scm b/tests/client.scm new file mode 100644 index 0000000..2948aed --- /dev/null +++ b/tests/client.scm @@ -0,0 +1,93 @@ +;;; mumi -- Mediocre, uh, mail interface +;;; Copyright © 2023 Arun Isaac +;;; +;;; This program is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU Affero General Public License +;;; as published by the Free Software Foundation, either version 3 of +;;; the License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; Affero General Public License for more details. +;;; +;;; You should have received a copy of the GNU Affero General Public +;;; License along with this program. If not, see +;;; . + +(use-modules (srfi srfi-26) + (srfi srfi-64) + (ice-9 match)) + +(define (with-variable variable value thunk) + "Set VARIABLE to VALUE, run THUNK and restore the old value of +VARIABLE. Return the value returned by THUNK." + (let ((old-value (variable-ref variable))) + (dynamic-wind + (cut variable-set! variable value) + thunk + (cut variable-set! variable old-value)))) + +(define (with-variables variable-bindings thunk) + "Set VARIABLE-BINDINGS, run THUNK and restore the old values of the +variables. Return the value returned by THUNK. VARIABLE-BINDINGS is a +list of pairs mapping variables to their values." + (match variable-bindings + (((variable . value) tail ...) + (with-variable variable value + (cut with-variables tail thunk))) + (() (thunk)))) + +(define-syntax-rule (var@@ module-name variable-name) + (module-variable (resolve-module 'module-name) + 'variable-name)) + +(define (trace-calls function-variable thunk) + "Run THUNK and return a list of argument lists FUNCTION-VARIABLE is +called with." + (let ((args-list (list))) + (with-variable function-variable (lambda args + (set! args-list + (cons args args-list))) + thunk) + (reverse args-list))) + +(define client-config-stub + (cons (var@@ (mumi client) client-config) + (lambda (key) + (case key + ((debbugs-host) "example.com") + ((patch-email-address) "foo@patches.com") + (else (error "Key unimplemented in stub" key)))))) + +(test-begin "client") + +(test-equal "send patches to new issue" + '(("git" "send-email" "--to=foo@patches.com" "foo.patch") + ("git" "send-email" "--to=12345@example.com" "bar.patch") + ("git" "send-email" "--to=12345@example.com" "foobar.patch")) + (map (match-lambda + ((command _) command)) + (trace-calls (var@@ (mumi client) call-with-input-pipe) + (lambda () + (with-variables (list (cons (var@@ (mumi client) issue-number-of-message) + (const 12345)) + client-config-stub) + (cut (@@ (mumi client) send-email) + (list "foo.patch" "bar.patch" "foobar.patch"))))))) + +(test-equal "send patches to existing issue" + '(("git" "send-email" "--to=12345@example.com" "foo.patch") + ("git" "send-email" "--to=12345@example.com" "bar.patch") + ("git" "send-email" "--to=12345@example.com" "foobar.patch")) + (map (match-lambda + ((command _) command)) + (trace-calls (var@@ (mumi client) call-with-input-pipe) + (lambda () + (with-variables (list (cons (var@@ (mumi client) current-issue-number) + (const 12345)) + client-config-stub) + (cut (@@ (mumi client) send-email) + (list "foo.patch" "bar.patch" "foobar.patch"))))))) + +(test-end "client") From patchwork Tue Feb 21 00:33:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 47182 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A909816AFC; Tue, 21 Feb 2023 00:35:30 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 25FD916653 for ; Tue, 21 Feb 2023 00:35:30 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUGca-0001z4-Hi; Mon, 20 Feb 2023 19:35:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUGcZ-0001yn-Il for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUGcZ-0005Rd-4E for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pUGcZ-0002tS-0F for guix-patches@gnu.org; Mon, 20 Feb 2023 19:35:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [PATCH v2 4/4] Set only GUILE_LOAD_PATH when running tests. References: <20230220013821.27440-1-arunisaac@systemreboot.net> In-Reply-To: <20230220013821.27440-1-arunisaac@systemreboot.net> Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Feb 2023 00:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61645 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 61645@debbugs.gnu.org Cc: Ricardo Wurmus , Arun Isaac Received: via spool by 61645-submit@debbugs.gnu.org id=B61645.167693965111038 (code B ref 61645); Tue, 21 Feb 2023 00:35:02 +0000 Received: (at 61645) by debbugs.gnu.org; 21 Feb 2023 00:34:11 +0000 Received: from localhost ([127.0.0.1]:53946 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGbi-0002ry-JB for submit@debbugs.gnu.org; Mon, 20 Feb 2023 19:34:10 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:38136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pUGbf-0002rm-Ev for 61645@debbugs.gnu.org; Mon, 20 Feb 2023 19:34:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2lhl3gdCJ47NFPpD77/Qd16kluD4EmntFysWyOzBBF8=; b=L+jzH3cYhUE8CbLIUaiTuL0lsA f7bu55lni4vtmPWzpJAQsHWTxpYjw9rqlPh+EYQfwMORVghBF8TDDVZ2ZaLFBlIe/2vId/XQWpVFS fjiCBgydkWl1xMQknlrn2waTyYUA/9XXG492AIbeBrUUnAQXclwBcau47goWrXrkGIbSf4DwNNEsm kKMCKLGKZDvSKW9H6RUkNkND0p5bbKYGFIYnO+Zoe8dFsNs+gE9Wxq7/nY95S1t5lBiLRPL4rgYkw 5AsEG6BSiH/rokjW5CGU/jrBg81M8baOBF+8XOriys0nw9ELC9Gn8au3BMtbG/wbbxfFGT+SpCGpu IAoHpSzg==; Received: from [192.168.2.1] (port=35216 helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pUGba-0009Um-2d; Tue, 21 Feb 2023 06:04:03 +0530 From: Arun Isaac Date: Tue, 21 Feb 2023 00:33:55 +0000 Message-Id: <20230221003355.5393-1-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Somehow, the stubs in tests/client.scm do not work when compiled modules are found. This could be a guile bug. * Makefile.am (SCM_LOG_DRIVER): Do not use pre-inst-env. Set only the load path. --- Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 86ba4f0..3e57e63 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,8 +70,7 @@ EXTRA_DIST += $(TESTS) \ AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)" GUILE_AUTO_COMPILE=0 SCM_LOG_DRIVER = \ - $(top_builddir)/pre-inst-env \ - $(GUILE) --no-auto-compile -e main \ + $(GUILE) --no-auto-compile -L $(top_srcdir) -e main \ $(top_srcdir)/build-aux/test-driver.scm AM_SCM_LOG_DRIVER_FLAGS = --brief=yes