diff --git a/pipelines.go b/pipelines.go index 3f2448447..33e97a2ea 100644 --- a/pipelines.go +++ b/pipelines.go @@ -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 +} diff --git a/pipelines_test.go b/pipelines_test.go index 870f2ea0c..88fb83117 100644 --- a/pipelines_test.go +++ b/pipelines_test.go @@ -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) + } +}