Skip to content

Commit

Permalink
fix(api): check if an application is available on the root node of a …
Browse files Browse the repository at this point in the history
…workflow as code (#4215)

* fix(api): check if an application is available on the root node of a workflow as code
* Apply suggestions from code review
  • Loading branch information
fsamin authored and yesnault committed Apr 24, 2019
1 parent c2a4596 commit ae9f724
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,16 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
return nil, nil, sdk.WrapError(err, "unable to import workflow %s", data.wrkflw.Name)
}

// If the workflow is "as-code", it should always be linked to a git repository
if opts != nil && opts.FromRepository != "" {
if wf.Root.Context.Application == nil {
return nil, nil, sdk.WithStack(sdk.ErrApplicationMandatoryOnWorkflowAsCode)
}
if wf.Root.Context.Application.VCSServer == "" || wf.Root.Context.Application.RepositoryFullname == "" {
return nil, nil, sdk.WithStack(sdk.ErrApplicationMandatoryOnWorkflowAsCode)
}
}

if wf.Root.Context.Application != nil {
if err := application.Update(tx, store, wf.Root.Context.Application); err != nil {
return nil, nil, sdk.WrapError(err, "Unable to update application vcs datas")
Expand Down
3 changes: 3 additions & 0 deletions sdk/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ var (
ErrInvalidJobRequirementWorkerModelCapabilitites = Error{ID: 166, Status: http.StatusBadRequest}
ErrMalformattedStep = Error{ID: 167, Status: http.StatusBadRequest}
ErrVCSUsedByApplication = Error{ID: 168, Status: http.StatusBadRequest}
ErrApplicationMandatoryOnWorkflowAsCode = Error{ID: 169, Status: http.StatusBadRequest}
)

var errorsAmericanEnglish = map[int]string{
Expand Down Expand Up @@ -348,6 +349,7 @@ var errorsAmericanEnglish = map[int]string{
ErrInvalidJobRequirementWorkerModelCapabilitites.ID: "Invalid job requirements: the worker model does't match with the binary requirements",
ErrMalformattedStep.ID: "Malformatted step",
ErrVCSUsedByApplication.ID: "Repository manager still used by an application",
ErrApplicationMandatoryOnWorkflowAsCode.ID: "An application linked to a git repository is mandatory on the workflow root",
}

var errorsFrench = map[int]string{
Expand Down Expand Up @@ -513,6 +515,7 @@ var errorsFrench = map[int]string{
ErrInvalidJobRequirementWorkerModelCapabilitites.ID: "Pré-requis de job invalide: Le modèle de worker ne dispose pas de binaires suffisants",
ErrMalformattedStep.ID: "Étape malformée",
ErrVCSUsedByApplication.ID: "Le gestionnaire de dépot est encore utilisé par une application",
ErrApplicationMandatoryOnWorkflowAsCode.ID: "Une application liée à un dépôt git est obligatoire à la racine du workflow",
}

var errorsLanguages = []map[int]string{
Expand Down

0 comments on commit ae9f724

Please sign in to comment.