Skip to content

Commit

Permalink
Merge pull request #165 from buildkite/SUP-1448-Pipeline-Templates
Browse files Browse the repository at this point in the history
SUP-1448: Pipeline Templates integration
  • Loading branch information
james2791 authored Nov 10, 2023
2 parents 77e050a + cb55987 commit ce5f39a
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
* SUP-1448: Pipeline Templates integration [#165](https://github.com/buildkite/go-buildkite/pull/165) ([james2791](https://github.com/james2791))

## [v3.8.0](https://github.com/buildkite/go-buildkite/compare/v3.7.0...v3.8.0) (2023-11-02)
* SUP-1537: Annotations create endpoint interaction [#163](https://github.com/buildkite/go-buildkite/pull/163) ([james2791](https://github.com/james2791))
Expand Down
36 changes: 19 additions & 17 deletions buildkite/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ type Client struct {
UserAgent string

// Services used for talking to different parts of the buildkite API.
AccessTokens *AccessTokensService
Agents *AgentsService
Annotations *AnnotationsService
Artifacts *ArtifactsService
Builds *BuildsService
Clusters *ClustersService
ClusterQueues *ClusterQueuesService
ClusterTokens *ClusterTokensService
FlakyTests *FlakyTestsService
Jobs *JobsService
Organizations *OrganizationsService
Pipelines *PipelinesService
User *UserService
Teams *TeamsService
Tests *TestsService
TestRuns *TestRunsService
TestSuites *TestSuitesService
AccessTokens *AccessTokensService
Agents *AgentsService
Annotations *AnnotationsService
Artifacts *ArtifactsService
Builds *BuildsService
Clusters *ClustersService
ClusterQueues *ClusterQueuesService
ClusterTokens *ClusterTokensService
FlakyTests *FlakyTestsService
Jobs *JobsService
Organizations *OrganizationsService
Pipelines *PipelinesService
PipelineTemplates *PipelineTemplatesService
User *UserService
Teams *TeamsService
Tests *TestsService
TestRuns *TestRunsService
TestSuites *TestSuitesService
}

// ListOptions specifies the optional parameters to various List methods that
Expand Down Expand Up @@ -92,6 +93,7 @@ func NewClient(httpClient *http.Client) *Client {
c.Jobs = &JobsService{c}
c.Organizations = &OrganizationsService{c}
c.Pipelines = &PipelinesService{c}
c.PipelineTemplates = &PipelineTemplatesService{c}
c.User = &UserService{c}
c.Teams = &TeamsService{c}
c.Tests = &TestsService{c}
Expand Down
158 changes: 158 additions & 0 deletions buildkite/pipeline_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package buildkite

import (
"errors"
"fmt"
)

// PipelineTemplatesService handles communication with pipeline template related
// methods of the Buildkite API.
//
// Buildkite API docs: <to-fill>
type PipelineTemplatesService struct {
client *Client
}

type PipelineTemplate struct {
UUID *string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
GraphQLID *string `json:"graphql_id,omitempty" yaml:"graphql_id,omitempty"`
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Configuration *string `json:"configuration,omitempty" yaml:"configuration,omitempty"`
Available *bool `json:"available,omitempty" yaml:"available,omitempty"`
URL *string `json:"url,omitempty" yaml:"url,omitempty"`
WebURL *string `json:"web_url,omitempty" yaml:"web_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty" yaml:"created_at,omitempty"`
CreatedBy *PipelineTemplateCreator `json:"created_by,omitempty" yaml:"created_by,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty" yaml:"updated_at,omitempty"`
UpdatedBy *PipelineTemplateCreator `json:"updated_by,omitempty" yaml:"updated_by,omitempty"`
}

type PipelineTemplateCreateUpdate struct {
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Configuration *string `json:"configuration,omitempty" yaml:"configuration,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Available *bool `json:"available,omitempty" yaml:"available,omitempty"`
}

type PipelineTemplateCreator struct {
ID *string `json:"id,omitempty" yaml:"id,omitempty"`
GraphQLID *string `json:"graphql_id,omitempty" yaml:"graphql_id,omitempty"`
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Email *string `json:"email,omitempty" yaml:"email,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty" yaml:"avatar_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty" yaml:"created_at,omitempty"`
}

type PipelineTemplateListOptions struct {
ListOptions
}

func (pts *PipelineTemplatesService) List(org string, opt *PipelineTemplateListOptions) ([]PipelineTemplate, *Response, error) {

u := fmt.Sprintf("v2/organizations/%s/pipeline-templates", org)

u, err := addOptions(u, opt)

if err != nil {
return nil, nil, err
}

req, err := pts.client.NewRequest("GET", u, nil)

if err != nil {
return nil, nil, err
}

templates := new([]PipelineTemplate)

resp, err := pts.client.Do(req, templates)

if err != nil {
return nil, resp, err
}

return *templates, resp, err
}

func (pts *PipelineTemplatesService) Get(org, templateUUID string) (*PipelineTemplate, *Response, error) {

u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)

req, err := pts.client.NewRequest("GET", u, nil)

if err != nil {
return nil, nil, err
}

template := new(PipelineTemplate)

resp, err := pts.client.Do(req, template)

if err != nil {
return nil, resp, err
}

return template, resp, err
}

func (pts *PipelineTemplatesService) Create(org string, ptc *PipelineTemplateCreateUpdate) (*PipelineTemplate, *Response, error) {

if ptc == nil {
return nil, nil, errors.New("PipelineTemplateCreateUpdate struct instance must not be nil")
}

u := fmt.Sprintf("v2/organizations/%s/pipeline-templates", org)

req, err := pts.client.NewRequest("POST", u, ptc)

if err != nil {
return nil, nil, err
}

template := new(PipelineTemplate)

resp, err := pts.client.Do(req, template)

if err != nil {
return nil, resp, err
}

return template, resp, err
}

func (pts *PipelineTemplatesService) Update(org, templateUUID string, ptu *PipelineTemplateCreateUpdate) (*Response, error) {

if ptu == nil {
return nil, errors.New("PipelineTemplateCreateUpdate struct instance must not be nil")
}

u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)

req, err := pts.client.NewRequest("PATCH", u, ptu)

if err != nil {
return nil, nil
}

resp, err := pts.client.Do(req, ptu)

if err != nil {
return resp, err
}

return resp, err
}

func (pts *PipelineTemplatesService) Delete(org, templateUUID string) (*Response, error) {

u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)

req, err := pts.client.NewRequest("DELETE", u, nil)

if err != nil {
return nil, err
}

return pts.client.Do(req, nil)
}
Loading

0 comments on commit ce5f39a

Please sign in to comment.