all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob e4a0123933b45a1dc347ee1cb5d608984033dc6d 3925 bytes (raw)
name: mumi/client.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
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")))

debug log:

solving e4a0123 ...
found e4a0123 in https://yhetil.org/guix/20230221003318.5334-1-arunisaac@systemreboot.net/ ||
	https://yhetil.org/guix/20230220014139.27804-1-arunisaac@systemreboot.net/ ||
	https://yhetil.org/guix/20230308153658.19929-2-arunisaac@systemreboot.net/

applying [1/1] https://yhetil.org/guix/20230221003318.5334-1-arunisaac@systemreboot.net/
diff --git a/mumi/client.scm b/mumi/client.scm
new file mode 100644
index 0000000..e4a0123

Checking patch mumi/client.scm...
Applied patch mumi/client.scm cleanly.

skipping https://yhetil.org/guix/20230220014139.27804-1-arunisaac@systemreboot.net/ for e4a0123
skipping https://yhetil.org/guix/20230308153658.19929-2-arunisaac@systemreboot.net/ for e4a0123
index at:
100644 e4a0123933b45a1dc347ee1cb5d608984033dc6d	mumi/client.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.