A peer-to-peer stack for code collaboration
Issue listing filters + closing issues (#372)
James Haydon0dd5572a0e3b
diff --git a/bin/rad-issues b/bin/rad-issuesindex a162b10..0b56c2e 100755--- a/bin/rad-issues+++ b/bin/rad-issues@@ -15,15 +15,19 @@"rad-issues - Radicle issue CLIUsage:- rad-issues [list|list-new|new|create-chain] <chain-name>+ rad-issues list <chain-name> [--closed] [--open] [--new]+ rad-issues [new|create-chain] <chain-name>+ rad-issues close <issue-number> <chain-name>rad-issues make-key <nick>rad-issues names+ rad-issues done+ rad-issues create-chain <chain-name>rad-issues help- list - Select from all issues to view or comment on- list-new - Select from all issues that have new activity+ list - Select from issues to view or comment ondone - Mark all issues as 'seen'new - Create a new issue in $EDITOR+ close - Close an issuecreate-chain - Create a new issues chainmake-key - Create a key-pair and register the namenames - See all registered names@@ -93,7 +97,7 @@(def list-items"Lists the recent items and uses an editor to add a relevant comment."- (fn [chain last-seen]+ (fn [chain options](def chain-ref (make-chain-ref chain))(load! "rad/monadic/names.rad")@@ -128,12 +132,20 @@(/as 'i {:issue {:number 'n :title 'tit}})[(string-append "Issue " (show n) " - " tit) i])))+ (def filt+ (match [(lookup-default "open" #f options)+ (lookup-default "closed" #f options)]+ [#t #f] (fn [x] (eq? (lookup :state (lookup :issue x)) :open))+ [#f #t] (fn [x] (eq? (lookup :state (lookup :issue x)) :closed))+ _ (fn [x] #t)))+(def items(map mk-key- (match last-seen- (/just 't) (recent-activity chain-ref t)- _ (map (fn [i] {:issue i})- (reverse (values (list-issues chain-ref)))))))+ (filter filt+ (match [(lookup-default "new" #f options) (read-file-key! ".radicle-issues" :last-mark-done)]+ [#t [:just 't]] (recent-activity chain-ref t)+ _ (map (fn [i] {:issue i})+ (reverse (values (list-issues chain-ref))))))))(def items-dict (dict-from-seq items))(if (empty-seq? items)@@ -161,6 +173,16 @@(string-append "Sent comment: " added-comment)))))_ (put-str! "No selection made.")))))+(def close-issue+ (fn [issue-number chain-name]+ (def n (read issue-number))+ (if (number? n)+ (if (integral? n)+ (do (def chain-ref (make-chain-ref chain-name))+ (simple-edit-issue! chain-ref n {:state :closed}))+ (cmd-parse-failure "Issue numbers must be whole numbers!"))+ (cmd-parse-failure "To close an issue, please provide the issue number."))))+(def new-issue(fn [chain](def chain-ref (make-chain-ref chain))@@ -212,6 +234,20 @@_ :nothing))))+(def /cmd-2+ (fn [cmd arg-1 arg-2]+ ((validation/type :string) cmd)+ ((validation/type :atom) arg-1)+ ((validation/type :atom) arg-2)+ (fn [value]+ (match value+ [cmd 'a-1 'a-2] (match-pat [arg-1 arg-2] [a-1 a-2])+ [cmd _] (cmd-parse-failure (string-append "Missing argument \"" (show arg-2) "\" for command \"" cmd "\""))+ [cmd] (cmd-parse-failure (string-append "Missing argument \"" (show arg-1) "\" for command \"" cmd "\""))+ (/cons cmd _) (cmd-parse-failure (string-append "Too many arguments for command \"" cmd "\""))+ _ :nothing)+ )))+(def /cmd-0(fn [cmd]((validation/type :string) cmd)@@ -222,14 +258,37 @@_ :nothing))))+(def valid-list-options+ ["--new" "--open" "--closed"])++(def list-options+ (fn [os]+ (foldr (fn [o acc]+ (if (member? o valid-list-options)+ (insert (drop 2 o) #t acc)+ (cmd-parse-failure (string-append "Invalid list option: " o))))+ {}+ os)))++(def /list-cmd+ (fn [ch-name opts]+ (fn [v]+ (match v+ ["list"] (cmd-parse-failure "Missing arguments for command \"list\"")+ (/cons "list" (/cons 'c-n 'os)) (if (member? c-n valid-list-options)+ (cmd-parse-failure "Missing \"chain-name\" argument for command \"list\"")+ [:just {ch-name c-n+ opts (list-options os)}])+ _ :nothing))))+(def args (get-args!))(match args- (/cmd-1 "list" 'chain-name) (list-items chain-name :nothing)- (/cmd-1 "list-new" 'chain-name) (list-items chain-name (read-file-key! ".radicle-issues" :last-mark-done))+ (/list-cmd 'chain-name 'options) (list-items chain-name options)(/cmd-0 "names") (names)(/cmd-1 "make-key" 'nick) (make-key nick)(/cmd-1 "new" 'chain-name) (new-issue chain-name)(/cmd-1 "create-chain" 'chain-name) (create-chain chain-name)+ (/cmd-2 "close" 'issue-number 'chain-name) (close-issue issue-number chain-name)(/cmd-0 "done") (mark-last-seen)["help"] (put-str! help)["-h"] (put-str! help)diff --git a/rad/prelude/patterns.rad b/rad/prelude/patterns.radindex 34b5a6d..462f18a 100644--- a/rad/prelude/patterns.rad+++ b/rad/prelude/patterns.rad@@ -78,7 +78,7 @@(cond(atom? pat)[:just {pat v}]- (some [(number? pat) (keyword? pat) (string? pat)])+ (some [(number? pat) (keyword? pat) (string? pat) (boolean? pat)])(if (eq? pat v) [:just {}] :nothing)(dict? pat)((/dict pat) v)