Add scaffolding for cron trigger support
This commit is contained in:
@@ -88,6 +88,33 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
},
|
||||
})
|
||||
|
||||
cronType := graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "Cron",
|
||||
Description: "A cron available for trigger pipeline runs.",
|
||||
Fields: graphql.Fields{
|
||||
"id": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
Description: "The id of the cron.",
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
if cron, ok := p.Source.(database.Cron); ok {
|
||||
return cron.Id, nil
|
||||
}
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
"cron": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
Description: "The cron.",
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
if cron, ok := p.Source.(database.Cron); ok {
|
||||
return cron.Cron, nil
|
||||
}
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
cloneCredentialType := graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "CloneCredential",
|
||||
Description: "A credential for authenticating with the pipeline source host.",
|
||||
@@ -316,6 +343,16 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
return []database.Secret{}, nil
|
||||
},
|
||||
},
|
||||
"crons": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(cronType))),
|
||||
Description: "The list of crons for the pipeline.",
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
if pipeline, ok := p.Source.(database.Pipeline); ok {
|
||||
return db.GetCronsForPipeline(pipeline.Id)
|
||||
}
|
||||
return []database.Cron{}, nil
|
||||
},
|
||||
},
|
||||
"webhooks": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(webhookType))),
|
||||
Description: "The list of webhooks for the pipeline.",
|
||||
@@ -728,6 +765,73 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pipeline, err := db.GetPipelineById(pipelineId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pipeline, nil
|
||||
},
|
||||
},
|
||||
"addCronToPipeline": &graphql.Field{
|
||||
Type: pipelineType,
|
||||
Description: "Add a cron string to trigger the pipeline",
|
||||
Args: graphql.FieldConfigArgument{
|
||||
"cron": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
"pipelineId": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
},
|
||||
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
|
||||
|
||||
cron := params.Args["cron"].(string)
|
||||
|
||||
pipelineId, err := uuid.Parse(params.Args["pipelineId"].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.AddCronForPipeline(pipelineId, cron)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pipeline, err := db.GetPipelineById(pipelineId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pipeline, nil
|
||||
},
|
||||
},
|
||||
"removeCronFromPipeline": &graphql.Field{
|
||||
Type: pipelineType,
|
||||
Description: "Remove a cron trigger from a pipeline.",
|
||||
Args: graphql.FieldConfigArgument{
|
||||
"cronId": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
"pipelineId": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
},
|
||||
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
|
||||
|
||||
cronId, err := uuid.Parse(params.Args["cronId"].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pipelineId, err := uuid.Parse(params.Args["pipelineId"].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.RemoveCronForPipeline(cronId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pipeline, err := db.GetPipelineById(pipelineId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user