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
bdd315a8
Commit
bdd315a8
authored
Jun 27, 2017
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #181
parent
a136d2e2
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
43 additions
and
122 deletions
+43
-122
build_variables.go
build_variables.go
+27
-6
build_variables_test.go
build_variables_test.go
+8
-14
commits.go
commits.go
+5
-5
commits_test.go
commits_test.go
+0
-14
gitlab_test.go
gitlab_test.go
+0
-38
pipelines_test.go
pipelines_test.go
+0
-1
projects_test.go
projects_test.go
+0
-36
services.go
services.go
+2
-2
services_test.go
services_test.go
+1
-6
No files found.
build_variables.go
View file @
bdd315a8
...
...
@@ -17,8 +17,9 @@ type BuildVariablesService struct {
//
// Gitlab API Docs : https://docs.gitlab.com/ce/api/build_variables.html
type
BuildVariable
struct
{
Key
string
`json:"key"`
Value
string
`json:"value"`
Key
string
`json:"key"`
Value
string
`json:"value"`
Protected
bool
`json:"protected"`
}
func
(
v
BuildVariable
)
String
()
string
{
...
...
@@ -83,18 +84,28 @@ func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string, op
return
v
,
resp
,
err
}
// CreateBuildVariableOptions are the parameters to CreateBuildVariable()
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#create-variable
type
CreateBuildVariableOptions
struct
{
Key
*
string
`url:"key" json:"key"`
Value
*
string
`url:"value" json:"value"`
Protected
*
bool
`url:"protected" json:"protected"`
}
// CreateBuildVariable creates a variable for a given project
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#create-variable
func
(
s
*
BuildVariablesService
)
CreateBuildVariable
(
pid
interface
{},
key
,
value
string
,
options
...
OptionFunc
)
(
*
BuildVariable
,
*
Response
,
error
)
{
func
(
s
*
BuildVariablesService
)
CreateBuildVariable
(
pid
interface
{},
opt
*
CreateBuildVariableOptions
,
options
...
OptionFunc
)
(
*
BuildVariable
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/variables"
,
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
BuildVariable
{
key
,
value
}
,
options
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
@@ -108,19 +119,29 @@ func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, key, value
return
v
,
resp
,
err
}
// UpdateBuildVariableOptions are the parameters to UpdateBuildVariable()
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#update-variable
type
UpdateBuildVariableOptions
struct
{
Key
*
string
`url:"key" json:"key"`
Value
*
string
`url:"value" json:"value"`
Protected
*
bool
`url:"protected" json:"protected"`
}
// UpdateBuildVariable updates an existing project variable
// The variable key must exist
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#update-variable
func
(
s
*
BuildVariablesService
)
UpdateBuildVariable
(
pid
interface
{},
key
,
value
string
,
options
...
OptionFunc
)
(
*
BuildVariable
,
*
Response
,
error
)
{
func
(
s
*
BuildVariablesService
)
UpdateBuildVariable
(
pid
interface
{},
key
string
,
opt
*
UpdateBuildVariableOptions
,
options
...
OptionFunc
)
(
*
BuildVariable
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/variables/%s"
,
url
.
QueryEscape
(
project
),
key
)
req
,
err
:=
s
.
client
.
NewRequest
(
"PUT"
,
u
,
BuildVariable
{
key
,
value
}
,
options
)
req
,
err
:=
s
.
client
.
NewRequest
(
"PUT"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
build_variables_test.go
View file @
bdd315a8
...
...
@@ -62,19 +62,16 @@ func TestCreateBuildVariable(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/variables"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testJSONBody
(
t
,
r
,
values
{
"key"
:
myKey
,
"value"
:
myValue
,
})
fmt
.
Fprintf
(
w
,
`{"key":"%s","value":"%s"}`
,
myKey
,
myValue
)
fmt
.
Fprintf
(
w
,
`{"key":"%s","value":"%s", "protected": false}`
,
myKey
,
myValue
)
})
variable
,
_
,
err
:=
client
.
BuildVariables
.
CreateBuildVariable
(
1
,
myKey
,
myValue
)
opt
:=
&
CreateBuildVariableOptions
{
String
(
myKey
),
String
(
myValue
),
Bool
(
false
)}
variable
,
_
,
err
:=
client
.
BuildVariables
.
CreateBuildVariable
(
1
,
opt
)
if
err
!=
nil
{
t
.
Errorf
(
"CreateBuildVariable returned error: %v"
,
err
)
}
want
:=
&
BuildVariable
{
Key
:
myKey
,
Value
:
myValue
}
want
:=
&
BuildVariable
{
Key
:
myKey
,
Value
:
myValue
,
Protected
:
false
}
if
!
reflect
.
DeepEqual
(
want
,
variable
)
{
t
.
Errorf
(
"CreateBuildVariable returned %+v, want %+v"
,
variable
,
want
)
}
...
...
@@ -86,19 +83,16 @@ func TestUpdateBuildVariable(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/variables/"
+
myKey
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"PUT"
)
testJSONBody
(
t
,
r
,
values
{
"key"
:
myKey
,
"value"
:
myNewValue
,
})
fmt
.
Fprintf
(
w
,
`{"key":"%s","value":"%s"}`
,
myKey
,
myNewValue
)
fmt
.
Fprintf
(
w
,
`{"key":"%s","value":"%s", "protected": false}`
,
myKey
,
myNewValue
)
})
variable
,
_
,
err
:=
client
.
BuildVariables
.
UpdateBuildVariable
(
1
,
myKey
,
myNewValue
)
opt
:=
&
UpdateBuildVariableOptions
{
String
(
myKey
),
String
(
myNewValue
),
Bool
(
false
)}
variable
,
_
,
err
:=
client
.
BuildVariables
.
UpdateBuildVariable
(
1
,
myKey
,
opt
)
if
err
!=
nil
{
t
.
Errorf
(
"UpdateBuildVariable returned error: %v"
,
err
)
}
want
:=
&
BuildVariable
{
Key
:
myKey
,
Value
:
myNewValue
}
want
:=
&
BuildVariable
{
Key
:
myKey
,
Value
:
myNewValue
,
Protected
:
false
}
if
!
reflect
.
DeepEqual
(
want
,
variable
)
{
t
.
Errorf
(
"UpdateBuildVariable returned %+v, want %+v"
,
variable
,
want
)
}
...
...
commits.go
View file @
bdd315a8
...
...
@@ -118,8 +118,8 @@ const (
// CommitAction represents a single file action within a commit.
type
CommitAction
struct
{
Action
FileAction
`url:"action" json:"action
,omitempty
"`
FilePath
string
`url:"file_path" json:"file_path
,omitempty
"`
Action
FileAction
`url:"action" json:"action"`
FilePath
string
`url:"file_path" json:"file_path"`
PreviousPath
string
`url:"previous_path,omitempty" json:"previous_path,omitempty"`
Content
string
`url:"content,omitempty" json:"content,omitempty"`
Encoding
string
`url:"encoding,omitempty" json:"encoding,omitempty"`
...
...
@@ -130,9 +130,9 @@ type CommitAction struct {
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/commits.md#create-a-commit-with-multiple-files-and-actions
type
CreateCommitOptions
struct
{
BranchName
*
string
`url:"branch_name" json:"branch_name
,omitempty
"`
CommitMessage
*
string
`url:"commit_message" json:"commit_message
,omitempty
"`
Actions
[]
*
CommitAction
`url:"actions" json:"actions
,omitempty
"`
BranchName
*
string
`url:"branch_name" json:"branch_name"`
CommitMessage
*
string
`url:"commit_message" json:"commit_message"`
Actions
[]
*
CommitAction
`url:"actions" json:"actions"`
AuthorEmail
*
string
`url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName
*
string
`url:"author_name,omitempty" json:"author_name,omitempty"`
}
...
...
commits_test.go
View file @
bdd315a8
...
...
@@ -13,12 +13,6 @@ func TestGetCommitStatuses(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/repository/commits/b0b3a907f41409829b307a28b82fdbd552ee5a27/statuses"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testFormValues
(
t
,
r
,
values
{
"ref"
:
"master"
,
"stage"
:
"test"
,
"name"
:
"ci/jenkins"
,
"all"
:
"true"
,
})
fmt
.
Fprint
(
w
,
`[{"id":1}]`
)
})
...
...
@@ -41,14 +35,6 @@ func TestSetCommitStatus(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/statuses/b0b3a907f41409829b307a28b82fdbd552ee5a27"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testJSONBody
(
t
,
r
,
values
{
"state"
:
"running"
,
"context"
:
""
,
"ref"
:
"master"
,
"name"
:
"ci/jenkins"
,
"target_url"
:
"http://abc"
,
"description"
:
"build"
,
})
fmt
.
Fprint
(
w
,
`{"id":1}`
)
})
...
...
gitlab_test.go
View file @
bdd315a8
...
...
@@ -2,12 +2,9 @@ package gitlab
import
(
"context"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
)
...
...
@@ -46,41 +43,6 @@ func testMethod(t *testing.T, r *http.Request, want string) {
}
}
type
values
map
[
string
]
string
func
testFormValues
(
t
*
testing
.
T
,
r
*
http
.
Request
,
values
values
)
{
want
:=
url
.
Values
{}
for
k
,
v
:=
range
values
{
want
.
Add
(
k
,
v
)
}
err
:=
r
.
ParseForm
()
if
err
!=
nil
{
t
.
Errorf
(
"Error parsing form: %v"
,
err
)
}
if
got
:=
r
.
Form
;
!
reflect
.
DeepEqual
(
got
,
want
)
{
t
.
Errorf
(
"Request parameters: %v, want %v"
,
got
,
want
)
}
}
func
testJSONBody
(
t
*
testing
.
T
,
r
*
http
.
Request
,
want
values
)
{
b
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
t
.
Errorf
(
"Error reading request body: %v"
,
err
)
}
var
got
values
err
=
json
.
Unmarshal
(
b
,
&
got
)
if
err
!=
nil
{
t
.
Errorf
(
"Error unmarshalling request body: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
got
,
want
)
{
t
.
Errorf
(
"Request parameters: %v, want %v"
,
got
,
want
)
}
}
func
TestNewClient
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
nil
,
""
)
...
...
pipelines_test.go
View file @
bdd315a8
...
...
@@ -53,7 +53,6 @@ func TestCreatePipeline(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/pipeline"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testJSONBody
(
t
,
r
,
values
{
"ref"
:
"master"
})
fmt
.
Fprint
(
w
,
`{"id":1, "status":"pending"}`
)
})
...
...
projects_test.go
View file @
bdd315a8
...
...
@@ -13,16 +13,6 @@ func TestListProjects(t *testing.T) {
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testFormValues
(
t
,
r
,
values
{
"page"
:
"2"
,
"per_page"
:
"3"
,
"archived"
:
"true"
,
"order_by"
:
"name"
,
"sort"
:
"asc"
,
"search"
:
"query"
,
"simple"
:
"true"
,
"visibility"
:
"public"
,
})
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
...
...
@@ -53,17 +43,6 @@ func TestListOwnedProjects(t *testing.T) {
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testFormValues
(
t
,
r
,
values
{
"page"
:
"2"
,
"per_page"
:
"3"
,
"archived"
:
"true"
,
"order_by"
:
"name"
,
"sort"
:
"asc"
,
"search"
:
"query"
,
"simple"
:
"true"
,
"owned"
:
"true"
,
"visibility"
:
"public"
,
})
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
...
...
@@ -95,17 +74,6 @@ func TestListStarredProjects(t *testing.T) {
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testFormValues
(
t
,
r
,
values
{
"page"
:
"2"
,
"per_page"
:
"3"
,
"archived"
:
"true"
,
"order_by"
:
"name"
,
"sort"
:
"asc"
,
"search"
:
"query"
,
"simple"
:
"true"
,
"starred"
:
"true"
,
"visibility"
:
"public"
,
})
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
...
...
@@ -178,10 +146,6 @@ func TestCreateProject(t *testing.T) {
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testJSONBody
(
t
,
r
,
values
{
"name"
:
"n"
,
})
fmt
.
Fprint
(
w
,
`{"id":1}`
)
})
...
...
services.go
View file @
bdd315a8
...
...
@@ -152,7 +152,7 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}, options ...Optio
type
SetDroneCIServiceOptions
struct
{
Token
*
string
`url:"token" json:"token" `
DroneURL
*
string
`url:"drone_url" json:"drone_url"`
EnableSSLVerification
*
string
`url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
EnableSSLVerification
*
bool
`url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
}
// SetDroneCIService sets Drone CI service for a project.
...
...
@@ -197,7 +197,7 @@ func (s *ServicesService) DeleteDroneCIService(pid interface{}, options ...Optio
type
DroneCIServiceProperties
struct
{
Token
*
string
`url:"token" json:"token"`
DroneURL
*
string
`url:"drone_url" json:"drone_url"`
EnableSSLVerification
*
string
`url:"enable_ssl_verification" json:"enable_ssl_verification"`
EnableSSLVerification
*
bool
`url:"enable_ssl_verification" json:"enable_ssl_verification"`
}
// DroneCIService represents Drone CI service settings.
...
...
services_test.go
View file @
bdd315a8
...
...
@@ -13,14 +13,9 @@ func TestSetDroneCIService(t *testing.T) {
mux
.
HandleFunc
(
"/projects/1/services/drone-ci"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"PUT"
)
testJSONBody
(
t
,
r
,
values
{
"token"
:
"t"
,
"drone_url"
:
"u"
,
"enable_ssl_verification"
:
"true"
,
})
})
opt
:=
&
SetDroneCIServiceOptions
{
String
(
"t"
),
String
(
"u"
),
String
(
"true"
)}
opt
:=
&
SetDroneCIServiceOptions
{
String
(
"t"
),
String
(
"u"
),
Bool
(
true
)}
_
,
err
:=
client
.
Services
.
SetDroneCIService
(
1
,
opt
)
if
err
!=
nil
{
...
...
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