Skip to content

Commit

Permalink
enhance(pipeline): remove ref from URL and chain build/pipeline api c…
Browse files Browse the repository at this point in the history
…alls (#551)
  • Loading branch information
plyr4 authored May 30, 2022
1 parent fd610e5 commit fe9a18f
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 179 deletions.
16 changes: 4 additions & 12 deletions cypress/integration/pipeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ context('Pipeline', () => {
cy.stubBuild();
cy.stubPipelineErrors();
cy.stubPipelineTemplatesErrors();
cy.login(
'/github/octocat/1/pipeline/9b1d8bded6e992ab660eaee527c5e3232d0a2441',
);
cy.login('/github/octocat/1/pipeline');
});
it('pipeline configuration error should show', () => {
cy.get('[data-test=pipeline-configuration-error]').should('be.visible');
Expand All @@ -38,9 +36,7 @@ context('Pipeline', () => {
cy.stubBuild();
cy.stubPipeline();
cy.stubPipelineTemplatesEmpty();
cy.login(
'/github/octocat/1/pipeline/9b1d8bded6e992ab660eaee527c5e3232d0a2441',
);
cy.login('/github/octocat/1/pipeline');
});
it('templates should not show', () => {
cy.get('[data-test=pipeline-templates]').should('not.be.visible');
Expand All @@ -67,9 +63,7 @@ context('Pipeline', () => {
cy.stubPipeline();
cy.stubPipelineExpand();
cy.stubPipelineTemplates();
cy.login(
'/github/octocat/1/pipeline/9b1d8bded6e992ab660eaee527c5e3232d0a2441',
);
cy.login('/github/octocat/1/pipeline');
});

it('should show 3 templates', () => {
Expand Down Expand Up @@ -263,9 +257,7 @@ context('Pipeline', () => {
cy.stubPipeline();
cy.stubPipelineExpandErrors();
cy.stubPipelineTemplates();
cy.login(
'/github/octocat/1/pipeline/9b1d8bded6e992ab660eaee527c5e3232d0a2441',
);
cy.login('/github/octocat/1/pipeline');
});

it('should show 3 templates', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Crumbs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ toPath page =
, ( "#" ++ buildNumber, Nothing )
]

Pages.BuildPipeline org repo buildNumber _ _ _ ->
Pages.BuildPipeline org repo buildNumber _ _ ->
let
organizationPage =
( org, Just <| Pages.OrgRepositories org Nothing Nothing )
Expand Down
6 changes: 3 additions & 3 deletions src/elm/Help/Commands.elm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ commands page =
Pages.BuildServices org repo buildNumber _ ->
[ viewBuild org repo buildNumber, restartBuild org repo buildNumber, cancelBuild org repo buildNumber, listServices org repo buildNumber, viewService org repo buildNumber ]

Pages.BuildPipeline org repo buildNumber _ _ _ ->
Pages.BuildPipeline org repo buildNumber _ _ ->
[ viewBuild org repo buildNumber, restartBuild org repo buildNumber ]

Pages.RepoSettings org repo ->
Expand Down Expand Up @@ -789,7 +789,7 @@ resourceLoaded args =
Pages.BuildServices _ _ _ _ ->
args.build.success

Pages.BuildPipeline _ _ _ _ _ _ ->
Pages.BuildPipeline _ _ _ _ _ ->
args.build.success

Pages.AddOrgSecret secretEngine org ->
Expand Down Expand Up @@ -870,7 +870,7 @@ resourceLoading args =
Pages.BuildServices _ _ _ _ ->
args.build.loading

Pages.BuildPipeline _ _ _ _ _ _ ->
Pages.BuildPipeline _ _ _ _ _ ->
args.build.loading

Pages.OrgSecrets _ _ _ _ ->
Expand Down
134 changes: 78 additions & 56 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Focus
exposing
( ExpandTemplatesQuery
, Fragment
, RefQuery
, focusFragmentToFocusId
, lineRangeId
, parseFocusFragment
Expand Down Expand Up @@ -187,13 +186,10 @@ import Vela
, stringToTheme
, updateBuild
, updateBuildNumber
, updateBuildPipelineBuildNumber
, updateBuildPipelineConfig
, updateBuildPipelineExpand
, updateBuildPipelineFocusFragment
, updateBuildPipelineLineFocus
, updateBuildPipelineOrgRepo
, updateBuildPipelineRef
, updateBuildServices
, updateBuildServicesFocusFragment
, updateBuildServicesFollowing
Expand Down Expand Up @@ -437,6 +433,7 @@ type Msg
| DeploymentsResponse Org Repo (Result (Http.Detailed.Error String) ( Http.Metadata, List Deployment ))
| HooksResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Hooks ))
| BuildResponse Org Repo (Result (Http.Detailed.Error String) ( Http.Metadata, Build ))
| BuildAndPipelineResponse Org Repo (Maybe ExpandTemplatesQuery) (Result (Http.Detailed.Error String) ( Http.Metadata, Build ))
| DeploymentResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Deployment ))
| StepsResponse Org Repo BuildNumber FocusFragment Bool (Result (Http.Detailed.Error String) ( Http.Metadata, Steps ))
| StepLogResponse StepNumber FocusFragment Bool (Result (Http.Detailed.Error String) ( Http.Metadata, Log ))
Expand Down Expand Up @@ -1147,7 +1144,7 @@ update msg model =
}
, Cmd.batch
[ getPipelineConfig model org repo ref lineFocus refresh
, Navigation.replaceUrl model.navigationKey <| Routes.routeToUrl <| Routes.BuildPipeline org repo buildNumber ref Nothing lineFocus
, Navigation.replaceUrl model.navigationKey <| Routes.routeToUrl <| Routes.BuildPipeline org repo buildNumber Nothing lineFocus
]
)

Expand All @@ -1160,7 +1157,7 @@ update msg model =
}
, Cmd.batch
[ expandPipelineConfig model org repo ref lineFocus refresh
, Navigation.replaceUrl model.navigationKey <| Routes.routeToUrl <| Routes.BuildPipeline org repo buildNumber ref (Just "true") lineFocus
, Navigation.replaceUrl model.navigationKey <| Routes.routeToUrl <| Routes.BuildPipeline org repo buildNumber (Just "true") lineFocus
]
)

Expand Down Expand Up @@ -1507,6 +1504,40 @@ update msg model =
Err error ->
( { model | repo = updateBuild (toFailure error) rm }, addError error )

BuildAndPipelineResponse org repo expand response ->
case response of
Ok ( _, build ) ->
let
-- set pipeline fetch api call based on ?expand= query
getPipeline =
case expand of
Just e ->
if e == "true" then
expandPipelineConfig

else
getPipelineConfig

Nothing ->
getPipelineConfig
in
( { model
| repo =
rm
|> updateOrgRepo org repo
|> updateBuild (RemoteData.succeed build)
, favicon = statusToFavicon build.status
}
, Cmd.batch
[ Interop.setFavicon <| Encode.string <| statusToFavicon build.status
, getPipeline model org repo build.commit Nothing False
, getPipelineTemplates model org repo build.commit Nothing False
]
)

Err error ->
( { model | repo = updateBuild (toFailure error) rm }, addError error )

DeploymentResponse response ->
case response of
Ok ( _, deployment ) ->
Expand Down Expand Up @@ -2122,7 +2153,7 @@ refreshPage model =
, refreshServiceLogs model org repo buildNumber model.repo.build.services.services Nothing
]

Pages.BuildPipeline org repo buildNumber _ _ _ ->
Pages.BuildPipeline org repo buildNumber _ _ ->
Cmd.batch
[ getBuilds model org repo Nothing Nothing Nothing
, refreshBuild model org repo buildNumber
Expand Down Expand Up @@ -2570,12 +2601,11 @@ viewContent model =
buildNumber
)

Pages.BuildPipeline org repo buildNumber ref _ _ ->
Pages.BuildPipeline org repo buildNumber _ _ ->
( "Pipeline " ++ String.join "/" [ org, repo ]
, Pages.Pipeline.View.viewPipeline
model
pipelineMsgs
ref
|> Pages.Build.View.wrapWithBuildPreview
model
buildMsgs
Expand Down Expand Up @@ -2867,8 +2897,8 @@ setNewPage route model =
( Routes.BuildServices org repo buildNumber lineFocus, Authenticated _ ) ->
loadBuildServicesPage model org repo buildNumber lineFocus

( Routes.BuildPipeline org repo buildNumber ref expand lineFocus, Authenticated _ ) ->
loadBuildPipelinePage model org repo buildNumber ref expand lineFocus
( Routes.BuildPipeline org repo buildNumber expand lineFocus, Authenticated _ ) ->
loadBuildPipelinePage model org repo buildNumber expand lineFocus

( Routes.Settings, Authenticated _ ) ->
( { model | page = Pages.Settings, showIdentity = False }, Cmd.none )
Expand Down Expand Up @@ -3656,24 +3686,21 @@ loadBuildServicesPage model org repo buildNumber lineFocus =

{-| loadBuildPipelinePage : takes model org, repo, and ref and loads the appropriate pipeline configuration resources.
-}
loadBuildPipelinePage : Model -> Org -> Repo -> BuildNumber -> Ref -> Maybe ExpandTemplatesQuery -> Maybe Fragment -> ( Model, Cmd Msg )
loadBuildPipelinePage model org repo buildNumber ref expand lineFocus =
loadBuildPipelinePage : Model -> Org -> Repo -> BuildNumber -> Maybe ExpandTemplatesQuery -> Maybe Fragment -> ( Model, Cmd Msg )
loadBuildPipelinePage model org repo buildNumber expand lineFocus =
let
-- get resource transition information
sameBuild =
isSameBuild ( org, repo, buildNumber ) model.page

sameResource =
case model.page of
Pages.BuildPipeline _ _ _ _ _ _ ->
Pages.BuildPipeline _ _ _ _ _ ->
True

_ ->
False

sameRef =
isSamePipelineRef ( org, repo, ref ) model.page pipeline

-- if build has changed, set build fields in the model
m =
if not sameBuild then
Expand Down Expand Up @@ -3703,13 +3730,11 @@ loadBuildPipelinePage model org repo buildNumber ref expand lineFocus =
model.pipeline
in
( { m
| page = Pages.BuildPipeline org repo buildNumber ref expand lineFocus

-- set pipeline fields
| page = Pages.BuildPipeline org repo buildNumber expand lineFocus
, pipeline =
pipeline
|> updateBuildPipelineConfig
(if sameRef then
(if sameBuild then
case pipeline.config of
( Success _, _ ) ->
pipeline.config
Expand All @@ -3720,31 +3745,44 @@ loadBuildPipelinePage model org repo buildNumber ref expand lineFocus =
else
( Loading, "" )
)
|> updateBuildPipelineOrgRepo org repo
|> updateBuildPipelineBuildNumber buildNumber
|> updateBuildPipelineRef ref
|> updateBuildPipelineExpand expand
|> updateBuildPipelineLineFocus ( parsed.lineA, parsed.lineB )
|> updateBuildPipelineFocusFragment (Maybe.map (\l -> "#" ++ l) lineFocus)

-- reset templates if ref has changed
-- reset templates if build has changed
, templates =
if sameRef then
if sameBuild then
model.templates

else
{ data = Loading, error = "", show = True }
}
-- do not load resources if transition is auto refresh, line focus, etc
, if sameBuild && sameResource then
Cmd.none
, Cmd.batch <|
-- do not load resources if transition is auto refresh, line focus, etc
if sameBuild && sameResource then
[]

else if sameBuild then
-- same build, most likely a tab switch
case model.repo.build.build of
Success build ->
-- build exists, chained request not needed
[ getBuilds model org repo Nothing Nothing Nothing
, getBuild model org repo buildNumber
, getPipeline model org repo build.commit lineFocus False
, getPipelineTemplates model org repo build.commit lineFocus False
]

else
Cmd.batch
_ ->
-- no build present, use chained request
[ getBuilds model org repo Nothing Nothing Nothing
, getBuildAndPipeline model org repo buildNumber expand
]

else
-- different build, use chained request
[ getBuilds model org repo Nothing Nothing Nothing
, getBuild model org repo buildNumber
, getPipeline model org repo ref lineFocus sameBuild
, getPipelineTemplates model org repo ref lineFocus sameBuild
, getBuildAndPipeline model org repo buildNumber expand
]
)

Expand All @@ -3760,31 +3798,13 @@ isSameBuild id currentPage =
Pages.BuildServices o r b _ ->
not <| resourceChanged id ( o, r, b )

Pages.BuildPipeline o r b _ _ _ ->
Pages.BuildPipeline o r b _ _ ->
not <| resourceChanged id ( o, r, b )

_ ->
False


{-| isSamePipelineRef : takes pipeline ref identifier and current page and returns true if the pipeline ref has not changed
-}
isSamePipelineRef : RepoResourceIdentifier -> Page -> PipelineModel -> Bool
isSamePipelineRef id currentPage pipeline =
case currentPage of
Pages.Build o r _ _ ->
not <| resourceChanged id ( o, r, pipeline.ref )

Pages.BuildServices o r _ _ ->
not <| resourceChanged id ( o, r, pipeline.ref )

Pages.BuildPipeline o r _ ref _ _ ->
not <| resourceChanged id ( o, r, ref )

_ ->
False


{-| setBuild : takes new build information and sets the appropriate model state
-}
setBuild : Org -> Repo -> BuildNumber -> Bool -> Model -> Model
Expand All @@ -3804,9 +3824,6 @@ setBuild org repo buildNumber soft model =
, expand = Nothing
, expanding = False
, expanded = False
, org = org
, repo = repo
, buildNumber = buildNumber
}
, templates = { data = NotAsked, error = "", show = True }
, repo =
Expand Down Expand Up @@ -4147,6 +4164,11 @@ getBuild model org repo buildNumber =
Api.try (BuildResponse org repo) <| Api.getBuild model org repo buildNumber


getBuildAndPipeline : Model -> Org -> Repo -> BuildNumber -> Maybe ExpandTemplatesQuery -> Cmd Msg
getBuildAndPipeline model org repo buildNumber expand =
Api.try (BuildAndPipelineResponse org repo expand) <| Api.getBuild model org repo buildNumber


getDeployment : Model -> Org -> Repo -> DeploymentId -> Cmd Msg
getDeployment model org repo deploymentNumber =
Api.try DeploymentResponse <| Api.getDeployment model org repo <| Just deploymentNumber
Expand Down
14 changes: 3 additions & 11 deletions src/elm/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ navButtons model { fetchSourceRepos, toggleFavorite, restartBuild, cancelBuild }
, restartBuildButton org repo model.repo.build.build restartBuild
]

Pages.BuildPipeline org repo _ _ _ _ ->
Pages.BuildPipeline org repo _ _ _ ->
div [ class "buttons" ]
[ cancelBuildButton org repo model.repo.build.build cancelBuild
, restartBuildButton org repo model.repo.build.build restartBuild
Expand Down Expand Up @@ -219,7 +219,7 @@ viewUtil model =
Pages.BuildServices _ _ _ _ ->
Pages.Build.History.view model.time model.zone model.page 10 model.repo

Pages.BuildPipeline _ _ _ _ _ _ ->
Pages.BuildPipeline _ _ _ _ _ ->
Pages.Build.History.view model.time model.zone model.page 10 model.repo

Pages.AddDeployment org repo ->
Expand Down Expand Up @@ -362,18 +362,10 @@ viewBuildTabs model org repo buildNumber currentPage =
pipeline =
model.pipeline

ref =
case bm.build of
RemoteData.Success build ->
build.commit

_ ->
""

tabs =
[ Tab "Build" currentPage (Pages.Build org repo buildNumber bm.steps.focusFragment) False
, Tab "Services" currentPage (Pages.BuildServices org repo buildNumber bm.services.focusFragment) False
, Tab "Pipeline" currentPage (Pages.BuildPipeline org repo buildNumber ref pipeline.expand pipeline.focusFragment) False
, Tab "Pipeline" currentPage (Pages.BuildPipeline org repo buildNumber pipeline.expand pipeline.focusFragment) False
]
in
viewTabs tabs "jump-bar-build"
Expand Down
Loading

0 comments on commit fe9a18f

Please sign in to comment.