From patchwork Wed Mar 8 15:36:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 47795 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 5C8D516E34; Wed, 8 Mar 2023 15:38:46 +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=-1.8 required=5.0 tests=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 60C0816E0D for ; Wed, 8 Mar 2023 15:38:45 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZvrg-0006Ge-Kh; Wed, 08 Mar 2023 10:38: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 1pZvre-0006G3-Q2 for guix-patches@gnu.org; Wed, 08 Mar 2023 10:38: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 1pZvre-00042s-Hx 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-0007ot-DT for guix-patches@gnu.org; Wed, 08 Mar 2023 10:38:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61645] [mumi v3 2/4] client: Support checking in to a specific issue. 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.167828985429964 (code B ref 61645); Wed, 08 Mar 2023 15:38:02 +0000 Received: (at 61645) by debbugs.gnu.org; 8 Mar 2023 15:37:34 +0000 Received: from localhost ([127.0.0.1]:49951 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZvrC-0007nD-5w for submit@debbugs.gnu.org; Wed, 08 Mar 2023 10:37:34 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:56570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZvrA-0007n4-AC for 61645@debbugs.gnu.org; Wed, 08 Mar 2023 10:37:33 -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: References:In-Reply-To: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:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zqjBxZLKjzVcf7jJ/h7Vxxu0CTLxSp+UU4Rw2xK8GiQ=; b=BTmc4qO3xjMhs/0JDJzR4Lek2G cyS9j7dp1WCer8fjUUXLNp022zn54lVQI7wZiFu/TsjAAiwM0XNW8ZoD5d4MtgIeMom4lzITCl6Wv XUK7tRC+p5O3UcoQxmJK3Re/o9HCaehy5+/e1L1dHGk4sgCi/5pDyaapE9kd9EbfWBpdQzhChrleu HNzPozyCZ1p0BumW3N37n6Shy2IchNcGwsluML2mlUj8z8qegw14PkxMXpWX2v7CuF2nbiiNfu0to NPUePA07ENg2IjAU5B7A8UT5zZTRW0h75u6sLznB1xWtMwLbaVvEk/9ncPSySSnZRThrHuhZHlsQw Ld2D5Akg==; 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 1pZvr4-0006Dd-2F; Wed, 08 Mar 2023 21:07:27 +0530 From: Arun Isaac Date: Wed, 8 Mar 2023 15:36:56 +0000 Message-Id: <20230308153658.19929-3-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 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))