Skip to content

Commit 42cdbef

Browse files
authored
Merge pull request #131 from unisoncomputing/ci-status
Add ProjectContributionChecksPage
2 parents cd3c457 + 82d396b commit 42cdbef

File tree

11 files changed

+853
-2
lines changed

11 files changed

+853
-2
lines changed

elm-git.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"git-dependencies": {
33
"direct": {
4-
"https://github.com/unisonweb/ui-core": "eac431215dca20541fc9d3e8d919085e4ce6fe15"
4+
"https://github.com/unisonweb/ui-core": "dcdfc425a673e2ce0f58dc536a611d2883f0d50d"
55
},
66
"indirect": {}
77
}

src/UnisonShare/Api.elm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,26 @@ project projectRef =
325325
GET { path = [ "users", handle, "projects", slug ], queryParams = [] }
326326

327327

328+
projectContributionChecks : ProjectRef -> ContributionRef -> Endpoint
329+
projectContributionChecks projectRef contrib =
330+
let
331+
( handle, slug ) =
332+
ProjectRef.toApiStringParts projectRef
333+
in
334+
GET
335+
{ path =
336+
[ "users"
337+
, handle
338+
, "projects"
339+
, slug
340+
, "contributions"
341+
, ContributionRef.toApiString contrib
342+
, "checks"
343+
]
344+
, queryParams = []
345+
}
346+
347+
328348
type ProjectBranchesKindFilter
329349
= AllBranches (Maybe UserHandle)
330350
| ContributorBranches (Maybe UserHandle)

src/UnisonShare/Check.elm

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
module UnisonShare.Check exposing (..)
2+
3+
import Code.BranchRef as BranchRef exposing (BranchRef)
4+
import Code.Hash as Hash exposing (Hash)
5+
import Json.Decode as Decode
6+
import Json.Decode.Pipeline exposing (required)
7+
import Lib.Decode.Helpers exposing (url, whenTagIs)
8+
import Lib.UserHandle as UserHandle exposing (UserHandle)
9+
import Parser exposing (Parser)
10+
import UI.DateTime as DateTime exposing (DateTime)
11+
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
12+
import Url exposing (Url)
13+
14+
15+
type CheckStatus
16+
= NotStarted
17+
| Waiting { startedAt : DateTime }
18+
| TimeOut
19+
{ startedAt : DateTime
20+
, endedAt : DateTime
21+
}
22+
| Failure
23+
{ startedAt : DateTime
24+
, endedAt : DateTime
25+
, errorTitle : String
26+
, errorDetails : String
27+
, output : String
28+
}
29+
| Success
30+
{ startedAt : DateTime
31+
, endedAt : DateTime
32+
, output : String
33+
}
34+
35+
36+
type Runner
37+
= LocalUcm UserHandle
38+
| Webhook Url
39+
40+
41+
type alias Check =
42+
{ id : CheckId
43+
, runner : Runner
44+
, projectRef : ProjectRef
45+
, branchRef : BranchRef
46+
, causalHash : Hash
47+
, createdAt : DateTime
48+
, updatedAt : DateTime
49+
, status : CheckStatus
50+
}
51+
52+
53+
54+
-- CheckId
55+
56+
57+
type CheckId
58+
= CheckId String
59+
60+
61+
checkIdToString : CheckId -> String
62+
checkIdToString (CheckId raw) =
63+
raw
64+
65+
66+
{-| TODO
67+
-}
68+
checkIdFromString : String -> Maybe CheckId
69+
checkIdFromString raw =
70+
Just (CheckId raw)
71+
72+
73+
checkIdFromUrl : Parser CheckId
74+
checkIdFromUrl =
75+
let
76+
parseMaybe checkId =
77+
case checkId of
78+
Just checkId_ ->
79+
Parser.succeed checkId_
80+
81+
Nothing ->
82+
Parser.problem "Invalid CheckId"
83+
in
84+
Parser.chompUntilEndOr "/"
85+
|> Parser.getChompedString
86+
|> Parser.map checkIdFromString
87+
|> Parser.andThen parseMaybe
88+
89+
90+
title : Check -> String
91+
title check =
92+
""
93+
94+
95+
96+
-- DECODE
97+
98+
99+
decodeRunner : Decode.Decoder Runner
100+
decodeRunner =
101+
Decode.oneOf
102+
[ whenTagIs "Local" (Decode.map LocalUcm (Decode.field "handle" UserHandle.decode))
103+
, whenTagIs "Webhook" (Decode.map Webhook (Decode.field "url" url))
104+
]
105+
106+
107+
decodeStatus : Decode.Decoder CheckStatus
108+
decodeStatus =
109+
let
110+
decodeWaiting =
111+
Decode.succeed (\s -> Waiting { startedAt = s })
112+
|> required "startedAt" DateTime.decode
113+
114+
decodeTimeOut =
115+
Decode.succeed (\s e -> TimeOut { startedAt = s, endedAt = e })
116+
|> required "startedAt" DateTime.decode
117+
|> required "endedAt" DateTime.decode
118+
119+
decodeFailure =
120+
let
121+
mkFailure started ended error errorDetails output =
122+
Failure
123+
{ startedAt = started
124+
, endedAt = ended
125+
, errorTitle = error
126+
, errorDetails = errorDetails
127+
, output = output
128+
}
129+
in
130+
Decode.succeed mkFailure
131+
|> required "startedAt" DateTime.decode
132+
|> required "endedAt" DateTime.decode
133+
|> required "errorTitle" Decode.string
134+
|> required "errorDetails" Decode.string
135+
|> required "output" Decode.string
136+
137+
decodeSuccess =
138+
Decode.succeed (\s e o -> Success { startedAt = s, endedAt = e, output = o })
139+
|> required "startedAt" DateTime.decode
140+
|> required "endedAt" DateTime.decode
141+
|> required "output" Decode.string
142+
in
143+
Decode.oneOf
144+
[ whenTagIs "NotStarted" (Decode.succeed NotStarted)
145+
, whenTagIs "Waiting" decodeWaiting
146+
, whenTagIs "TimeOut" decodeTimeOut
147+
, whenTagIs "Failure" decodeFailure
148+
, whenTagIs "Success" decodeSuccess
149+
]
150+
151+
152+
decodeCheckId : Decode.Decoder CheckId
153+
decodeCheckId =
154+
Decode.map CheckId Decode.string
155+
156+
157+
decode : Decode.Decoder Check
158+
decode =
159+
let
160+
make id runner projectRef branchRef causalHash createdAt updatedAt status =
161+
{ id = id
162+
, runner = runner
163+
, projectRef = projectRef
164+
, branchRef = branchRef
165+
, causalHash = causalHash
166+
, createdAt = createdAt
167+
, updatedAt = updatedAt
168+
, status = status
169+
}
170+
in
171+
Decode.succeed make
172+
|> required "id" decodeCheckId
173+
|> required "runner" decodeRunner
174+
|> required "projectRef" ProjectRef.decode
175+
|> required "branchRef" BranchRef.decode
176+
|> required "causalHash" Hash.decode
177+
|> required "createdAt" DateTime.decode
178+
|> required "updatedAt" DateTime.decode
179+
|> required "status" decodeStatus

src/UnisonShare/Link.elm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Lib.UserHandle as UserHandle exposing (UserHandle)
1111
import UI.Click as Click exposing (Click)
1212
import UnisonShare.AppContext exposing (AppContext, LastActiveNotificationsTab(..))
1313
import UnisonShare.BranchDiff.ChangeLineId exposing (ChangeLineId)
14+
import UnisonShare.Check exposing (CheckId)
1415
import UnisonShare.Contribution.ContributionRef exposing (ContributionRef)
1516
import UnisonShare.Paginated as Paginated exposing (PageCursorParam)
1617
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
@@ -328,6 +329,16 @@ projectContributionChange projectRef_ contribRef changeLineId =
328329
toClick (Route.projectContributionChange projectRef_ contribRef changeLineId)
329330

330331

332+
projectContributionChecks : ProjectRef -> ContributionRef -> Click msg
333+
projectContributionChecks projectRef_ contribRef =
334+
toClick (Route.projectContributionChecks projectRef_ contribRef)
335+
336+
337+
projectContributionCheck : ProjectRef -> ContributionRef -> CheckId -> Click msg
338+
projectContributionCheck projectRef_ contribRef checkId =
339+
toClick (Route.projectContributionCheck projectRef_ contribRef checkId)
340+
341+
331342
projectContributions : ProjectRef -> Click msg
332343
projectContributions projectRef_ =
333344
toClick (Route.projectContributions projectRef_)

0 commit comments

Comments
 (0)