Skip to content

Commit 12b01d1

Browse files
committed
Merge #146: Split BuildPending into BuildStarted.
Approved-by: rudymatela Auto-deploy: false
2 parents ff6b394 + febcaa2 commit 12b01d1

File tree

6 files changed

+108
-73
lines changed

6 files changed

+108
-73
lines changed

src/EventLoop.hs

+6-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ eventFromCommentPayload payload =
7373
_ -> Nothing
7474

7575
mapCommitStatus :: Github.CommitStatus -> Maybe Text.Text -> Project.BuildStatus
76-
mapCommitStatus status url = case status of
77-
Github.Pending -> Project.BuildPending url
76+
mapCommitStatus status murl = case status of
77+
Github.Pending -> case murl of
78+
Nothing -> Project.BuildPending
79+
Just url -> Project.BuildStarted url
7880
Github.Success -> Project.BuildSucceeded
79-
Github.Failure -> Project.BuildFailed url
80-
Github.Error -> Project.BuildFailed url
81+
Github.Failure -> Project.BuildFailed murl
82+
Github.Error -> Project.BuildFailed murl
8183

8284
eventFromCommitStatusPayload :: CommitStatusPayload -> Logic.Event
8385
eventFromCommitStatusPayload payload =

src/Logic.hs

+7-9
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ handleBuildStatusChanged buildSha newStatus = pure . Pr.updatePullRequests setBu
551551
Integrated candidateSha oldStatus | candidateSha == buildSha && newStatus /= oldStatus ->
552552
pr { Pr.integrationStatus = Integrated buildSha newStatus
553553
, Pr.needsFeedback = case newStatus of
554-
BuildPending (Just _) -> True
555-
BuildFailed _ -> True
556-
_ -> Pr.needsFeedback pr -- unchanged
554+
BuildStarted _ -> True
555+
BuildFailed _ -> True
556+
_ -> Pr.needsFeedback pr -- unchanged
557557
}
558558
_ -> pr
559559

@@ -655,7 +655,7 @@ tryIntegratePullRequest pr state =
655655
-- as pushing should have triggered a build.
656656
pure
657657
-- The build pending has no URL here, we need to wait for semaphore
658-
$ Pr.setIntegrationStatus pr (Integrated (Sha sha) (BuildPending Nothing))
658+
$ Pr.setIntegrationStatus pr (Integrated (Sha sha) BuildPending)
659659
$ Pr.setNeedsFeedback pr True
660660
$ state
661661

@@ -734,11 +734,9 @@ describeStatus prId pr state = case Pr.classifyPullRequest pr of
734734
0 -> format "Pull request approved for {} by @{}, rebasing now." [approvalCommand, approvedBy]
735735
1 -> format "Pull request approved for {} by @{}, waiting for rebase behind one pull request." [approvalCommand, approvedBy]
736736
n -> format "Pull request approved for {} by @{}, waiting for rebase behind {} pull requests." (approvalCommand, approvedBy, n)
737-
PrStatusBuildPending url ->
738-
let Sha sha = fromJust $ getIntegrationSha pr
739-
in case url of
740-
Just url' -> Text.concat ["Waiting on CI job: ", url']
741-
Nothing -> Text.concat ["Rebased as ", sha, ", waiting for CI …"]
737+
PrStatusBuildPending -> let Sha sha = fromJust $ getIntegrationSha pr
738+
in Text.concat ["Rebased as ", sha, ", waiting for CI …"]
739+
PrStatusBuildStarted url -> Text.concat ["[CI job](", url, ") started."]
742740
PrStatusIntegrated -> "The build succeeded."
743741
PrStatusIncorrectBaseBranch -> "Merge rejected: the target branch must be the integration branch."
744742
PrStatusWrongFixups -> "Pull request cannot be integrated as it contains fixup commits that do not belong to any other commits."

src/Project.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ import qualified Data.IntMap.Strict as IntMap
7171
import Types (PullRequestId (..), Username)
7272

7373
data BuildStatus
74-
= BuildPending (Maybe Text)
74+
= BuildPending
75+
| BuildStarted Text
7576
| BuildSucceeded
7677
| BuildFailed (Maybe Text)
7778
deriving (Eq, Show, Generic)
@@ -97,7 +98,8 @@ data IntegrationStatus
9798
data PullRequestStatus
9899
= PrStatusAwaitingApproval -- New, awaiting review.
99100
| PrStatusApproved -- Approved, but not yet integrated or built.
100-
| PrStatusBuildPending (Maybe Text) -- Integrated, and build pending or in progress.
101+
| PrStatusBuildPending -- Integrated, and build pending or in progress.
102+
| PrStatusBuildStarted Text -- Integrated, and build pending or in progress.
101103
| PrStatusIntegrated -- Integrated, build passed, merged into target branch.
102104
| PrStatusIncorrectBaseBranch -- ^ Integration branch not being valid.
103105
| PrStatusWrongFixups -- Failed to integrate due to the presence of orphan fixup commits.
@@ -294,7 +296,8 @@ classifyPullRequest pr = case approval pr of
294296
Conflicted _ EmptyRebase -> PrStatusEmptyRebase
295297
Conflicted _ _ -> PrStatusFailedConflict
296298
Integrated _ buildStatus -> case buildStatus of
297-
BuildPending url -> PrStatusBuildPending url
299+
BuildPending -> PrStatusBuildPending
300+
BuildStarted url -> PrStatusBuildStarted url
298301
BuildSucceeded -> PrStatusIntegrated
299302
BuildFailed url -> PrStatusFailedBuild url
300303
Promoted -> PrStatusIntegrated
@@ -364,7 +367,8 @@ isInProgress pr = case approval pr of
364367
IncorrectBaseBranch -> False
365368
Conflicted _ _ -> False
366369
Integrated _ buildStatus -> case buildStatus of
367-
BuildPending _ -> True
370+
BuildPending -> True
371+
BuildStarted _ -> True
368372
BuildSucceeded -> False
369373
BuildFailed _ -> False
370374
Promoted -> False
@@ -379,7 +383,8 @@ wasIntegrationAttemptFor commit pr = case integrationStatus pr of
379383
integratedPullRequests :: ProjectState -> [PullRequestId]
380384
integratedPullRequests = filterPullRequestsBy $ isIntegrated . integrationStatus
381385
where
382-
isIntegrated (Integrated _ (BuildPending _)) = True
386+
isIntegrated (Integrated _ BuildPending) = True
387+
isIntegrated (Integrated _ (BuildStarted _)) = True
383388
isIntegrated (Integrated _ BuildSucceeded) = True
384389
isIntegrated _ = False
385390

src/WebInterface.hs

+49-19
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import qualified Data.ByteString.Lazy as LazyByteString
3030
import qualified Data.Text as Text
3131

3232
import Format (format)
33+
import Git (Sha(..))
3334
import Project (Approval (..), BuildStatus (..), IntegrationStatus (..), Owner, ProjectInfo,
3435
ProjectState, PullRequest (integrationStatus))
3536
import Types (PullRequestId (..), Username (..))
@@ -228,24 +229,27 @@ viewGroupedProjectQueues projects = do
228229

229230
-- Renders the contents of a list item with a link for a pull request.
230231
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 " "
249253

250254
viewPullRequestWithApproval :: ProjectInfo -> PullRequestId -> PullRequest -> Html
251255
viewPullRequestWithApproval info prId pullRequest = do
@@ -270,11 +274,37 @@ viewList :: (ProjectInfo -> PullRequestId -> PullRequest -> Html)
270274
-> Html
271275
viewList view info prs = forM_ prs $ \(prId, pr, _) -> p $ view info prId pr
272276

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+
273302
prFailed :: Project.PullRequestStatus -> Bool
274303
prFailed Project.PrStatusFailedConflict = True
275304
prFailed (Project.PrStatusFailedBuild _) = True
276305
prFailed _ = False
277306

278307
prPending :: Project.PullRequestStatus -> Bool
279-
prPending (Project.PrStatusBuildPending _) = True
308+
prPending Project.PrStatusBuildPending = True
309+
prPending (Project.PrStatusBuildStarted _) = True
280310
prPending _ = False

tests/EventLoopSpec.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ eventLoopSpec = parallel $ do
849849
let Just pullRequest4 = Project.lookupPullRequest pr4 state
850850
Integrated _ buildStatus = Project.integrationStatus pullRequest4
851851
-- Expect no CI url
852-
buildStatus `shouldBe` BuildPending Nothing
852+
buildStatus `shouldBe` BuildPending
853853

854854
-- We did not send a build status notification for c4, so it should not
855855
-- have been integrated.

0 commit comments

Comments
 (0)