forked from filipg/gonito
Fix slack hook
This commit is contained in:
parent
3447b29a82
commit
ec4947254a
@ -409,9 +409,12 @@ runSlackHook hook message = do
|
|||||||
|
|
||||||
R.runReq def $ do
|
R.runReq def $ do
|
||||||
let payload = object [ "text" .= message ]
|
let payload = object [ "text" .= message ]
|
||||||
(_ :: JsonResponse Value) <- R.req R.POST
|
(_ :: IgnoreResponse) <- R.req R.POST
|
||||||
hookUrl
|
hookUrl
|
||||||
(R.ReqBodyJson payload)
|
(R.ReqBodyJson payload)
|
||||||
R.jsonResponse
|
R.ignoreResponse
|
||||||
mempty
|
mempty
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
slackLink app title addr = "<" ++ link ++ "|" ++ title ++ ">"
|
||||||
|
where link = (appRoot $ appSettings app) ++ "/" ++ addr
|
||||||
|
@ -242,6 +242,7 @@ doCreateSubmission userId challengeId mDescription mTags repoSpec chan = do
|
|||||||
Just repoId -> do
|
Just repoId -> do
|
||||||
|
|
||||||
challenge <- runDB $ get404 challengeId
|
challenge <- runDB $ get404 challengeId
|
||||||
|
user <- runDB $ get404 userId
|
||||||
|
|
||||||
activeTests <- runDB $ selectList [TestChallenge ==. challengeId, TestActive ==. True] []
|
activeTests <- runDB $ selectList [TestChallenge ==. challengeId, TestActive ==. True] []
|
||||||
let (Entity mainTestId mainTest) = getMainTest activeTests
|
let (Entity mainTestId mainTest) = getMainTest activeTests
|
||||||
@ -295,6 +296,14 @@ doCreateSubmission userId challengeId mDescription mTags repoSpec chan = do
|
|||||||
|
|
||||||
outs <- getOuts chan submissionId (gonitoMetadataGeneralParams gonitoMetadata)
|
outs <- getOuts chan submissionId (gonitoMetadataGeneralParams gonitoMetadata)
|
||||||
|
|
||||||
|
currentTagIds <- runDB $ selectList [SubmissionTagSubmission ==. submissionId] []
|
||||||
|
|
||||||
|
runDB $ addTags submissionId (gonitoMetadataTags gonitoMetadata) (
|
||||||
|
map (submissionTagTag . entityVal) currentTagIds)
|
||||||
|
msg chan "SUBMISSION CREATED"
|
||||||
|
|
||||||
|
app <- getYesod
|
||||||
|
|
||||||
newScores <- mapM (getScoreForOut mainTestId) outs
|
newScores <- mapM (getScoreForOut mainTestId) outs
|
||||||
let newScores' = catMaybes newScores
|
let newScores' = catMaybes newScores
|
||||||
let newScores'' = case getMetricOrdering (testMetric mainTest) of
|
let newScores'' = case getMetricOrdering (testMetric mainTest) of
|
||||||
@ -308,19 +317,25 @@ doCreateSubmission userId challengeId mDescription mTags repoSpec chan = do
|
|||||||
(s:_) -> if compOp s b
|
(s:_) -> if compOp s b
|
||||||
then
|
then
|
||||||
do
|
do
|
||||||
app <- getYesod
|
let submissionLink = slackLink app "submission" ("q/" ++ (fromSHA1ToText (repoCurrentCommit repo)))
|
||||||
let submissionLink = (appRoot $ appSettings app) ++ "/q/" ++ (fromSHA1ToText (repoCurrentCommit repo))
|
let challengeLink = slackLink app (challengeTitle challenge) ("challenge/"
|
||||||
let message = ("Whoa! New best result for '"
|
++ (challengeName challenge))
|
||||||
++ (challengeName challenge)
|
let message = ("Whoa! New best result for "
|
||||||
++ "' challenge, "
|
++ challengeLink
|
||||||
|
++ " challenge by "
|
||||||
|
++ (fromMaybe "???" $ userName user)
|
||||||
|
++ ", "
|
||||||
++ (T.pack $ show $ testMetric mainTest)
|
++ (T.pack $ show $ testMetric mainTest)
|
||||||
|
++ ": "
|
||||||
|
++ (formatScore (testPrecision mainTest) s)
|
||||||
++ " ("
|
++ " ("
|
||||||
++ (if s > b
|
++ (if s > b
|
||||||
then "+"
|
then "+"
|
||||||
else "")
|
else "")
|
||||||
++ (T.pack $ show $ s-b)
|
++ (formatScore (testPrecision mainTest) (s-b))
|
||||||
++ ")"
|
++ ")."
|
||||||
++ " See <" ++ submissionLink ++ "|Submission>")
|
++ " See " ++ submissionLink ++ "."
|
||||||
|
++ " :clap:")
|
||||||
msg chan message
|
msg chan message
|
||||||
case appNewBestResultSlackHook $ appSettings app of
|
case appNewBestResultSlackHook $ appSettings app of
|
||||||
Just hook -> liftIO $ runSlackHook hook message
|
Just hook -> liftIO $ runSlackHook hook message
|
||||||
@ -330,13 +345,6 @@ doCreateSubmission userId challengeId mDescription mTags repoSpec chan = do
|
|||||||
[] -> return ()
|
[] -> return ()
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
||||||
currentTagIds <- runDB $ selectList [SubmissionTagSubmission ==. submissionId] []
|
|
||||||
|
|
||||||
runDB $ addTags submissionId (gonitoMetadataTags gonitoMetadata) (
|
|
||||||
map (submissionTagTag . entityVal) currentTagIds)
|
|
||||||
msg chan "SUBMISSION CREATED"
|
|
||||||
|
|
||||||
app <- getYesod
|
|
||||||
if appAutoOpening $ appSettings app
|
if appAutoOpening $ appSettings app
|
||||||
then
|
then
|
||||||
doMakePublic userId submissionId chan
|
doMakePublic userId submissionId chan
|
||||||
|
Loading…
Reference in New Issue
Block a user