From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id QM35JQKsCGTU1AAASxT56A (envelope-from ) for ; Wed, 08 Mar 2023 16:38:42 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id KAANJQKsCGRiDAAAG6o9tA (envelope-from ) for ; Wed, 08 Mar 2023 16:38:42 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4C8C81F37F for ; Wed, 8 Mar 2023 16:38:42 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZvrj-0006IQ-0N; Wed, 08 Mar 2023 10:38: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 1pZvrf-0006GC-HH for guix-patches@gnu.org; Wed, 08 Mar 2023 10:38: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 1pZvre-000431-TZ for guix-patches@gnu.org; Wed, 08 Mar 2023 10:38:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pZvre-0007p0-Ok for guix-patches@gnu.org; Wed, 08 Mar 2023 10:38:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [mumi v3 1/4] client: Add CLI client to search for issues. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 08 Mar 2023 15:38: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, Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: Ricardo Wurmus , Arun Isaac Received: via spool by 61645-submit@debbugs.gnu.org id=B61645.167828985929994 (code B ref 61645); Wed, 08 Mar 2023 15:38:02 +0000 Received: (at 61645) by debbugs.gnu.org; 8 Mar 2023 15:37:39 +0000 Received: from localhost ([127.0.0.1]:49955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZvrG-0007nd-Oi for submit@debbugs.gnu.org; Wed, 08 Mar 2023 10:37:39 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:56572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZvrB-0007n5-3S for 61645@debbugs.gnu.org; Wed, 08 Mar 2023 10:37:37 -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:References:In-Reply-To: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:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bqXGycyjUiMhKVUhLViu+Zbvj38z59DLmq+GIFZaPOo=; b=WGM/rn2xLuNm/FEJyiMlrdPxuH IoCRS1l4SzVqVQhEfkY02IavrBqCVNTnmZkAnIh2UKzWJGMAAxSjLI1R0B/rAU8v6hSK2eU6mYE3R 5zNjgXb54CxJXvFigh1YceFzlyfJx6GsGnJYuUVsbt96VPJTj7mpUT3jLka+mpL56yJGmr47VeIq0 DPOLmOn2Z9++kn2jSQy7DC434a2st54bWyVnYdcLqC4Ke+WAqNpOi9sdMf/agOInjCjlBNRQFuwS1 qKe7PjFWdG2Rfn24WrSqg8PzLBz0777XXrCG10sr2IvU4jKvl8P+a8Wl4xZLuvEZJeJSyB5EwAfvu u4aC40+w==; Received: from [192.168.2.1] (port=6222 helo=localhost.localdomain) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pZvr0-0006Dd-1c; Wed, 08 Mar 2023 21:07:23 +0530 From: Arun Isaac Date: Wed, 8 Mar 2023 15:36:55 +0000 Message-Id: <20230308153658.19929-2-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <87r0tzgyok.fsf@systemreboot.net> References: <87r0tzgyok.fsf@systemreboot.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1678289922; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=bqXGycyjUiMhKVUhLViu+Zbvj38z59DLmq+GIFZaPOo=; b=Z1W9Z/TLdHWG/4LzCdSR/LvwMdBMMwPRlmJ5ojJNpOcO8GGMgAA4ymmXimdB1Lb0KWrWQw aMQkH2vJ/D5alVHzYjBpax3j/pHhRTQcj/EeEwXIuHQ5S/Kd78WCMzd/lFcf8hR+lUb6x2 PFD6jdqcly8/5dWtnhCEZUWcttKdfRAfCZixqfzMz3QcSTBf6FBrUIU1pKjkr9iaDUFWM7 SzDC/9W32DfDnz5M52xAIgTcRq75tGQOgzmKxkfjbLhiSurHv+N0bGe/YiET30IQaFuwDD 6cpX4vOqgVI22XNdVJjsF9az4c6zVmO7uULKW+Be2GHhF4Jj8nOL20CdhsrR+g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b="WGM/rn2x"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=systemreboot.net (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1678289922; a=rsa-sha256; cv=none; b=fxdrgVrY8WSL0RBq1/X5iz9Y+QsZILBMIzgfsL+lyOrbYu2O2jX8fK16Ujvo8BRv3AKl+l 5NQKwHhFeOMFkpULWN9fILGqPzHzGc5iIoru6OULekY60Pv7mdHCLyJEVN3uY8XCvm1zEK 4tO946/w804iNNxoAs25yyIeGFX2Y7KK8POnDKjBkT+EeYDpcaLOz0LQeAtSwkO1gW+Oyi nS+wGKadrn9pLFijzDvQU2r1GNNQ4jugvD3mN4aEWrFlHUb0i+gqhI3+dSjk4SyLcwWYUK O0CW1DoS3Y89ye3jhwq6YbquzYXw8nxvKf2dPihmJlHYvVtswoCxTBy32BI6+g== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b="WGM/rn2x"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=systemreboot.net (policy=none) X-Migadu-Spam-Score: 6.80 X-Spam-Score: 6.80 X-Migadu-Queue-Id: 4C8C81F37F X-Migadu-Scanner: scn1.migadu.com X-TUID: zB0GdGKK4elq * 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)) -- 2.39.1