@@ -30,6 +30,7 @@ import qualified Data.ByteString.Lazy as LazyByteString
30
30
import qualified Data.Text as Text
31
31
32
32
import Format (format )
33
+ import Git (Sha (.. ))
33
34
import Project (Approval (.. ), BuildStatus (.. ), IntegrationStatus (.. ), Owner , ProjectInfo ,
34
35
ProjectState , PullRequest (integrationStatus ))
35
36
import Types (PullRequestId (.. ), Username (.. ))
@@ -228,24 +229,27 @@ viewGroupedProjectQueues projects = do
228
229
229
230
-- Renders the contents of a list item with a link for a pull request.
230
231
viewPullRequest :: ProjectInfo -> PullRequestId -> PullRequest -> Html
231
- viewPullRequest info (PullRequestId n) pullRequest =
232
- let
233
- url = format " https://github.com/{}/{}/pull/{}"
234
- (Project. owner info, Project. repository info, n)
235
- in do
236
- a ! href (toValue url) $ toHtml $ Project. title pullRequest
237
- span ! class_ " prId" $ toHtml $ " #" <> (show n)
238
-
239
- case integrationStatus pullRequest of
240
- Integrated _ (BuildPending (Just ciUrl)) -> do
241
- span " | "
242
- a ! href (toValue ciUrl) $ " View in CI"
243
-
244
- Integrated _ (BuildFailed (Just ciUrl)) -> do
245
- span " | "
246
- a ! href (toValue ciUrl) $ " View in CI"
247
-
248
- _ -> pure ()
232
+ viewPullRequest info pullRequestId pullRequest = do
233
+ a ! href (toValue $ pullRequestUrl info pullRequestId) $ toHtml $ Project. title pullRequest
234
+ span ! class_ " prId" $ toHtml $ prettyPullRequestId pullRequestId
235
+
236
+ case integrationStatus pullRequest of
237
+ Integrated sha buildStatus -> do
238
+ span " | "
239
+ case buildStatus of
240
+ (BuildStarted ciUrl) -> ciLink ciUrl " 🟡"
241
+ (BuildFailed (Just ciUrl)) -> ciLink ciUrl " ❌"
242
+ _ -> pure ()
243
+ a ! href (toValue $ commitUrl info sha) $ toHtml $ prettySha sha
244
+ case buildStatus of
245
+ (BuildStarted ciUrl) -> span " | " >> ciLink ciUrl " CI build"
246
+ (BuildFailed (Just ciUrl)) -> span " | " >> ciLink ciUrl " CI build"
247
+ _ -> pure ()
248
+ _ -> pure ()
249
+ where
250
+ ciLink url text = do
251
+ a ! href (toValue url) $ text
252
+ span " "
249
253
250
254
viewPullRequestWithApproval :: ProjectInfo -> PullRequestId -> PullRequest -> Html
251
255
viewPullRequestWithApproval info prId pullRequest = do
@@ -270,11 +274,37 @@ viewList :: (ProjectInfo -> PullRequestId -> PullRequest -> Html)
270
274
-> Html
271
275
viewList view info prs = forM_ prs $ \ (prId, pr, _) -> p $ view info prId pr
272
276
277
+ -- | Formats a pull request URL
278
+ pullRequestUrl :: ProjectInfo -> PullRequestId -> Text
279
+ pullRequestUrl info (PullRequestId n) =
280
+ format " https://github.com/{}/{}/pull/{}"
281
+ ( Project. owner info
282
+ , Project. repository info
283
+ , n
284
+ )
285
+
286
+ commitUrl :: ProjectInfo -> Sha -> Text
287
+ commitUrl info (Sha sha) =
288
+ format " https://github.com/{}/{}/commit/{}"
289
+ ( Project. owner info
290
+ , Project. repository info
291
+ , sha
292
+ )
293
+
294
+ -- | Textual rendering of a PullRequestId as #number
295
+ prettyPullRequestId :: PullRequestId -> String
296
+ prettyPullRequestId (PullRequestId n) = " #" <> show n
297
+
298
+ -- | Textual rendering of a Sha with just the first 7 characters
299
+ prettySha :: Sha -> Text
300
+ prettySha (Sha sha) = Text. take 7 sha
301
+
273
302
prFailed :: Project. PullRequestStatus -> Bool
274
303
prFailed Project. PrStatusFailedConflict = True
275
304
prFailed (Project. PrStatusFailedBuild _) = True
276
305
prFailed _ = False
277
306
278
307
prPending :: Project. PullRequestStatus -> Bool
279
- prPending (Project. PrStatusBuildPending _) = True
308
+ prPending Project. PrStatusBuildPending = True
309
+ prPending (Project. PrStatusBuildStarted _) = True
280
310
prPending _ = False
0 commit comments