Exemplo n.º 1
0
// POST /pipelines/:uuid
func UpdatePipeline(ctx *Context, form api.CreatePipelineOptions) {
	if ctx.HasError(form) {
		return
	}

	pipe := &models.Pipeline{UUID: ctx.Params(":uuid")}
	if err := pipe.Retrieve(); err != nil {
		if models.IsErrPipelineNotExist(err) {
			ctx.Handle(404, err)
		} else {
			ctx.Handle(500, "Fail to retrieve pipeline '%s': %v", pipe.UUID, err)
		}
		return
	}
	if form.Name != nil {
		pipe.Name = *form.Name
	}

	if setPrerequisites(pipe, ctx, form.Requires) {
		return
	} else if setStages(pipe, ctx, form.Stages) {
		return
	}

	if err := pipe.Save(); err != nil {
		ctx.Handle(500, "Fail to save pipeline '%s': %v", pipe.UUID, err)
		return
	}

	ctx.AutoJSON(201, pipe)
}
Exemplo n.º 2
0
// GET /pipelines/:uuid
func GetPipeline(ctx *Context) {
	pipe := &models.Pipeline{UUID: ctx.Params(":uuid")}
	if err := pipe.Retrieve(); err != nil {
		if models.IsErrPipelineNotExist(err) {
			ctx.Handle(404, err)
		} else {
			ctx.Handle(500, "Fail to retrieve pipeline '%s': %v", pipe.UUID, err)
		}
		return
	}

	ctx.AutoJSON(200, pipe)
}
Exemplo n.º 3
0
func setPipelines(flow *models.Flow, ctx *Context, pipelines []string) bool {
	if len(pipelines) == 0 {
		return false
	}
	if err := flow.SetPipelines(pipelines...); err != nil {
		if models.IsErrPipelineNotExist(err) {
			ctx.Handle(422, err)
		} else {
			ctx.Handle(500, "Fail to add pipelines to flow '%s': %v", flow.UUID, err)
		}
		return true
	}
	return false
}
Exemplo n.º 4
0
func setPrerequisites(pipe *models.Pipeline, ctx *Context, requires []string) bool {
	if len(requires) == 0 {
		return false
	}
	if err := pipe.SetPrerequisites(requires...); err != nil {
		if models.IsErrPipelineNotExist(err) ||
			models.IsErrCircularDependencies(err) {
			ctx.Handle(422, err)
		} else {
			ctx.Handle(500, "Fail to add prerequisites to pipeline '%s': %v", pipe.UUID, err)
		}
		return true
	}
	return false
}