Commit 0d37fe7f authored by Lorac's avatar Lorac Committed by Sander van Harmelen

Add ListProjectPipelinesOptions (#327)

parent b3ebd74a
......@@ -386,6 +386,7 @@ const (
Success BuildState = "success"
Failed BuildState = "failed"
Canceled BuildState = "canceled"
Skipped BuildState = "skipped"
)
// SetCommitStatus sets the status of a commit in a project.
......
......@@ -10,7 +10,18 @@ func pipelineExample() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
git.SetBaseURL("https://gitlab.com/api/v4")
pipelines, _, err := git.Pipelines.ListProjectPipelines(2743054)
opt := &gitlab.ListProjectPipelinesOptions{
Scope: gitlab.String("branches"),
Status: gitlab.Build(gitlab.Running),
Ref: gitlab.String("master"),
YamlErrors: gitlab.Bool(true),
Name: gitlab.String("name"),
Username: gitlab.String("username"),
OrderBy: gitlab.Order(gitlab.OrderByStatus),
Sort: gitlab.String("asc"),
}
pipelines, _, err := git.Pipelines.ListProjectPipelines(2743054, opt)
if err != nil {
log.Fatal(err)
}
......
......@@ -713,3 +713,19 @@ func Visibility(v VisibilityValue) *VisibilityValue {
*p = v
return p
}
// Order is a helper routine that allocates a new OrderBy
// to store v and returns a pointer to it.
func Order(v OrderBy) *OrderBy {
p := new(OrderBy)
*p = v
return p
}
// Build is a helper routine that allocates a new BuildState
// to store v and returns a pointer to it.
func Build(v BuildState) *BuildState {
p := new(BuildState)
*p = v
return p
}
......@@ -76,17 +76,43 @@ func (i PipelineList) String() string {
return Stringify(i)
}
// OrderBy represent in which order to sort the item
type OrderBy string
// These constants represent all valid order by values.
const (
OrderByID OrderBy = "id"
OrderByStatus OrderBy = "status"
OrderByRef OrderBy = "ref"
OrderByUserID OrderBy = "user_id"
)
// ListProjectPipelinesOptions represents the available ListProjectPipelines() options.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
type ListProjectPipelinesOptions struct {
ListOptions
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
Status *BuildState `url:"status,omitempty" json:"status,omitempty"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
YamlErrors *bool `url:"yaml_errors,omitempty" json:"yaml_errors,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
Username *string `url:"username,omitempty" json:"username,omitempty"`
OrderBy *OrderBy `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
}
// ListProjectPipelines gets a list of project piplines.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
func (s *PipelinesService) ListProjectPipelines(pid interface{}, options ...OptionFunc) (PipelineList, *Response, error) {
func (s *PipelinesService) ListProjectPipelines(pid interface{}, opt *ListProjectPipelinesOptions, options ...OptionFunc) (PipelineList, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil, options)
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}
......
......@@ -16,7 +16,8 @@ func TestListProjectPipelines(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
piplines, _, err := client.Pipelines.ListProjectPipelines(1)
opt := &ListProjectPipelinesOptions{Ref: String("master")}
piplines, _, err := client.Pipelines.ListProjectPipelines(1, opt)
if err != nil {
t.Errorf("Pipelines.ListProjectPipelines returned error: %v", err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment