Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
08a95e8e
Unverified
Commit
08a95e8e
authored
Oct 10, 2017
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for running pipeline triggers
parent
3c8436f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
pipeline_triggers.go
pipeline_triggers.go
+35
-0
pipeline_triggers_test.go
pipeline_triggers_test.go
+30
-0
No files found.
pipeline_triggers.go
View file @
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
}
pipeline_triggers_test.go
0 → 100644
View file @
08a95e8e
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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment