Commit b54e5b9d authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

Merge pull request #224 from nolith/run-pipeline

Add support for running pipeline triggers
parents b04a6b8e 08a95e8e
......@@ -197,3 +197,38 @@ func (s *PipelineTriggersService) DeletePipelineTrigger(pid interface{}, trigger
return s.client.Do(req, nil)
}
// RunPipelineTriggerOptions represents the available RunPipelineTrigger() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/ci/triggers/README.html#triggering-a-pipeline
type RunPipelineTriggerOptions struct {
Ref *string `url:"ref" json:"ref"`
Token *string `url:"token" json:"token"`
Variables map[string]string `url:"variables,omitempty" json:"variables,omitempty"`
}
// RunPipelineTrigger starts a trigger from a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/ci/triggers/README.html#triggering-a-pipeline
func (s *PipelineTriggersService) RunPipelineTrigger(pid interface{}, opt *RunPipelineTriggerOptions, options ...OptionFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/trigger/pipeline", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil {
return nil, nil, err
}
pt := new(Pipeline)
resp, err := s.client.Do(req, pt)
if err != nil {
return nil, resp, err
}
return pt, resp, err
}
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRunPipeline(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/trigger/pipeline", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":1, "status":"pending"}`)
})
opt := &RunPipelineTriggerOptions{Ref: String("master")}
pipeline, _, err := client.PipelineTriggers.RunPipelineTrigger(1, opt)
if err != nil {
t.Errorf("PipelineTriggers.RunPipelineTrigger returned error: %v", err)
}
want := &Pipeline{ID: 1, Status: "pending"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("PipelineTriggers.RunPipelineTrigger returned %+v, want %+v", pipeline, want)
}
}
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