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
96446cb1
Commit
96446cb1
authored
Apr 14, 2017
by
Ben Getsug
Committed by
Sander van Harmelen
Aug 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing builds service to jobs service (#166)
parent
f4f1b4fc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
83 deletions
+81
-83
gitlab.go
gitlab.go
+2
-2
jobs.go
jobs.go
+79
-81
No files found.
gitlab.go
View file @
96446cb1
...
...
@@ -169,11 +169,11 @@ type Client struct {
// Services used for talking to different parts of the GitLab API.
Branches
*
BranchesService
BuildVariables
*
BuildVariablesService
Builds
*
BuildsService
Commits
*
CommitsService
DeployKeys
*
DeployKeysService
Groups
*
GroupsService
Issues
*
IssuesService
Jobs
*
JobsService
Labels
*
LabelsService
MergeRequests
*
MergeRequestsService
Milestones
*
MilestonesService
...
...
@@ -234,11 +234,11 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
c
.
Branches
=
&
BranchesService
{
client
:
c
}
c
.
BuildVariables
=
&
BuildVariablesService
{
client
:
c
}
c
.
Builds
=
&
BuildsService
{
client
:
c
}
c
.
Commits
=
&
CommitsService
{
client
:
c
}
c
.
DeployKeys
=
&
DeployKeysService
{
client
:
c
}
c
.
Groups
=
&
GroupsService
{
client
:
c
}
c
.
Issues
=
&
IssuesService
{
client
:
c
}
c
.
Jobs
=
&
JobsService
{
client
:
c
}
c
.
Labels
=
&
LabelsService
{
client
:
c
}
c
.
MergeRequests
=
&
MergeRequestsService
{
client
:
c
}
c
.
Milestones
=
&
MilestonesService
{
client
:
c
}
...
...
build
s.go
→
job
s.go
View file @
96446cb1
...
...
@@ -24,26 +24,24 @@ import (
"time"
)
// List
Build
sOptions are options for two list apis
type
List
Build
sOptions
struct
{
// List
Job
sOptions are options for two list apis
type
List
Job
sOptions
struct
{
ListOptions
Scope
[]
BuildState
`url:"scope,omitempty" json:"scope,omitempty"`
}
//
Build
sService handles communication with the ci builds related methods
//
Job
sService handles communication with the ci builds related methods
// of the GitLab API.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md
type
BuildsService
struct
{
// GitLab API docs: https://docs.gitlab.com/ce/api/jobs.html
type
JobsService
struct
{
client
*
Client
}
//
Build
represents a ci build.
//
Job
represents a ci build.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md
type
Build
struct
{
// GitLab API docs: https://docs.gitlab.com/ce/api/jobs.html
type
Job
struct
{
Commit
*
Commit
`json:"commit"`
CreatedAt
*
time
.
Time
`json:"created_at"`
ArtifactsFile
struct
{
...
...
@@ -68,95 +66,95 @@ type Build struct {
User
*
User
`json:"user"`
}
// ListProject
Builds gets a list of build
s in a project.
// ListProject
Jobs gets a list of job
s in a project.
//
// The scope of
builds to show, one or array of:
pending, running,
// failed, success, canceled
; showing all builds if none provided.
// The scope of
jobs to show, one or array of: created,
pending, running,
// failed, success, canceled
, skipped; showing all jobs if none provided
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#list-project-build
s
func
(
s
*
BuildsService
)
ListProjectBuilds
(
pid
interface
{},
opts
*
ListBuildsOptions
,
options
...
OptionFunc
)
([]
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#list-project-job
s
func
(
s
*
JobsService
)
ListProjectJobs
(
pid
interface
{},
opts
*
ListJobsOptions
,
options
...
OptionFunc
)
([]
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
build
s"
,
url
.
QueryEscape
(
project
))
u
:=
fmt
.
Sprintf
(
"projects/%s/
job
s"
,
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opts
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
builds
[]
Build
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
build
s
)
var
jobs
[]
Job
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
job
s
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
s
,
resp
,
err
return
job
s
,
resp
,
err
}
// List
CommitBuilds gets a list of builds for specific commit
in a
// project. If the
commit SHA
is not found, it will respond with 404.
// List
PipelineJobs gets a list of jobs for specific pipeline
in a
// project. If the
pipeline ID
is not found, it will respond with 404.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#list-commit-build
s
func
(
s
*
BuildsService
)
ListCommitBuilds
(
pid
interface
{},
sha
string
,
opts
*
ListBuildsOptions
,
options
...
OptionFunc
)
([]
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#list-pipeline-job
s
func
(
s
*
JobsService
)
ListPipelineJobs
(
pid
interface
{},
pipelineID
int
,
opts
*
ListJobsOptions
,
options
...
OptionFunc
)
([]
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
repository/commits/%s/builds"
,
project
,
sha
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
pipeline/%d/jobs"
,
project
,
pipelineID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opts
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
builds
[]
Build
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
build
s
)
var
jobs
[]
Job
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
job
s
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
s
,
resp
,
err
return
job
s
,
resp
,
err
}
// Get
Build gets a single build
of a project.
// Get
Job gets a single job
of a project.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#get-a-single-build
func
(
s
*
BuildsService
)
GetBuild
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#get-a-single-job
func
(
s
*
JobsService
)
GetJob
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
// Get
BuildArtifacts get build
s artifacts of a project
// Get
JobArtifacts get job
s artifacts of a project
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#get-build
-artifacts
func
(
s
*
BuildsService
)
GetBuildArtifacts
(
pid
interface
{},
build
ID
int
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#get-job
-artifacts
func
(
s
*
JobsService
)
GetJobArtifacts
(
pid
interface
{},
job
ID
int
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/artifacts"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/artifacts"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
...
...
@@ -173,16 +171,16 @@ func (s *BuildsService) GetBuildArtifacts(pid interface{}, buildID int, options
}
// DownloadArtifactsFile download the artifacts file from the given
// reference name and job provided the
build
finished successfully.
// reference name and job provided the
job
finished successfully.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md
#download-the-artifacts-file
func
(
s
*
Build
sService
)
DownloadArtifactsFile
(
pid
interface
{},
refName
string
,
job
string
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html
#download-the-artifacts-file
func
(
s
*
Job
sService
)
DownloadArtifactsFile
(
pid
interface
{},
refName
string
,
job
string
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
build
s/artifacts/%s/download?job=%s"
,
project
,
refName
,
job
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
job
s/artifacts/%s/download?job=%s"
,
project
,
refName
,
job
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
...
...
@@ -198,16 +196,16 @@ func (s *BuildsService) DownloadArtifactsFile(pid interface{}, refName string, j
return
artifactsBuf
,
resp
,
err
}
// GetTraceFile gets a trace of a specific
build
of a project
// GetTraceFile gets a trace of a specific
job
of a project
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md
#get-a-trace-file
func
(
s
*
BuildsService
)
GetTraceFile
(
pid
interface
{},
build
ID
int
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html
#get-a-trace-file
func
(
s
*
JobsService
)
GetTraceFile
(
pid
interface
{},
job
ID
int
,
options
...
OptionFunc
)
(
io
.
Reader
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/trace"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/trace"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
...
...
@@ -223,129 +221,129 @@ func (s *BuildsService) GetTraceFile(pid interface{}, buildID int, options ...Op
return
traceBuf
,
resp
,
err
}
// Cancel
Build cancels a single build
of a project.
// Cancel
Job cancels a single job
of a project.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#cancel-a-build
func
(
s
*
BuildsService
)
CancelBuild
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#cancel-a-job
func
(
s
*
JobsService
)
CancelJob
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/cancel"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/cancel"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
// Retry
Build retries a single build
of a project
// Retry
Job retries a single job
of a project
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#retry-a-build
func
(
s
*
BuildsService
)
RetryBuild
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#retry-a-job
func
(
s
*
JobsService
)
RetryJob
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/retry"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/retry"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
// Erase
Build erases a single build of a project, removes a build
// artifacts and a
build
trace.
// Erase
Job erases a single job of a project, removes a job
// artifacts and a
job
trace.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#erase-a-build
func
(
s
*
BuildsService
)
EraseBuild
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#erase-a-job
func
(
s
*
JobsService
)
EraseJob
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/erase"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/erase"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
// KeepArtifacts prevents artifacts from being deleted when
// expiration is set.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md
#keep-artifacts
func
(
s
*
BuildsService
)
KeepArtifacts
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html
#keep-artifacts
func
(
s
*
JobsService
)
KeepArtifacts
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/artifacts/keep"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/artifacts/keep"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
// Play
Build triggers a nanual action to start a build
.
// Play
Job triggers a nanual action to start a job
.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/builds.md#play-a-build
func
(
s
*
BuildsService
)
PlayBuild
(
pid
interface
{},
buildID
int
,
options
...
OptionFunc
)
(
*
Build
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/jobs.html#play-a-job
func
(
s
*
JobsService
)
PlayJob
(
pid
interface
{},
jobID
int
,
options
...
OptionFunc
)
(
*
Job
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/
builds/%d/play"
,
project
,
build
ID
)
u
:=
fmt
.
Sprintf
(
"projects/%s/
jobs/%d/play"
,
project
,
job
ID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
build
:=
new
(
Build
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
build
)
job
:=
new
(
Job
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
job
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
build
,
resp
,
err
return
job
,
resp
,
err
}
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