cleaning up

This commit is contained in:
Yann Esposito (Yogsototh) 2018-10-11 23:17:17 +02:00
parent 838ae10ec6
commit 8356988d95
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
5 changed files with 55 additions and 51 deletions

View file

@ -97,9 +97,9 @@ instance ToMustache NewIssue where
, "title" ~> title , "title" ~> title
, "user" ~> user , "user" ~> user
, "branch" ~> branch , "branch" ~> branch
, "tags" ~> tags , "tags" ~> if null tags then Nothing else Just (T.intercalate ":" tags)
, "assignee" ~> assignee , "assignee" ~> assignee
, "reviewers" ~> reviewers , "reviewers" ~> if null reviewers then Nothing else Just (T.intercalate "," reviewers)
, "description" ~> description , "description" ~> description
] ]
@ -119,44 +119,48 @@ handleNewIssue opts br = do
then interactiveNewIssue newIssueTmp then interactiveNewIssue newIssueTmp
else return newIssueTmp else return newIssueTmp
createTmpNewIssue newIssue createTmpNewIssue newIssue
validTmpNewIssue validTmpNewIssue newIssue
interactiveNewIssue :: NewIssue -> IO NewIssue interactiveNewIssue :: NewIssue -> IO NewIssue
interactiveNewIssue ni = interactiveNewIssue ni =
NewIssue NewIssue
<$> (fromMaybe (priority ni) <$> ask "priority" (ptot (priority ni)) toPriority
<$> ask "priority" (ptot (priority ni)) toPriority) <*> ask "status" (status ni) identity
<*> (fromMaybe (status ni) <*> ask "title" (title ni) identity
<$> ask "status" (status ni) identity) <*> ask "user" (fromMaybe "" (user ni)) notEmpty
<*> (fromMaybe (title ni) <*> ask "branch" (fromMaybe "" (branch ni)) notEmpty
<$> ask "title" (title ni) identity) <*> ask "tags" (T.intercalate "," (tags ni)) (T.splitOn ",")
<*> (maybe (user ni) Just <*> ask "assignee" (fromMaybe "" (assignee ni)) notEmpty
<$> <*> ask "reviewers (comma separated)" (T.intercalate "," (reviewers ni)) (T.splitOn ",")
ask "user" (fromMaybe "your name" (user ni)) identity) <*> ask "description" (fromMaybe "" (description ni)) notEmpty
<*> (maybe (branch ni) Just
<$> ask "branch" (fromMaybe "related branch" (branch ni)) identity)
<*> (fromMaybe (tags ni)
<$> ask "tags" "comma separated tags" (T.splitOn ","))
<*> (maybe (assignee ni) Just
<$> ask "assignee" "a single nick" identity)
<*> (fromMaybe (tags ni)
<$> ask "reviewers" "comma separated nicks" (T.splitOn ","))
<*> (maybe (description ni) Just
<$> ask "description" "the long description" identity)
where where
ptot :: Priority -> Text ptot :: Priority -> Text
ptot PriorityA = "A" ptot PriorityA = "A"
ptot PriorityB = "B" ptot PriorityB = "B"
ptot PriorityC = "C" ptot PriorityC = "C"
ask :: Text -> Text -> (Text -> a) -> IO (Maybe a)
ask field ex tr = do
putText $ "Please enter " <> field <> "("<> ex <>"): "
fmap (tr . lineToText) <$> readline
validTmpNewIssue :: IO () notEmpty :: Text -> Maybe Text
validTmpNewIssue = do notEmpty "" = Nothing
notEmpty str = Just str
ask :: Text -> Text -> (Text -> a) -> IO a
ask field defaultValue tr = do
putText $ "Please enter " <> field
<> (if defaultValue /= "" then " ("<> defaultValue <>"): " else "")
mline <- readline
case mline of
Nothing -> return (tr defaultValue)
Just line -> if line == ""
then return (tr defaultValue)
else return . tr . lineToText $ line
validTmpNewIssue :: NewIssue -> IO ()
validTmpNewIssue ni = do
tmpIssue <- readFile ".issues.org.tmp" tmpIssue <- readFile ".issues.org.tmp"
appendFile "issues.org" ("\n\n" <> tmpIssue) appendFile "issues.org" ("\n\n" <> tmpIssue)
debug_ "git add issues.org"
debug_ $ "git commit -m \"New Issue: " <> T.replace "\"" "'" (title ni) <> "\""
rm ".issues.org.tmp"
gatherNewIssueInfos :: NewIssue -> Text -> IO NewIssue gatherNewIssueInfos :: NewIssue -> Text -> IO NewIssue
gatherNewIssueInfos iss br = do gatherNewIssueInfos iss br = do

View file

@ -257,24 +257,22 @@ createTmpNewReview nr br = do
interactiveNewReview :: NewReview -> IO NewReview interactiveNewReview :: NewReview -> IO NewReview
interactiveNewReview nr = interactiveNewReview nr =
NewReview NewReview
<$> (fromMaybe (status nr) <$> ask "status" (status nr) identity
<$> ask "status" (status nr) identity) <*> ask "title" (title nr) identity
<*> (fromMaybe (title nr) <*> ask "user" (fromMaybe "" (user nr)) notEmpty
<$> ask "title" (title nr) identity) <*> ask "branch" (fromMaybe "" (branch nr)) notEmpty
<*> (maybe (user nr) Just <*> ask "description" "" notEmpty
<$>
ask "user" (fromMaybe "your name" (user nr)) identity)
<*> (maybe (branch nr) Just
<$> ask "branch" (fromMaybe "related branch" (branch nr)) identity)
<*> (maybe (description nr) Just
<$> ask "description" "the long description" identity)
where where
ask :: Text -> Text -> (Text -> a) -> IO (Maybe a) notEmpty :: Text -> Maybe Text
notEmpty "" = Nothing
notEmpty str = Just str
ask :: Text -> Text -> (Text -> a) -> IO a
ask field ex tr = do ask field ex tr = do
putText $ "Please enter " <> field <> " ("<> ex <>"): " putText $ "Please enter " <> field
<> (if ex /= "" then " ("<> ex <>"): " else "")
mline <- readline mline <- readline
case mline of case mline of
Nothing -> return Nothing Nothing -> return (tr "")
Just line -> if line == "" Just line -> if line == ""
then return Nothing then return (tr "")
else return . Just . tr . lineToText $ line else return . tr . lineToText $ line

View file

@ -53,6 +53,8 @@ init = do
output descriptionFile "Main repositories" output descriptionFile "Main repositories"
repoRoot <- getProjectRoot repoRoot <- getProjectRoot
publicProjectDir <- getPublicPrjDir publicProjectDir <- getPublicPrjDir
putText (format ("rmtree " % fp) publicProjectDir)
rmtree publicProjectDir
debug_ (format ("git clone --bare "%fp%" "%fp) debug_ (format ("git clone --bare "%fp%" "%fp)
repoRoot repoRoot
publicProjectDir) publicProjectDir)

View file

@ -1,8 +1,8 @@
**** {{priority}} {{status}} {{title}} :{{#tags}}{{tag}}:{{/tags}} **** {{priority}} {{status}} {{title}}{{#tags}} :{{tags}}:{{/tags}}
:PROPERTIES: :PROPERTIES:
:CREATOR: {{user}} :CREATOR: {{user}}{{#branch}}
{{#branch}}:BRANCH: {{branch}}{{/branch}} :BRANCH: {{branch}}{{/branch}}{{#assignee}}
{{#assignee}}:ASSIGNEE: {{assignee}}{{/assignee}} :ASSIGNEE: {{assignee}}{{/assignee}}{{#reviewers}}
{{#reviewers}}:REQUESTED_REVIEWERS:{{#reviewers}} {{reviewer}}{{/reviewers}}{{/reviewers}} :REQUESTED_REVIEWERS: {{reviewers}}{{/reviewers}}
:END: :END:
{{description}} {{description}}

View file

@ -1,6 +1,6 @@
**** {{status}} {{title}} **** {{status}} {{title}}
:PROPERTIES: :PROPERTIES:
:REVIEWER: {{user}} :REVIEWER: {{user}}{{#branch}}
{{#branch}}:BRANCH: {{branch}}{{/branch}} :BRANCH: {{branch}}{{/branch}}
:END: :END:
{{description}} {{description}}