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
3a152ef5
Commit
3a152ef5
authored
Jun 22, 2019
by
Ilan Shamir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemneted get environment
parent
e4d31990
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
4 deletions
+50
-4
environments.go
environments.go
+30
-4
environments_test.go
environments_test.go
+20
-0
No files found.
environments.go
View file @
3a152ef5
...
...
@@ -32,10 +32,11 @@ type EnvironmentsService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/environments.html
type
Environment
struct
{
ID
int
`json:"id"`
Name
string
`json:"name"`
Slug
string
`json:"slug"`
ExternalURL
string
`json:"external_url"`
ID
int
`json:"id"`
Name
string
`json:"name"`
Slug
string
`json:"slug"`
ExternalURL
string
`json:"external_url"`
LastDeployment
Deployment
`json:"last_deployment,omitempty"`
}
func
(
env
Environment
)
String
()
string
{
...
...
@@ -74,6 +75,31 @@ func (s *EnvironmentsService) ListEnvironments(pid interface{}, opts *ListEnviro
return
envs
,
resp
,
err
}
// GetEnvironment gets a specific environment from a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#get-a-specific-environment
func
(
s
*
EnvironmentsService
)
GetEnvironment
(
pid
interface
{},
environment
int
,
options
...
OptionFunc
)
(
*
Environment
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/environments/%d"
,
pathEscape
(
project
),
environment
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
env
:=
new
(
Environment
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
env
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
env
,
resp
,
err
}
// CreateEnvironmentOptions represents the available CreateEnvironment() options.
//
// GitLab API docs:
...
...
environments_test.go
View file @
3a152ef5
...
...
@@ -29,6 +29,26 @@ func TestListEnvironments(t *testing.T) {
}
}
func
TestGetEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments/5949167"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id":1,"name":"test/test"}`
)
})
env
,
_
,
err
:=
client
.
Environments
.
GetEnvironment
(
1
,
5949167
)
if
err
!=
nil
{
t
.
Errorf
(
"Environemtns.GetEnvironment returned error: %v"
,
err
)
}
want
:=
&
Environment
{
ID
:
1
,
Name
:
"test/test"
}
if
!
reflect
.
DeepEqual
(
want
,
env
)
{
t
.
Errorf
(
"Environments.GetEnvironment returned %+v, want %+v"
,
env
,
want
)
}
}
func
TestCreateEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
...
...
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