@@ -30,7 +30,6 @@ import Data.Submission.Query
30import Data.Tasks.Build
30import Data.Tasks.Build
31import Data.Tasks.StatusUpdate
31import Data.Tasks.StatusUpdate
32import qualified Data.Text as T
32import qualified Data.Text as T
33−import Data.Time.Clock
34import Data.Yaml
33import Data.Yaml
35import GHC.Generics
34import GHC.Generics
36import GitHub hiding (Accept)
35import GitHub hiding (Accept)
@@ -50,6 +49,7 @@ import Server.Config
50import Server.Html
49import Server.Html
51import Server.Schema
50import Server.Schema
52import Squeal.PostgreSQL
51import Squeal.PostgreSQL
53import Text.Blaze.Html
53import Text.Blaze.Html
54import UnliftIO.Exception (catch, displayException, handleAny, throwIO, try)
54import UnliftIO.Exception (catch, displayException, handleAny, throwIO, try)
@@ -75,18 +75,14 @@ type API =
75 :> Post '[HTML] Markup
75 :> Post '[HTML] Markup
76 :<|> "results" :> Capture "task name" String :> Get '[CSV, HTML] [Score]
76 :<|> "results" :> Capture "task name" String :> Get '[CSV, HTML] [Score]
78−webhookInstallation :: WithLog env Message m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
78+webhookInstallation :: MonadIO m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
79webhookInstallation _ ((), ev) =
79webhookInstallation _ ((), ev) =
80− logInfo . T.pack . show $ ev
80+ liftIO $ do
82webhookPushEvent ::
84webhookPushEvent ::
84− MonadReader (ServerData m) m,
85+ (StaticPQ m, MonadReader (ServerData m) m, MonadUnliftIO m, HasTasks m, MonadError ServerError m) =>
87− MonadError ServerError m,
88− WithLog env Message m
90 RepoWebhookEvent ->
86 RepoWebhookEvent ->
91 ((), PushEvent) ->
87 ((), PushEvent) ->
@@ -104,28 +100,18 @@ webhookPushEvent _ ((), ev) = do
104 M.takeWhileAntitone (repoName >) tasks
100 M.takeWhileAntitone (repoName >) tasks
105 case task of
101 case task of
106 Just (name, TaskConfig {..}) | T.take (T.length name) repoName == name -> do
102 Just (name, TaskConfig {..}) | T.take (T.length name) repoName == name -> do
107− nowTime <- liftIO getCurrentTime
108− if nowTime > deadline
110− deadlineHasPassedStatus (N owner) (N repoName) (N sha)
114− (T.unpack fullRepoName)
117− (Jsonb PastDeadline)
119− schedulePendingStatus (N owner) (N repoName) (N sha)
103+ schedulePendingStatus (N owner) (N repoName) (N sha)
120− createSubmission $
104+ createSubmission $
121− Submission
105+ Submission
123− (T.unpack fullRepoName)
107+ (T.unpack fullRepoName)
124− (T.unpack name)
108+ (T.unpack name)
125− (T.unpack sha)
109+ (T.unpack sha)
126− (Jsonb BuildScheduled)
110+ (Jsonb BuildScheduled)
127− scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
111+ scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
128− logInfo . T.pack . show $ ev
112+ liftIO $ do
129 _ -> return ()
115 _ -> return ()
131retestSubmission ::
117retestSubmission ::
@@ -175,9 +161,9 @@ instance MonadError ServerError (ServerM schema) where
175server :: ServerT API (ServerM Schema)
161server :: ServerT API (ServerM Schema)
176server = (webhookInstallation :<|> webhookPushEvent) :<|> getSubmissionR :<|> retestSubmission :<|> getResults
162server = (webhookInstallation :<|> webhookPushEvent) :<|> getSubmissionR :<|> retestSubmission :<|> getResults
178−runServer :: FilePath -> IO ()
164+runServer :: IO ()
179−runServer config = do
165+runServer = do
180− c@Config {..} <- getConfig config
166+ c@Config {..} <- getConfig
182 pem <- BS.readFile appPkPemPath
168 pem <- BS.readFile appPkPemPath
183 appPkPem <- case readRsaPem pem of
169 appPkPem <- case readRsaPem pem of
@@ -292,7 +278,7 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
292 ( NewStatus
278 ( NewStatus
293 StatusPending
279 StatusPending
294 (Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha)
280 (Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha)
295− (Just "⌛")
281+ Nothing
298 scheduleTestedStatus TestResult {..} nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
284 scheduleTestedStatus TestResult {..} nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
@@ -300,7 +286,7 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
300 c <- asks context
286 c <- asks context
301 let total = M.size tests
287 let total = M.size tests
302 passed = M.size . M.filter id $ tests
288 passed = M.size . M.filter id $ tests
303− description = T.pack $ show passed <> "/" <> show total <> if passed == total then " ✅" else " ❌"
289+ description = T.pack $ show passed <> "/" <> show total
305 StatusUpdate
291 StatusUpdate
@@ -325,22 +311,7 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
325 NewStatus
311 NewStatus
326 { newStatusState = StatusError,
312 { newStatusState = StatusError,
327 newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
313 newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
328− newStatusDescription = Just "Build failed ☠️",
314+ newStatusDescription = Just "Build failed",
329− newStatusContext = Just c
332− deadlineHasPassedStatus nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
341− { newStatusState = StatusError,
342− newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
343− newStatusDescription = Just "The deadline has passed ⏰",
344 newStatusContext = Just c
315 newStatusContext = Just c
346 scheduleTask status
317 scheduleTask status
@@ -354,8 +325,7 @@ data TaskConfig
354 = TaskConfig
325 = TaskConfig
355 { prebuild :: String,
326 { prebuild :: String,
356 dockerfile :: String,
327 dockerfile :: String,
357− timeoutMinutes :: Int,
328+ timeoutMinutes :: Int
360 deriving stock (Show, Eq, Generic)
330 deriving stock (Show, Eq, Generic)
361 deriving anyclass (FromJSON, ToJSON)
331 deriving anyclass (FromJSON, ToJSON)