Skip to content

Commit

Permalink
refactor(builds): repo actions menu cancel working
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Feb 7, 2024
1 parent db9f35d commit 6be7031
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Api.Operations exposing
, addRepoSchedule
, addRepoSecret
, addSharedSecret
, cancelBuild
, chownRepo
, deleteOrgSecret
, deleteRepoSchedule
Expand Down Expand Up @@ -307,6 +308,27 @@ restartBuild baseUrl session options =
|> withAuth session


cancelBuild :
String
-> Session
->
{ a
| org : String
, repo : String
, buildNumber : String
}
-> Request Vela.Build
cancelBuild baseUrl session options =
delete baseUrl
(Api.Endpoint.CancelBuild
options.org
options.repo
options.buildNumber
)
Vela.decodeBuild
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments :
Expand Down
9 changes: 7 additions & 2 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ viewActionsMenu :
{ msgs :
{ showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
, restartBuild : { org : String, repo : String, buildNumber : String } -> msg
, cancelBuild : { org : String, repo : String, buildNumber : String } -> msg
}
, build : Vela.Build
, showActionsMenus : List Int
Expand Down Expand Up @@ -319,8 +320,12 @@ viewActionsMenu props =
[ a
[ href "#"
, class "menu-item"

-- , Util.onClickPreventDefault <| props.msgs.cancelBuild org repo <| String.fromInt build.number
, Util.onClickPreventDefault <|
props.msgs.cancelBuild
{ org = org
, repo = repo
, buildNumber = String.fromInt props.build.number
}
, Util.testAttribute "cancel-build"
]
[ text "Cancel Build"
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import Vela
type alias Msgs msg =
{ approveBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, restartBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, cancelBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, cancelBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
}

Expand Down
12 changes: 11 additions & 1 deletion src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, addAlertError, addAlertSuccess, addDeployment, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSharedSecret, getSharedSecrets, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorites, updateOrgSecret, updateRepo, updateRepoSchedule, updateRepoSecret, updateSharedSecret
, addAlertError, addAlertSuccess, addDeployment, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSharedSecret, getSharedSecrets, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorites, updateOrgSecret, updateRepo, updateRepoSchedule, updateRepoSecret, updateSharedSecret
)

{-|
Expand Down Expand Up @@ -454,6 +454,16 @@ restartBuild options =
SendSharedMsg <| Shared.Msg.RestartBuild options


cancelBuild :
{ org : String
, repo : String
, buildNumber : String
}
-> Effect msg
cancelBuild options =
SendSharedMsg <| Shared.Msg.CancelBuild options


addDeployment :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
5 changes: 3 additions & 2 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type Msg
| GotoPage Int
| ApproveBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| CancelBuild Vela.Org Vela.Repo Vela.BuildNumber
| CancelBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| ShowHideActionsMenus (Maybe Int) (Maybe Bool)
| FilterByEvent (Maybe String)
| ShowHideFullTimestamps
Expand Down Expand Up @@ -178,7 +178,7 @@ update shared route msg model =
in
( model, Effect.none )

CancelBuild _ _ _ ->
CancelBuild _ ->
( model, Effect.none )

ShowHideActionsMenus build show ->
Expand Down Expand Up @@ -304,6 +304,7 @@ view shared route model =
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
, cancelBuild = CancelBuild
}
, build = options.build
, showActionsMenus = model.showActionsMenus
Expand Down
19 changes: 10 additions & 9 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Msg
| GotoPage Int
| ApproveBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| CancelBuild Vela.Org Vela.Repo Vela.BuildNumber
| CancelBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| ShowHideActionsMenus (Maybe Int) (Maybe Bool)
| FilterByEvent (Maybe String)
| ShowHideFullTimestamps
Expand Down Expand Up @@ -205,18 +205,18 @@ update shared route msg model =
}
)

-- RestartBuild _ ->
-- let
-- _ =
-- Debug.log "restart build clicked" ""
-- in
-- ( model, Effect.none )
CancelBuild _ _ _ ->
CancelBuild options ->
let
_ =
Debug.log "cancel build clicked" ""
in
( model, Effect.none )
( model
, Effect.cancelBuild
{ org = options.org
, repo = options.repo
, buildNumber = options.buildNumber
}
)

ShowHideActionsMenus build show ->
let
Expand Down Expand Up @@ -343,6 +343,7 @@ view shared route model =
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
, cancelBuild = CancelBuild
}
, build = options.build
, showActionsMenus = model.showActionsMenus
Expand Down
28 changes: 28 additions & 0 deletions src/elm/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,34 @@ update route msg model =
, Effect.handleHttpError { httpError = error }
)

Shared.Msg.CancelBuild options ->
let
_ =
Debug.log "cancel a build" options
in
( model
, Api.try
(Shared.Msg.CancelBuildResponse options)
(Api.Operations.cancelBuild model.velaAPIBaseURL model.session options)
|> Effect.sendCmd
)

Shared.Msg.CancelBuildResponse options response ->
case response of
Ok _ ->
let
canceledBuild =
"Build " ++ String.join "/" [ options.org, options.repo, options.buildNumber ]
in
( model
, Effect.addAlertSuccess { content = canceledBuild ++ " canceled.", addToastIfUnique = True }
)

Err error ->
( model
, Effect.handleHttpError { httpError = error }
)

-- HOOKS
Shared.Msg.GetRepoHooks options ->
( model
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Shared/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Msg
-- BUILD
| RestartBuild { org : String, repo : String, buildNumber : String }
| RestartBuildResponse { org : String, repo : String, buildNumber : String } (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build ))
| CancelBuild { org : String, repo : String, buildNumber : String }
| CancelBuildResponse { org : String, repo : String, buildNumber : String } (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build ))
-- HOOKS
| GetRepoHooks { org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String }
| GetRepoHooksResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Hook ))
Expand Down

0 comments on commit 6be7031

Please sign in to comment.