Skip to content

Commit

Permalink
chore: removed all legacy code and cleaned up various things
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 19, 2024
1 parent 0fafced commit ee6de5a
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 503 deletions.
68 changes: 17 additions & 51 deletions src/elm/Api/Operations_.elm → src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0
--}


module Api.Operations_ exposing
module Api.Operations exposing
( enableRepo
, finishAuthentication
, getCurrentUser
Expand All @@ -17,46 +17,12 @@ module Api.Operations_ exposing
)

import Api.Api exposing (Request, delete, get, patch, post, put, withAuth)
import Api.Endpoint as Endpoint exposing (Endpoint)
import Api.Pagination as Pagination
import Auth.Jwt exposing (JwtAccessToken, decodeJwtAccessToken)
import Api.Endpoint
import Auth.Jwt exposing (JwtAccessToken)
import Auth.Session exposing (Session(..))
import Http
import Json.Decode
import Vela
exposing
( AuthParams
, BuildGraph
, BuildNumber
, Builds
, CurrentUser
, Deployment
, DeploymentId
, Engine
, Event
, Hook
, HookNumber
, Hooks
, Key
, Log
, Name
, Org
, PipelineConfig
, Ref
, Repo
, Schedule
, ScheduleName
, Schedules
, Secret
, Secrets
, Service
, ServiceNumber
, SourceRepositories
, Step
, StepNumber
, Templates
, Type
)



Expand All @@ -67,76 +33,76 @@ import Vela
-}
getToken : String -> Request JwtAccessToken
getToken baseUrl =
get baseUrl Endpoint.Token decodeJwtAccessToken
get baseUrl Api.Endpoint.Token Auth.Jwt.decodeJwtAccessToken


{-| finishAuthentication : complete authentication by supplying code and state to the authenciate endpoint
which will also set the refresh token cookie
-}
finishAuthentication : String -> AuthParams -> Request JwtAccessToken
finishAuthentication : String -> Vela.AuthParams -> Request JwtAccessToken
finishAuthentication baseUrl { code, state } =
get baseUrl (Endpoint.Authenticate { code = code, state = state }) decodeJwtAccessToken
get baseUrl (Api.Endpoint.Authenticate { code = code, state = state }) Auth.Jwt.decodeJwtAccessToken


{-| logout: logs the user out by deleting the refresh token cookie
-}
logout : String -> Session -> Request String
logout baseUrl session =
get baseUrl Endpoint.Logout Json.Decode.string
get baseUrl Api.Endpoint.Logout Json.Decode.string
|> withAuth session


{-| getCurrentUser : retrieves the currently authenticated user with the current user endpoint
-}
getCurrentUser : String -> Session -> Request CurrentUser
getCurrentUser : String -> Session -> Request Vela.CurrentUser
getCurrentUser baseUrl session =
get baseUrl Endpoint.CurrentUser Vela.decodeCurrentUser
get baseUrl Api.Endpoint.CurrentUser Vela.decodeCurrentUser
|> withAuth session


{-| updateCurrentUser : updates the currently authenticated user with the current user endpoint
-}
updateCurrentUser : String -> Session -> Http.Body -> Request CurrentUser
updateCurrentUser : String -> Session -> Http.Body -> Request Vela.CurrentUser
updateCurrentUser baseUrl session body =
put baseUrl Endpoint.CurrentUser body Vela.decodeCurrentUser
put baseUrl Api.Endpoint.CurrentUser body Vela.decodeCurrentUser
|> withAuth session


{-| getUserSourceRepos : retrieves the current users source repositories
-}
getUserSourceRepos : String -> Session -> Request SourceRepositories
getUserSourceRepos : String -> Session -> Request Vela.SourceRepositories
getUserSourceRepos baseUrl session =
get baseUrl Endpoint.UserSourceRepositories Vela.decodeSourceRepositories
get baseUrl Api.Endpoint.UserSourceRepositories Vela.decodeSourceRepositories
|> withAuth session


{-| enableRepo : enables a repo
-}
enableRepo : String -> Session -> Http.Body -> Request Vela.Repository
enableRepo baseUrl session body =
post baseUrl (Endpoint.Repositories Nothing Nothing) body Vela.decodeRepository
post baseUrl (Api.Endpoint.Repositories Nothing Nothing) body Vela.decodeRepository
|> withAuth session


{-| getOrgRepos : retrieves the repositories for an org
-}
getOrgRepos : String -> Session -> { a | org : String } -> Request (List Vela.Repository)
getOrgRepos baseUrl session { org } =
get baseUrl (Endpoint.OrgRepositories Nothing Nothing org) Vela.decodeRepositories
get baseUrl (Api.Endpoint.OrgRepositories Nothing Nothing org) Vela.decodeRepositories
|> withAuth session


{-| getRepoBuilds : retrieves builds for a repo
-}
getRepoBuilds : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String } -> Request (List Vela.Build)
getRepoBuilds baseUrl session options =
get baseUrl (Endpoint.Builds options.pageNumber options.perPage options.maybeEvent options.org options.repo) Vela.decodeBuilds
get baseUrl (Api.Endpoint.Builds options.pageNumber options.perPage options.maybeEvent options.org options.repo) Vela.decodeBuilds
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int } -> Request (List Vela.Deployment)
getRepoDeployments baseUrl session options =
get baseUrl (Endpoint.Deployments options.pageNumber options.perPage options.org options.repo) Vela.decodeDeployments
get baseUrl (Api.Endpoint.Deployments options.pageNumber options.perPage options.org options.repo) Vela.decodeDeployments
|> withAuth session
2 changes: 1 addition & 1 deletion src/elm/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ onPageLoad shared route =

Unauthenticated ->
Auth.Action.pushRoute
{ path = Route.Path.Login_
{ path = Route.Path.AccountLogin_
, query =
Dict.fromList
[ ( "from", Route.toString route ) ]
Expand Down
6 changes: 3 additions & 3 deletions src/elm/Components/Crumbs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,21 @@ toCrumbs path =
-- ( "#" ++ buildNumber, Nothing )
-- in
-- [ overviewCrumbLink, orgReposCrumbLink, repoBuildsCrumbLink, buildNumberCrumbStatic ]
Route.Path.Login_ ->
Route.Path.AccountLogin_ ->
let
loginCrumbStatic =
( "Login", Nothing )
in
[ accountCrumbStatic, loginCrumbStatic ]

Route.Path.Logout_ ->
Route.Path.AccountLogout_ ->
let
logoutCrumbStatic =
( "Logout", Nothing )
in
[ accountCrumbStatic, logoutCrumbStatic ]

Route.Path.Authenticate_ ->
Route.Path.AccountAuthenticate_ ->
let
loginCrumbStatic =
( "Login", Nothing )
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Components/Header.elm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ view { session, feedbackLink, docsLink, theme, setTheme, help, showId, showHideI
, li [ class "identity-menu-item" ]
[ a
[ Util.testAttribute "logout-link"
, Route.Path.href Route.Path.Logout_
, Route.Path.href Route.Path.AccountLogout_
, attribute "role" "menuitem"
]
[ text "Logout" ]
Expand Down
29 changes: 23 additions & 6 deletions 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, alertsUpdate, enableRepo, focusOn, getCurrentUser, getOrgRepos, getRepoBuilds, getRepoDeployments, gotoPage, handleHttpError, logout, pushPath, setTheme, updateFavorites
, addAlertError, addAlertSuccess, alertsUpdate, clearRedirect, enableRepo, finishAuthentication, focusOn, getCurrentUser, getOrgRepos, getRepoBuilds, getRepoDeployments, gotoPage, handleHttpError, logout, pushPath, setRedirect, setTheme, updateFavorites
)

{-|
Expand All @@ -24,14 +24,16 @@ module Effect exposing
-}

import Api.Api as Api
import Api.Operations_
import Api.Operations
import Auth.Session exposing (Session(..))
import Browser.Navigation
import Components.Alerts exposing (Alert)
import Components.Favorites as Favorites
import Dict exposing (Dict)
import Http
import Http.Detailed
import Interop
import Json.Encode
import Route
import Route.Path
import Shared.Model
Expand Down Expand Up @@ -222,6 +224,21 @@ setTheme options =
SendSharedMsg <| Shared.Msg.SetTheme options


setRedirect : { redirect : String } -> Effect msg
setRedirect options =
sendCmd <| Interop.setRedirect <| Json.Encode.string options.redirect


clearRedirect : {} -> Effect msg
clearRedirect _ =
sendCmd <| Interop.setRedirect <| Json.Encode.null


finishAuthentication : { code : Maybe String, state : Maybe String } -> Effect msg
finishAuthentication options =
SendSharedMsg <| Shared.Msg.FinishAuthentication options


logout : {} -> Effect msg
logout _ =
SendSharedMsg <| Shared.Msg.Logout
Expand Down Expand Up @@ -256,7 +273,7 @@ enableRepo options =
in
Api.try
options.onResponse
(Api.Operations_.enableRepo options.baseUrl options.session body)
(Api.Operations.enableRepo options.baseUrl options.session body)
|> sendCmd


Expand All @@ -274,7 +291,7 @@ getRepoBuilds :
getRepoBuilds options =
Api.try
options.onResponse
(Api.Operations_.getRepoBuilds options.baseUrl options.session options)
(Api.Operations.getRepoBuilds options.baseUrl options.session options)
|> sendCmd


Expand All @@ -288,7 +305,7 @@ getOrgRepos :
getOrgRepos options =
Api.try
options.onResponse
(Api.Operations_.getOrgRepos options.baseUrl options.session options)
(Api.Operations.getOrgRepos options.baseUrl options.session options)
|> sendCmd


Expand All @@ -305,7 +322,7 @@ getRepoDeployments :
getRepoDeployments options =
Api.try
options.onResponse
(Api.Operations_.getRepoDeployments options.baseUrl options.session options)
(Api.Operations.getRepoDeployments options.baseUrl options.session options)
|> sendCmd


Expand Down
25 changes: 16 additions & 9 deletions src/elm/Interop.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ SPDX-License-Identifier: Apache-2.0
--}


port module Interop exposing (onGraphInteraction, onThemeChange, renderBuildGraph, setFavicon, setRedirect, setTheme)
port module Interop exposing
( onGraphInteraction
, onThemeChange
, renderBuildGraph
, setFavicon
, setRedirect
, setTheme
)

import Json.Decode as Decode
import Json.Encode as Encode
import Json.Decode
import Json.Encode



Expand All @@ -15,7 +22,7 @@ import Json.Encode as Encode

{-| outbound
-}
port setRedirect : Encode.Value -> Cmd msg
port setRedirect : Json.Encode.Value -> Cmd msg



Expand All @@ -24,12 +31,12 @@ port setRedirect : Encode.Value -> Cmd msg

{-| inbound
-}
port onThemeChange : (Decode.Value -> msg) -> Sub msg
port onThemeChange : (Json.Decode.Value -> msg) -> Sub msg


{-| outbound
-}
port setTheme : Encode.Value -> Cmd msg
port setTheme : Json.Encode.Value -> Cmd msg



Expand All @@ -38,7 +45,7 @@ port setTheme : Encode.Value -> Cmd msg

{-| outbound
-}
port setFavicon : Encode.Value -> Cmd msg
port setFavicon : Json.Encode.Value -> Cmd msg



Expand All @@ -47,9 +54,9 @@ port setFavicon : Encode.Value -> Cmd msg

{-| outbound
-}
port renderBuildGraph : Encode.Value -> Cmd msg
port renderBuildGraph : Json.Encode.Value -> Cmd msg


{-| inbound
-}
port onGraphInteraction : (Decode.Value -> msg) -> Sub msg
port onGraphInteraction : (Json.Decode.Value -> msg) -> Sub msg
Loading

0 comments on commit ee6de5a

Please sign in to comment.