From e7bd3df0efbb1dd80cde6af53e2b6b8d0dfceee3 Mon Sep 17 00:00:00 2001 From: alexpts Date: Tue, 29 Oct 2024 21:04:55 +0300 Subject: [PATCH 1/2] issue-2026 implement pipeline update metadata --- pipelines.go | 32 ++++++++++++++++++++++++++++++++ pipelines_test.go | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/pipelines.go b/pipelines.go index 3f2448447..0dba7d21c 100644 --- a/pipelines.go +++ b/pipelines.go @@ -406,3 +406,35 @@ func (s *PipelinesService) DeletePipeline(pid interface{}, pipeline int, options return s.client.Do(req, nil) } + +// UpdateMetadataOptions represents the available UpdateMetadata() options. +// +// https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata +type UpdateMetadataOptions struct { + Name string `url:"ref" json:"name"` +} + +// UpdateMetadata 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) UpdateMetadata(pid interface{}, pipeline int, opt *UpdateMetadataOptions, 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..fd6a8e082 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 := &UpdateMetadataOptions{Name: "new pipeline title"} + pipeline, _, err := client.Pipelines.UpdateMetadata("1", 234, opt) + if err != nil { + t.Errorf("Pipelines.UpdateMetadata returned error: %v", err) + } + + want := &Pipeline{ID: 1, Status: "running"} + if !reflect.DeepEqual(want, pipeline) { + t.Errorf("Pipelines.UpdateMetadata returned %+v, want %+v", pipeline, want) + } +} From f0941641a41e20de52f465f1d256ea2ec1b005c2 Mon Sep 17 00:00:00 2001 From: alexpts Date: Wed, 30 Oct 2024 17:54:37 +0300 Subject: [PATCH 2/2] issue-2026 CR fix --- pipelines.go | 12 +++++++----- pipelines_test.go | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pipelines.go b/pipelines.go index 0dba7d21c..33e97a2ea 100644 --- a/pipelines.go +++ b/pipelines.go @@ -407,18 +407,20 @@ func (s *PipelinesService) DeletePipeline(pid interface{}, pipeline int, options return s.client.Do(req, nil) } -// UpdateMetadataOptions represents the available UpdateMetadata() options. +// UpdatePipelineMetadataOptions represents the available UpdatePipelineMetadata() options. // +// GitLab API docs: // https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata -type UpdateMetadataOptions struct { - Name string `url:"ref" json:"name"` +type UpdatePipelineMetadataOptions struct { + Name *string `url:"name,omitempty" json:"name,omitempty"` } -// UpdateMetadata You can update the metadata of a pipeline. The metadata contains the name of the pipeline. +// 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) UpdateMetadata(pid interface{}, pipeline int, opt *UpdateMetadataOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) { +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 diff --git a/pipelines_test.go b/pipelines_test.go index fd6a8e082..88fb83117 100644 --- a/pipelines_test.go +++ b/pipelines_test.go @@ -280,14 +280,14 @@ func TestUpdateMetadata(t *testing.T) { fmt.Fprint(w, `{"id":1, "status":"running"}`) }) - opt := &UpdateMetadataOptions{Name: "new pipeline title"} - pipeline, _, err := client.Pipelines.UpdateMetadata("1", 234, opt) + opt := &UpdatePipelineMetadataOptions{Name: Ptr("new pipeline title")} + pipeline, _, err := client.Pipelines.UpdatePipelineMetadata("1", 234, opt) if err != nil { - t.Errorf("Pipelines.UpdateMetadata returned error: %v", err) + t.Errorf("Pipelines.UpdatePipelineMetadata returned error: %v", err) } want := &Pipeline{ID: 1, Status: "running"} if !reflect.DeepEqual(want, pipeline) { - t.Errorf("Pipelines.UpdateMetadata returned %+v, want %+v", pipeline, want) + t.Errorf("Pipelines.UpdatePipelineMetadata returned %+v, want %+v", pipeline, want) } }