Skip to content

Commit

Permalink
refactor: added helper to parse org/repo from build.link and used it …
Browse files Browse the repository at this point in the history
…to do restartBuild
  • Loading branch information
plyr4 committed Feb 6, 2024
1 parent 7d30e7e commit db9f35d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
24 changes: 10 additions & 14 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,8 @@ view shared props =
case props.build of
RemoteData.Success build ->
let
path =
build.link
|> Url.fromString
|> Maybe.Extra.unwrap build.link .path

( org, repo ) =
case Route.Path.fromString path of
Just (Route.Path.Org_Repo_Build_ params) ->
( params.org, params.repo )

_ ->
( Maybe.withDefault "" <| List.head (List.drop 1 (String.split "/" path))
, Maybe.withDefault "" <| List.head (List.drop 2 (String.split "/" path))
)
Util.orgRepoFromBuildLink build.link

repoLink =
span []
Expand Down Expand Up @@ -267,6 +255,9 @@ viewActionsMenu :
-> Html msg
viewActionsMenu props =
let
( org, repo ) =
Util.orgRepoFromBuildLink props.build.link

isMenuOpen =
List.member props.build.id props.showActionsMenus

Expand Down Expand Up @@ -309,7 +300,12 @@ viewActionsMenu props =
[ a
[ href "#"
, class "menu-item"
, Util.onClickPreventDefault <| props.msgs.restartBuild { org = "", repo = "", buildNumber = String.fromInt props.build.number }
, Util.onClickPreventDefault <|
props.msgs.restartBuild
{ org = org
, repo = repo
, buildNumber = String.fromInt props.build.number
}
, Util.testAttribute "restart-build"
]
[ text "Restart Build"
Expand Down
4 changes: 2 additions & 2 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type alias Props msg =
, builds : WebData (List Vela.Build)
, maybeEvent : Maybe String
, showFullTimestamps : Bool
, viewActionsMenu : Vela.Build -> Html msg
, viewActionsMenu : { build : Vela.Build } -> Html msg
}


Expand Down Expand Up @@ -122,7 +122,7 @@ view shared props =
Components.Build.view shared
{ build = RemoteData.succeed build
, showFullTimestamps = props.showFullTimestamps
, actionsMenu = props.viewActionsMenu build
, actionsMenu = props.viewActionsMenu { build = build }
, showActionsMenuBool = True
}
)
Expand Down
10 changes: 7 additions & 3 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ update shared route msg model =
ApproveBuild _ _ _ ->
( model, Effect.none )

RestartBuild _ ->
RestartBuild options ->
let
_ =
Debug.log "Org.Builds.RestartBuild" options
in
( model, Effect.none )

CancelBuild _ _ _ ->
Expand Down Expand Up @@ -295,13 +299,13 @@ view shared route model =
, maybeEvent = Dict.get "event" route.query
, showFullTimestamps = model.showFullTimestamps
, viewActionsMenu =
\b ->
\options ->
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
}
, build = b
, build = options.build
, showActionsMenus = model.showActionsMenus
, showActionsMenuBool = True
}
Expand Down
4 changes: 2 additions & 2 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ view shared route model =
, maybeEvent = Dict.get "event" route.query
, showFullTimestamps = model.showFullTimestamps
, viewActionsMenu =
\b ->
\options ->
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
}
, build = b
, build = options.build
, showActionsMenus = model.showActionsMenus
, showActionsMenuBool = True
}
Expand Down
27 changes: 26 additions & 1 deletion src/elm/Utils/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Utils.Helpers exposing
, onMouseDownSubscription
, oneSecondMillis
, open
, orgRepoFromBuildLink
, overwriteById
, pageToString
, relativeTimeNoSeconds
Expand All @@ -53,15 +54,18 @@ import Bytes.Decode
import DateFormat
import DateFormat.Relative exposing (defaultRelativeOptions, relativeTimeWithOptions)
import Filesize
import Html exposing (Attribute, Html, div, text)
import Html exposing (Attribute)
import Html.Attributes exposing (attribute, class)
import Html.Events exposing (custom)
import Json.Decode
import List.Extra
import Maybe.Extra
import RemoteData exposing (WebData)
import Route.Path
import String.Extra
import Task exposing (perform, succeed)
import Time exposing (Posix, Zone, posixToMillis, toHour, toMinute, utc)
import Url


{-| onMouseDownShowHelp : takes model and returns subscriptions for handling onMouseDown events at the browser level
Expand Down Expand Up @@ -549,6 +553,27 @@ buildRefURL clone ref =
String.dropRight 4 clone ++ "/tree/" ++ ref


{-| orgRepoFromBuildLink : takes build and uses the link field to parse out org and repo
if the build link has a host, then URL is used to parse, otherwise it splits on '/'
-}
orgRepoFromBuildLink : String -> ( String, String )
orgRepoFromBuildLink link =
let
path =
link
|> Url.fromString
|> Maybe.Extra.unwrap link .path
in
case Route.Path.fromString path of
Just (Route.Path.Org_Repo_Build_ params) ->
( params.org, params.repo )

_ ->
( Maybe.withDefault "" <| List.head (List.drop 1 (String.split "/" path))
, Maybe.withDefault "" <| List.head (List.drop 2 (String.split "/" path))
)


{-| trimCommitHash : takes the first 7 characters of the full commit hash
-}
trimCommitHash : String -> String
Expand Down

0 comments on commit db9f35d

Please sign in to comment.