Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2051 from alexpts/issue/2026/update-pipeline-meta…
Browse files Browse the repository at this point in the history
…data

API pipeline update metadata
  • Loading branch information
svanharmelen authored Oct 31, 2024
2 parents 0f91b06 + f094164 commit 435631c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,37 @@ func (s *PipelinesService) DeletePipeline(pid interface{}, pipeline int, options

return s.client.Do(req, nil)
}

// UpdatePipelineMetadataOptions represents the available UpdatePipelineMetadata() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata
type UpdatePipelineMetadataOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// UpdatePipelineMetadata You can update the metadata of a pipeline. The metadata
// contains the name of the pipeline.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata
func (s *PipelinesService) UpdatePipelineMetadata(pid interface{}, pipeline int, opt *UpdatePipelineMetadataOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d/metadata", PathEscape(project), pipeline)

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}

p := new(Pipeline)
resp, err := s.client.Do(req, p)
if err != nil {
return nil, resp, err
}

return p, resp, nil
}
20 changes: 20 additions & 0 deletions pipelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,23 @@ func TestDeletePipeline(t *testing.T) {
t.Errorf("Pipelines.DeletePipeline returned error: %v", err)
}
}

func TestUpdateMetadata(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/pipelines/234/metadata", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"id":1, "status":"running"}`)
})

opt := &UpdatePipelineMetadataOptions{Name: Ptr("new pipeline title")}
pipeline, _, err := client.Pipelines.UpdatePipelineMetadata("1", 234, opt)
if err != nil {
t.Errorf("Pipelines.UpdatePipelineMetadata returned error: %v", err)
}

want := &Pipeline{ID: 1, Status: "running"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("Pipelines.UpdatePipelineMetadata returned %+v, want %+v", pipeline, want)
}
}

0 comments on commit 435631c

Please sign in to comment.