@@ -30,6 +30,7 @@ import Data.Submission.Query
3030import Data.Tasks.Build
3131import Data.Tasks.StatusUpdate
3232import qualified Data.Text as T
33+import Data.Time.Clock
3334import Data.Yaml
3435import GHC.Generics
3536import GitHub hiding (Accept)
@@ -49,7 +50,6 @@ import Server.Config
4950import Server.Html
5051import Server.Schema
5152import Squeal.PostgreSQL
52−import System.IO
5353import Text.Blaze.Html
5454import UnliftIO.Exception (catch, displayException, handleAny, throwIO, try)
5555
@@ -75,14 +75,18 @@ type API =
7575 :> Post '[HTML] Markup
7676 :<|> "results" :> Capture "task name" String :> Get '[CSV, HTML] [Score]
7777
78−webhookInstallation :: MonadIO m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
78+webhookInstallation :: WithLog env Message m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
7979webhookInstallation _ ((), ev) =
80− liftIO $ do
81− print ev
82− hFlush stdout
80+ logInfo . T.pack . show $ ev
8381
8482webhookPushEvent ::
85− (StaticPQ m, MonadReader (ServerData m) m, MonadUnliftIO m, HasTasks m, MonadError ServerError m) =>
83+ ( StaticPQ m,
84+ MonadReader (ServerData m) m,
85+ MonadUnliftIO m,
86+ HasTasks m,
87+ MonadError ServerError m,
88+ WithLog env Message m
89+ ) =>
8690 RepoWebhookEvent ->
8791 ((), PushEvent) ->
8892 m ()
@@ -100,18 +104,28 @@ webhookPushEvent _ ((), ev) = do
100104 M.takeWhileAntitone (repoName >) tasks
101105 case task of
102106 Just (name, TaskConfig {..}) | T.take (T.length name) repoName == name -> do
103− schedulePendingStatus (N owner) (N repoName) (N sha)
104− createSubmission $
105− Submission
106− user
107− (T.unpack fullRepoName)
108− (T.unpack name)
109− (T.unpack sha)
110− (Jsonb BuildScheduled)
111− scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
112− liftIO $ do
113− print ev
114− hFlush stdout
107+ nowTime <- liftIO getCurrentTime
108+ if nowTime > deadline
109+ then do
110+ deadlineHasPassedStatus (N owner) (N repoName) (N sha)
111+ createSubmission $
112+ Submission
113+ user
114+ (T.unpack fullRepoName)
115+ (T.unpack name)
116+ (T.unpack sha)
117+ (Jsonb PastDeadline)
118+ else do
119+ schedulePendingStatus (N owner) (N repoName) (N sha)
120+ createSubmission $
121+ Submission
122+ user
123+ (T.unpack fullRepoName)
124+ (T.unpack name)
125+ (T.unpack sha)
126+ (Jsonb BuildScheduled)
127+ scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
128+ logInfo . T.pack . show $ ev
115129 _ -> return ()
116130
117131retestSubmission ::
@@ -161,9 +175,9 @@ instance MonadError ServerError (ServerM schema) where
161175server :: ServerT API (ServerM Schema)
162176server = (webhookInstallation :<|> webhookPushEvent) :<|> getSubmissionR :<|> retestSubmission :<|> getResults
163177
164−runServer :: IO ()
165−runServer = do
166− c@Config {..} <- getConfig
178+runServer :: FilePath -> IO ()
179+runServer config = do
180+ c@Config {..} <- getConfig config
167181 print c
168182 pem <- BS.readFile appPkPemPath
169183 appPkPem <- case readRsaPem pem of
@@ -278,7 +292,7 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
278292 ( NewStatus
279293 StatusPending
280294 (Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha)
281− Nothing
295+ (Just "⌛")
282296 (Just c)
283297 )
284298 scheduleTestedStatus TestResult {..} nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
@@ -286,7 +300,7 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
286300 c <- asks context
287301 let total = M.size tests
288302 passed = M.size . M.filter id $ tests
289− description = T.pack $ show passed <> "/" <> show total
303+ description = T.pack $ show passed <> "/" <> show total <> if passed == total then " ✅" else " ❌"
290304 status =
291305 StatusUpdate
292306 nOwner
@@ -311,7 +325,22 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
311325 NewStatus
312326 { newStatusState = StatusError,
313327 newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
314− newStatusDescription = Just "Build failed",
328+ newStatusDescription = Just "Build failed ☠️",
329+ newStatusContext = Just c
330+ }
331+ scheduleTask status
332+ deadlineHasPassedStatus nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
333+ h <- asks baseUrl
334+ c <- asks context
335+ let status =
336+ StatusUpdate
337+ nOwner
338+ nRepo
339+ nCommit
340+ NewStatus
341+ { newStatusState = StatusError,
342+ newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
343+ newStatusDescription = Just "The deadline has passed ⏰",
315344 newStatusContext = Just c
316345 }
317346 scheduleTask status
@@ -325,7 +354,8 @@ data TaskConfig
325354 = TaskConfig
326355 { prebuild :: String,
327356 dockerfile :: String,
328− timeoutMinutes :: Int
357+ timeoutMinutes :: Int,
358+ deadline :: UTCTime
329359 }
330360 deriving stock (Show, Eq, Generic)
331361 deriving anyclass (FromJSON, ToJSON)