Skip to content

Commit

Permalink
fix(api): don't raise error if the application isn't linked to a repo…
Browse files Browse the repository at this point in the history
…sitory (#3302)
  • Loading branch information
yesnault authored and fsamin committed Sep 10, 2018
1 parent bbe65ce commit 7b89844
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion engine/api/repositoriesmanager/repositories_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *localAuthorizedClientCache) Get(repo *sdk.ProjectVCSServer) (sdk.VCSAut
//AuthorizedClient returns an implementation of AuthorizedClient wrapping calls to vcs uService
func AuthorizedClient(ctx context.Context, db gorp.SqlExecutor, store cache.Store, repo *sdk.ProjectVCSServer) (sdk.VCSAuthorizedClient, error) {
if repo == nil {
return nil, sdk.ErrUnauthorized
return nil, sdk.ErrNoReposManagerClientAuth
}

vcs, has := local.Get(repo)
Expand Down
46 changes: 23 additions & 23 deletions engine/api/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,31 @@ func (api *API) getApplicationOverviewHandler() service.Handler {

// GET VCS URL
// Get vcs info to known if we are on the default branch or not
projectVCSServer := repositoriesmanager.GetProjectVCSServer(p, app.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, projectVCSServer)
if erra != nil {
return sdk.WrapError(erra, "getApplicationOverviewHandler> Cannot get repo client %s : %v", app.VCSServer)
}
vcsRepo, errRepo := client.RepoByFullname(ctx, app.RepositoryFullname)
if errRepo != nil {
return sdk.WrapError(errRepo, "getApplicationOverviewHandler> unable to get repo")
}
appOverview.GitURL = vcsRepo.URL
defaultBranch, errB := repositoriesmanager.DefaultBranch(ctx, client, app.RepositoryFullname)
if errB != nil {
return sdk.WrapError(errB, "getApplicationOverviewHandler> Unable to get default branch")
}

// GET LAST BUILD
if projectVCSServer := repositoriesmanager.GetProjectVCSServer(p, app.VCSServer); projectVCSServer != nil {
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, projectVCSServer)
if erra != nil {
return sdk.WrapError(sdk.ErrNoReposManagerClientAuth, "getApplicationOverviewHandler> Cannot get repo client %s : %v", app.VCSServer)
}
vcsRepo, errRepo := client.RepoByFullname(ctx, app.RepositoryFullname)
if errRepo != nil {
return sdk.WrapError(errRepo, "getApplicationOverviewHandler> unable to get repo")
}
appOverview.GitURL = vcsRepo.URL
defaultBranch, errB := repositoriesmanager.DefaultBranch(ctx, client, app.RepositoryFullname)
if errB != nil {
return sdk.WrapError(errB, "getApplicationOverviewHandler> Unable to get default branch")
}

tagFilter := make(map[string]string, 1)
tagFilter["git.branch"] = defaultBranch
for _, w := range app.Usage.Workflows {
runs, _, _, _, errR := workflow.LoadRuns(api.mustDB(), key, w.Name, 0, 5, tagFilter)
if errR != nil {
return sdk.WrapError(errR, "getApplicationOverviewHandler> Unable to load runs")
// GET LAST BUILD
tagFilter := make(map[string]string, 1)
tagFilter["git.branch"] = defaultBranch
for _, w := range app.Usage.Workflows {
runs, _, _, _, errR := workflow.LoadRuns(api.mustDB(), key, w.Name, 0, 5, tagFilter)
if errR != nil {
return sdk.WrapError(errR, "getApplicationOverviewHandler> Unable to load runs")
}
appOverview.History[w.Name] = runs
}
appOverview.History[w.Name] = runs
}

return service.WriteJSON(w, appOverview, http.StatusOK)
Expand Down

0 comments on commit 7b89844

Please sign in to comment.