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 1 commit
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
32 changes: 32 additions & 0 deletions pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
alexpts marked this conversation as resolved.
Show resolved Hide resolved
type UpdateMetadataOptions struct {
Name string `url:"ref" json:"name"`
alexpts marked this conversation as resolved.
Show resolved Hide resolved
}

// UpdateMetadata You can update the metadata of a pipeline. The metadata contains the name of the pipeline.
alexpts marked this conversation as resolved.
Show resolved Hide resolved
//
// 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) {
alexpts marked this conversation as resolved.
Show resolved Hide resolved
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 := &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)
}
}