From: Arun Isaac <arunisaac@systemreboot.net>
To: 61645@debbugs.gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>,
Arun Isaac <arunisaac@systemreboot.net>
Subject: [bug#61645] [PATCH v2 1/4] client: Add CLI client to search for issues.
Date: Tue, 21 Feb 2023 00:33:18 +0000 [thread overview]
Message-ID: <20230221003318.5334-1-arunisaac@systemreboot.net> (raw)
In-Reply-To: <20230220013821.27440-1-arunisaac@systemreboot.net>
* 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 <arunisaac@systemreboot.net>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 <rekado@elephly.net>
-;;; Copyright © 2018, 2021 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2018, 2021, 2023 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; 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.38.1
next prev parent reply other threads:[~2023-02-21 1:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-20 1:38 [bug#61645] [PATCH mumi 0/1] Add CLI client to search for issues Arun Isaac
2023-02-20 1:41 ` [bug#61645] [PATCH mumi 1/1] client: " Arun Isaac
2023-02-21 0:32 ` [bug#61645] [PATCH v2 0/4] Add mumi CLI client Arun Isaac
2023-02-21 0:33 ` Arun Isaac [this message]
2023-02-21 0:33 ` [bug#61645] [PATCH v2 2/4] client: Support checking in to a specific issue Arun Isaac
2023-02-21 0:33 ` [bug#61645] [PATCH v2 3/4] client: Support sending email to issues Arun Isaac
2023-02-21 0:33 ` [bug#61645] [PATCH v2 4/4] Set only GUILE_LOAD_PATH when running tests Arun Isaac
2023-03-08 12:05 ` [bug#61645] [PATCH mumi 0/1] Add CLI client to search for issues Ludovic Courtès
2023-03-08 13:28 ` Arun Isaac
2023-03-08 15:36 ` [bug#61645] [mumi v3 0/4] Add mumi CLI client Arun Isaac
2023-03-08 15:36 ` [bug#61645] [mumi v3 1/4] client: Add CLI client to search for issues Arun Isaac
2023-03-08 15:36 ` [bug#61645] [mumi v3 2/4] client: Support checking in to a specific issue Arun Isaac
2023-03-08 15:36 ` [bug#61645] [mumi v3 3/4] client: Support sending email to issues Arun Isaac
2023-03-08 15:36 ` [bug#61645] [mumi v3 4/4] Set only GUILE_LOAD_PATH when running tests Arun Isaac
2023-03-30 20:47 ` [bug#61645] [PATCH mumi 0/1] Add CLI client to search for issues Ludovic Courtès
2023-03-30 20:57 ` Ricardo Wurmus
2023-03-30 21:57 ` bug#61645: " Ricardo Wurmus
2023-03-31 12:15 ` [bug#61645] " Ludovic Courtès
2023-03-31 20:32 ` Arun Isaac
2023-03-31 22:15 ` Ludovic Courtès
2023-03-31 22:51 ` Arun Isaac
2023-04-01 17:32 ` Arun Isaac
2023-04-24 14:41 ` Arun Isaac
2023-04-24 20:01 ` Ludovic Courtès
2023-04-25 12:28 ` Arun Isaac
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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230221003318.5334-1-arunisaac@systemreboot.net \
--to=arunisaac@systemreboot.net \
--cc=61645@debbugs.gnu.org \
--cc=rekado@elephly.net \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).