From 0773047933a7dca72d02ff0c81f8eb20b5c36406 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 4 Dec 2022 01:04:17 -0600 Subject: [PATCH] Refactor most command handling code out of Main. --- src/Commands.idr | 240 +++++++++++++++++++++++++++++++++++++++++++++++ src/Main.idr | 204 ++++------------------------------------ 2 files changed, 256 insertions(+), 188 deletions(-) create mode 100644 src/Commands.idr diff --git a/src/Commands.idr b/src/Commands.idr new file mode 100644 index 0000000..7a1148c --- /dev/null +++ b/src/Commands.idr @@ -0,0 +1,240 @@ +module Commands + +import Data.Config +import Data.Date +import Data.List +import Data.Promise +import Data.PullRequest +import Data.SortedMap +import Data.String +import Data.User + +import BashCompletion +import Config +import FFI.Concurrency +import FFI.Git +import FFI.GitHub +import Graph +import Label +import PullRequest +import Reviewer +import User +import Util + +import Language.JSON +import Text.PrettyPrint.Prettyprinter +import Text.PrettyPrint.Prettyprinter.Render.Terminal + +%default total + +export +sync : Config => Octokit => + Promise () +sync = ignore $ syncConfig True + +||| Provide information about who the current user is when +||| they execute `harmony whoami`. +export +whoami : Config => Git => Octokit => + Promise () +whoami = printInfoOnSelf + +||| Provide information on the curent user's recent work and currrent +||| workflow when they execute `harmony relfect`. +export +reflect : Config => Octokit => + Promise () +reflect = reflectOnSelf + +||| Print the URI for the current branch's PR or create a new PR if one +||| does not exist when the user executes `harmony pr` +export +pr : Config => Git => Octokit => + Promise () +pr = do + (Identified, pr) <- identifyOrCreatePR !currentBranch + | _ => pure () + putStrLn pr.webURI + +||| Assign the given teams & users as reviewers when the user executes +||| `harmony assign ...`. +export +assign : Config => Git => Octokit => + (assignArgs : List String) + -> {default False dry : Bool} + -> Promise () +assign args {dry} = + do (_, openPr) <- identifyOrCreatePR !currentBranch + let (forcedReviewers, teamNames) = partitionedArgs + requestReviewers openPr teamNames forcedReviewers {dry} + where + -- partition args into user logins and team slugs + partitionedArgs : (List String, List String) + partitionedArgs = + let part = partition (isPrefixOf "+") args + in mapFst (map $ drop 1) part + +||| Apply the given labels to the current PR when the user executes +||| `harmony label