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))