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

API pipeline update metadata #2051

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
alexpts marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}