cleaning up and manual tests
This commit is contained in:
parent
9b341ba8b0
commit
f22c7e0e67
1 changed files with 35 additions and 8 deletions
|
@ -18,7 +18,7 @@ module GPM.Review
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Protolude hiding (ask, die, (%))
|
import Protolude hiding (ask, die, (%),stdout)
|
||||||
import Turtle
|
import Turtle
|
||||||
|
|
||||||
import Data.FileEmbed (embedStringFile)
|
import Data.FileEmbed (embedStringFile)
|
||||||
|
@ -35,6 +35,8 @@ data ReviewCommand = ReviewStart ReviewOptions
|
||||||
| ReviewFeedback ReviewOptions
|
| ReviewFeedback ReviewOptions
|
||||||
| ReviewQuestion ReviewOptions
|
| ReviewQuestion ReviewOptions
|
||||||
| ReviewReject ReviewOptions
|
| ReviewReject ReviewOptions
|
||||||
|
| ReviewShow
|
||||||
|
| ReviewRetrieve
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
-- | init gpm branch to handle reviews
|
-- | init gpm branch to handle reviews
|
||||||
|
@ -72,7 +74,6 @@ parseFullNewReview = do
|
||||||
, title = fromMaybe "Review Title" nrTitle
|
, title = fromMaybe "Review Title" nrTitle
|
||||||
, user = nrUser
|
, user = nrUser
|
||||||
, branch = nrBranch
|
, branch = nrBranch
|
||||||
, reviewer = nrUser
|
|
||||||
, description = nrDescription
|
, description = nrDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +93,6 @@ parsePartialNewReview status = do
|
||||||
, title = fromMaybe "Review Title" nrTitle
|
, title = fromMaybe "Review Title" nrTitle
|
||||||
, user = nrUser
|
, user = nrUser
|
||||||
, branch = nrBranch
|
, branch = nrBranch
|
||||||
, reviewer = nrUser
|
|
||||||
, description = nrDescription
|
, description = nrDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +112,10 @@ parseReviewCmd =
|
||||||
(ReviewStart <$> parseFullReviewOptions)
|
(ReviewStart <$> parseFullReviewOptions)
|
||||||
<|> subcommand "end" "End a review"
|
<|> subcommand "end" "End a review"
|
||||||
(pure ReviewCommit)
|
(pure ReviewCommit)
|
||||||
|
<|> subcommand "show" "Show the review"
|
||||||
|
(pure ReviewShow)
|
||||||
|
<|> subcommand "retrieve" "Retrieve all the reviews for current branch"
|
||||||
|
(pure ReviewRetrieve)
|
||||||
|
|
||||||
|
|
||||||
gatherNewReviewInfos :: NewReview -> Text -> IO NewReview
|
gatherNewReviewInfos :: NewReview -> Text -> IO NewReview
|
||||||
|
@ -151,6 +155,29 @@ handleReview (ReviewChangeRequest opts) br =
|
||||||
handleNewReview (setStatus opts "CHANGE_REQUESTED") br
|
handleNewReview (setStatus opts "CHANGE_REQUESTED") br
|
||||||
handleReview (ReviewReject opts) br =
|
handleReview (ReviewReject opts) br =
|
||||||
handleNewReview (setStatus opts "REJECTED") br
|
handleNewReview (setStatus opts "REJECTED") br
|
||||||
|
handleReview ReviewShow br = showReview br
|
||||||
|
handleReview ReviewRetrieve br = retrieveReview br
|
||||||
|
|
||||||
|
communicateFp :: MonadIO m => Turtle.FilePath -> m ()
|
||||||
|
communicateFp filepath = do
|
||||||
|
let fptxt = format fp filepath
|
||||||
|
putText $ "Review file: " <> fptxt
|
||||||
|
export "GPM_REVIEW_FILE" fptxt
|
||||||
|
putText $ "export GPM_REVIEW_FILE=" <> fptxt
|
||||||
|
|
||||||
|
retrieveReview :: Text -> IO ()
|
||||||
|
retrieveReview br = do
|
||||||
|
reviewName <- getTmpReviewFile br
|
||||||
|
let gpmReviewFile = "reviews" </>
|
||||||
|
fromString (toS ("review-" <> protectStr br <> ".org"))
|
||||||
|
mktree (directory reviewName)
|
||||||
|
cp gpmReviewFile reviewName
|
||||||
|
communicateFp reviewName
|
||||||
|
|
||||||
|
showReview :: Text -> IO ()
|
||||||
|
showReview br = do
|
||||||
|
reviewName <- getTmpReviewFile br
|
||||||
|
stdout (input reviewName)
|
||||||
|
|
||||||
protectStr :: Text -> Text
|
protectStr :: Text -> Text
|
||||||
protectStr =
|
protectStr =
|
||||||
|
@ -164,13 +191,14 @@ validTmpNewReview br = do
|
||||||
let dstReview = "reviews" </>
|
let dstReview = "reviews" </>
|
||||||
fromString (toS ("review-" <> protectStr br <> ".org"))
|
fromString (toS ("review-" <> protectStr br <> ".org"))
|
||||||
appendFile (toS (format fp dstReview)) ("\n\n" <> tmpReview)
|
appendFile (toS (format fp dstReview)) ("\n\n" <> tmpReview)
|
||||||
|
debug_ $ "git add " <> toS (format fp dstReview)
|
||||||
|
debug_ $ "git commit -m \"review for " <> br <> "\""
|
||||||
|
|
||||||
data NewReview =
|
data NewReview =
|
||||||
NewReview { status :: Text
|
NewReview { status :: Text
|
||||||
, title :: Text
|
, title :: Text
|
||||||
, user :: Maybe User
|
, user :: Maybe User
|
||||||
, branch :: Maybe Text
|
, branch :: Maybe Text
|
||||||
, reviewer :: Maybe User
|
|
||||||
, description :: Maybe Text
|
, description :: Maybe Text
|
||||||
} deriving (Eq)
|
} deriving (Eq)
|
||||||
|
|
||||||
|
@ -182,7 +210,6 @@ instance ToMustache NewReview where
|
||||||
, "title" ~> title
|
, "title" ~> title
|
||||||
, "user" ~> user
|
, "user" ~> user
|
||||||
, "branch" ~> branch
|
, "branch" ~> branch
|
||||||
, "reviewer" ~> reviewer
|
|
||||||
, "description" ~> description
|
, "description" ~> description
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -194,6 +221,7 @@ getTmpReviewFile br = do
|
||||||
|
|
||||||
createTmpNewReview :: NewReview -> IO ()
|
createTmpNewReview :: NewReview -> IO ()
|
||||||
createTmpNewReview nr = do
|
createTmpNewReview nr = do
|
||||||
|
putText "DEBUG: create temporary file for the new review"
|
||||||
ecompiled <- automaticCompile ["./templates"] "new-review.org"
|
ecompiled <- automaticCompile ["./templates"] "new-review.org"
|
||||||
case ecompiled of
|
case ecompiled of
|
||||||
Left pe -> do
|
Left pe -> do
|
||||||
|
@ -202,8 +230,9 @@ createTmpNewReview nr = do
|
||||||
Right compiled -> do
|
Right compiled -> do
|
||||||
reviewName <- getTmpReviewFile (fromMaybe "no-name" (branch nr))
|
reviewName <- getTmpReviewFile (fromMaybe "no-name" (branch nr))
|
||||||
let tmpReviewFilename = format fp reviewName
|
let tmpReviewFilename = format fp reviewName
|
||||||
|
mktree (directory reviewName)
|
||||||
writeFile (toS tmpReviewFilename) (substitute compiled nr)
|
writeFile (toS tmpReviewFilename) (substitute compiled nr)
|
||||||
putText $ "Review file: " <> tmpReviewFilename
|
communicateFp reviewName
|
||||||
|
|
||||||
interactiveNewReview :: NewReview -> IO NewReview
|
interactiveNewReview :: NewReview -> IO NewReview
|
||||||
interactiveNewReview nr =
|
interactiveNewReview nr =
|
||||||
|
@ -217,8 +246,6 @@ interactiveNewReview nr =
|
||||||
ask "user" (fromMaybe "your name" (user nr)) identity)
|
ask "user" (fromMaybe "your name" (user nr)) identity)
|
||||||
<*> (maybe (branch nr) Just
|
<*> (maybe (branch nr) Just
|
||||||
<$> ask "branch" (fromMaybe "related branch" (branch nr)) identity)
|
<$> ask "branch" (fromMaybe "related branch" (branch nr)) identity)
|
||||||
<*> (maybe (reviewer nr) Just
|
|
||||||
<$> ask "reviewer" "a single nick" identity)
|
|
||||||
<*> (maybe (description nr) Just
|
<*> (maybe (description nr) Just
|
||||||
<$> ask "description" "the long description" identity)
|
<$> ask "description" "the long description" identity)
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in a new issue