Switch to more general announcements

Compatibility break: switch NEW_BEST_RESULT_SLACK_HOOK env
to ANNOUNCEMENT_HOOK
This commit is contained in:
Filip Gralinski 2021-08-21 10:26:46 +02:00
parent 3dc9ae5dd8
commit 5f4af21006
5 changed files with 12 additions and 12 deletions

View File

@ -9,14 +9,14 @@ getTestAnnouncementsR :: Handler Html
getTestAnnouncementsR = do
app <- getYesod
let webHook = appNewBestResultSlackHook $ appSettings app
let webHook = appAnnouncementHook $ appSettings app
let name = case appLocation $ appSettings app of
Just loc -> "Gonito@" ++ loc
Nothing -> "Gonito"
case webHook of
Just hook -> liftIO $ sendAnnouncement hook ("Test message from " ++ (slackLink (Just hook) app name ""))
Just hook -> liftIO $ sendAnnouncement hook ("Test message from " ++ (linkInAnnouncement (Just hook) app name ""))
Nothing -> return ()
defaultLayout $ do

View File

@ -743,8 +743,8 @@ compareFun :: MetricOrdering -> Double -> Double -> Ordering
compareFun TheLowerTheBetter = flip compare
compareFun TheHigherTheBetter = compare
slackLink :: Maybe AnnouncementHook -> App -> Text -> Text -> Text
slackLink hook app title addr = formatLink hook slink title
linkInAnnouncement :: Maybe AnnouncementHook -> App -> Text -> Text -> Text
linkInAnnouncement hook app title addr = formatLink hook slink title
where slink = (appRoot $ appSettings app) ++ "/" ++ addr
formatVersion :: (Int, Int, Int) -> Text

View File

@ -933,9 +933,9 @@ doCreateSubmission' _ userId challengeId challengeSubmissionData chan = do
msg chan "SUBMISSION CREATED"
app <- getYesod
let mHook = appNewBestResultSlackHook $ appSettings app
let mHook = appAnnouncementHook $ appSettings app
let submissionLink = slackLink mHook app "submission" ("q/" ++ (fromSHA1ToText (repoCurrentCommit repo)))
let submissionLink = linkInAnnouncement mHook app "submission" ("q/" ++ (fromSHA1ToText (repoCurrentCommit repo)))
case mMainEnt of
Just (Entity mainTestId mainTest) -> do
@ -953,7 +953,7 @@ doCreateSubmission' _ userId challengeId challengeSubmissionData chan = do
(s:_) -> if compOp s b
then
do
let challengeLink = slackLink mHook app (challengeTitle challenge) ("challenge/"
let challengeLink = linkInAnnouncement mHook app (challengeTitle challenge) ("challenge/"
++ (challengeName challenge))
let message = ("Whoa! New best result for "
++ challengeLink
@ -1020,7 +1020,7 @@ checkTarget theNow user submissionLink entries indicator target chan = do
++ " See " ++ submissionLink ++ "."
++ (T.replicate 10 " :champagne: ") ++ " :mleczko: "
msg chan message
case appNewBestResultSlackHook $ appSettings app of
case appAnnouncementHook $ appSettings app of
Just hook -> liftIO $ sendAnnouncement hook message
Nothing -> return ()
else

View File

@ -102,7 +102,7 @@ data AppSettings = AppSettings
, appTagPermissions :: TagPermissions
, appAutoOpening :: Bool
, appLeaderboardStyle :: LeaderboardStyle
, appNewBestResultSlackHook :: Maybe AnnouncementHook
, appAnnouncementHook :: Maybe AnnouncementHook
, appServerSSHPublicKey :: Maybe Text
-- ^ Are challenges, submission, etc. visible without logging in
, appIsPublic :: Bool
@ -154,7 +154,7 @@ instance FromJSON AppSettings where
appAutoOpening <- o .:? "auto-opening" .!= False
appLeaderboardStyle <- toLeaderboardStyle <$> o .: "leaderboard-style"
appNewBestResultSlackHook <- toAnnouncementHook' <$> (o .:? "new-best-result-slack-hook")
appAnnouncementHook <- toAnnouncementHook' <$> (o .:? "announcement-hook")
appServerSSHPublicKey <- o .:? "server-ssh-public-key"

View File

@ -13,7 +13,7 @@ repo-scheme: "_env:REPO_SCHEME:selfhosted"
tag-permissions: "_env:TAG_PERMISSIONS:only-admin-can-add-new-tags"
auto-opening: "_env:AUTO_OPENING:false"
leaderboard-style: "_env:LEADERBOARD_STYLE:by-submitter"
new-best-result-slack-hook: "_env:NEW_BEST_RESULT_SLACK_HOOK:"
announcement-hook: "_env:ANNOUNCEMENT_HOOK:"
server-ssh-public-key: "_env:SERVER_SSH_PUBLIC_KEY:"
is-public: "_env:IS_PUBLIC:true"