Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elm-git.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"git-dependencies": {
"direct": {
"https://github.com/unisonweb/ui-core": "eac431215dca20541fc9d3e8d919085e4ce6fe15"
"https://github.com/unisonweb/ui-core": "dcdfc425a673e2ce0f58dc536a611d2883f0d50d"
},
"indirect": {}
}
Expand Down
20 changes: 20 additions & 0 deletions src/UnisonShare/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ project projectRef =
GET { path = [ "users", handle, "projects", slug ], queryParams = [] }


projectContributionChecks : ProjectRef -> ContributionRef -> Endpoint
projectContributionChecks projectRef contrib =
let
( handle, slug ) =
ProjectRef.toApiStringParts projectRef
in
GET
{ path =
[ "users"
, handle
, "projects"
, slug
, "contributions"
, ContributionRef.toApiString contrib
, "checks"
]
, queryParams = []
}


type ProjectBranchesKindFilter
= AllBranches (Maybe UserHandle)
| ContributorBranches (Maybe UserHandle)
Expand Down
179 changes: 179 additions & 0 deletions src/UnisonShare/Check.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
module UnisonShare.Check exposing (..)

import Code.BranchRef as BranchRef exposing (BranchRef)
import Code.Hash as Hash exposing (Hash)
import Json.Decode as Decode
import Json.Decode.Pipeline exposing (required)
import Lib.Decode.Helpers exposing (url, whenTagIs)
import Lib.UserHandle as UserHandle exposing (UserHandle)
import Parser exposing (Parser)
import UI.DateTime as DateTime exposing (DateTime)
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
import Url exposing (Url)


type CheckStatus
= NotStarted
| Waiting { startedAt : DateTime }
| TimeOut
{ startedAt : DateTime
, endedAt : DateTime
}
| Failure
{ startedAt : DateTime
, endedAt : DateTime
, errorTitle : String
, errorDetails : String
, output : String
}
| Success
{ startedAt : DateTime
, endedAt : DateTime
, output : String
}


type Runner
= LocalUcm UserHandle
| Webhook Url


type alias Check =
{ id : CheckId
, runner : Runner
, projectRef : ProjectRef
, branchRef : BranchRef
, causalHash : Hash
, createdAt : DateTime
, updatedAt : DateTime
, status : CheckStatus
}



-- CheckId


type CheckId
= CheckId String


checkIdToString : CheckId -> String
checkIdToString (CheckId raw) =
raw


{-| TODO
-}
checkIdFromString : String -> Maybe CheckId
checkIdFromString raw =
Just (CheckId raw)


checkIdFromUrl : Parser CheckId
checkIdFromUrl =
let
parseMaybe checkId =
case checkId of
Just checkId_ ->
Parser.succeed checkId_

Nothing ->
Parser.problem "Invalid CheckId"
in
Parser.chompUntilEndOr "/"
|> Parser.getChompedString
|> Parser.map checkIdFromString
|> Parser.andThen parseMaybe


title : Check -> String
title check =
""



-- DECODE


decodeRunner : Decode.Decoder Runner
decodeRunner =
Decode.oneOf
[ whenTagIs "Local" (Decode.map LocalUcm (Decode.field "handle" UserHandle.decode))
, whenTagIs "Webhook" (Decode.map Webhook (Decode.field "url" url))
]


decodeStatus : Decode.Decoder CheckStatus
decodeStatus =
let
decodeWaiting =
Decode.succeed (\s -> Waiting { startedAt = s })
|> required "startedAt" DateTime.decode

decodeTimeOut =
Decode.succeed (\s e -> TimeOut { startedAt = s, endedAt = e })
|> required "startedAt" DateTime.decode
|> required "endedAt" DateTime.decode

decodeFailure =
let
mkFailure started ended error errorDetails output =
Failure
{ startedAt = started
, endedAt = ended
, errorTitle = error
, errorDetails = errorDetails
, output = output
}
in
Decode.succeed mkFailure
|> required "startedAt" DateTime.decode
|> required "endedAt" DateTime.decode
|> required "errorTitle" Decode.string
|> required "errorDetails" Decode.string
|> required "output" Decode.string

decodeSuccess =
Decode.succeed (\s e o -> Success { startedAt = s, endedAt = e, output = o })
|> required "startedAt" DateTime.decode
|> required "endedAt" DateTime.decode
|> required "output" Decode.string
in
Decode.oneOf
[ whenTagIs "NotStarted" (Decode.succeed NotStarted)
, whenTagIs "Waiting" decodeWaiting
, whenTagIs "TimeOut" decodeTimeOut
, whenTagIs "Failure" decodeFailure
, whenTagIs "Success" decodeSuccess
]


decodeCheckId : Decode.Decoder CheckId
decodeCheckId =
Decode.map CheckId Decode.string


decode : Decode.Decoder Check
decode =
let
make id runner projectRef branchRef causalHash createdAt updatedAt status =
{ id = id
, runner = runner
, projectRef = projectRef
, branchRef = branchRef
, causalHash = causalHash
, createdAt = createdAt
, updatedAt = updatedAt
, status = status
}
in
Decode.succeed make
|> required "id" decodeCheckId
|> required "runner" decodeRunner
|> required "projectRef" ProjectRef.decode
|> required "branchRef" BranchRef.decode
|> required "causalHash" Hash.decode
|> required "createdAt" DateTime.decode
|> required "updatedAt" DateTime.decode
|> required "status" decodeStatus
11 changes: 11 additions & 0 deletions src/UnisonShare/Link.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Lib.UserHandle as UserHandle exposing (UserHandle)
import UI.Click as Click exposing (Click)
import UnisonShare.AppContext exposing (AppContext, LastActiveNotificationsTab(..))
import UnisonShare.BranchDiff.ChangeLineId exposing (ChangeLineId)
import UnisonShare.Check exposing (CheckId)
import UnisonShare.Contribution.ContributionRef exposing (ContributionRef)
import UnisonShare.Paginated as Paginated exposing (PageCursorParam)
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
Expand Down Expand Up @@ -328,6 +329,16 @@ projectContributionChange projectRef_ contribRef changeLineId =
toClick (Route.projectContributionChange projectRef_ contribRef changeLineId)


projectContributionChecks : ProjectRef -> ContributionRef -> Click msg
projectContributionChecks projectRef_ contribRef =
toClick (Route.projectContributionChecks projectRef_ contribRef)


projectContributionCheck : ProjectRef -> ContributionRef -> CheckId -> Click msg
projectContributionCheck projectRef_ contribRef checkId =
toClick (Route.projectContributionCheck projectRef_ contribRef checkId)


projectContributions : ProjectRef -> Click msg
projectContributions projectRef_ =
toClick (Route.projectContributions projectRef_)
Expand Down
Loading
Loading