BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
76e9b684
Commit
76e9b684
authored
Jul 26, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate feedback
parent
84cd2120
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
29 deletions
+45
-29
environment.rb
app/models/environment.rb
+9
-1
20160725083350_add_external_url_to_enviroments.rb
db/migrate/20160725083350_add_external_url_to_enviroments.rb
+0
-3
schema.rb
db/schema.rb
+1
-1
enviroments.md
doc/api/enviroments.md
+3
-4
environments.rb
lib/api/environments.rb
+1
-4
environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+16
-8
environment_spec.rb
spec/models/environment_spec.rb
+8
-0
environments_spec.rb
spec/requests/api/environments_spec.rb
+7
-8
No files found.
app/models/environment.rb
View file @
76e9b684
...
...
@@ -3,6 +3,8 @@ class Environment < ActiveRecord::Base
has_many
:deployments
before_validation
:nullify_external_url
validates
:name
,
presence:
true
,
uniqueness:
{
scope: :project_id
},
...
...
@@ -12,9 +14,15 @@ class Environment < ActiveRecord::Base
validates
:external_url
,
uniqueness:
{
scope: :project_id
},
length:
{
maximum:
255
}
length:
{
maximum:
255
},
allow_nil:
true
,
addressable_url:
true
def
last_deployment
deployments
.
last
end
def
nullify_external_url
self
.
external_url
=
nil
if
self
.
external_url
.
blank?
end
end
db/migrate/20160725083350_add_external_url_to_enviroments.rb
View file @
76e9b684
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddExternalUrlToEnviroments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/schema.rb
View file @
76e9b684
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2016072
2221922
)
do
ActiveRecord
::
Schema
.
define
(
version:
2016072
6093600
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
doc/api/enviroments.md
View file @
76e9b684
...
...
@@ -32,8 +32,7 @@ Example response:
Creates a new environment with the given name and external_url.
It returns 200 if the environment was successfully created, 400 for wrong parameters
and 409 if the environment already exists.
It returns 200 if the environment was successfully created, 400 for wrong parameters.
```
POST /projects/:id/environment
...
...
@@ -43,7 +42,7 @@ POST /projects/:id/environment
| ------------- | ------- | -------- | ---------------------------- |
|
`id`
| integer | yes | The ID of the project |
|
`name`
| string | yes | The name of the environment |
|
`external_url`
| string |
yes
| Place to link to for this environment |
|
`external_url`
| string |
no
| Place to link to for this environment |
```
bash
curl
--data
"name=deploy&external_url=https://deploy.example.gitlab.com"
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v3/projects/1/environments"
...
...
@@ -88,7 +87,7 @@ Example response:
## Edit an existing environment
Updates an existing environments name and/or external_url.
Updates an existing environment
'
s name and/or external_url.
It returns 200 if the label was successfully updated, In case of an error, an additional error message is returned.
...
...
lib/api/environments.rb
View file @
76e9b684
...
...
@@ -30,9 +30,6 @@ module API
required_attributes!
[
:name
]
attrs
=
attributes_for_keys
[
:name
,
:external_url
]
environment
=
user_project
.
environments
.
find_by
(
name:
attrs
[
:name
])
conflict!
(
'Environment already exists'
)
if
environment
environment
=
user_project
.
environments
.
create
(
attrs
)
...
...
@@ -52,7 +49,7 @@ module API
# Example Request:
# DELETE /projects/:id/environments/:environment_id
delete
':id/environments/:environment_id'
do
authorize!
:
admin
_environment
,
user_project
authorize!
:
update
_environment
,
user_project
environment
=
user_project
.
environments
.
find
(
params
[
:environment_id
])
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
76e9b684
...
...
@@ -11,12 +11,10 @@ describe Projects::EnvironmentsController do
sign_in
(
user
)
end
render_views
describe
'GET show'
do
context
'with valid id'
do
it
'responds with a status code 200'
do
get
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
environment
.
id
get
:show
,
environment_params
expect
(
response
).
to
be_ok
end
...
...
@@ -24,16 +22,18 @@ describe Projects::EnvironmentsController do
context
'with invalid id'
do
it
'responds with a status code 404'
do
get
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
12345
params
=
environment_params
params
[
:id
]
=
12345
get
:show
,
params
expect
(
response
).
to
be_not_found
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'GET edit'
do
it
'responds with a status code 200'
do
get
:edit
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
environment
.
id
get
:edit
,
environment_params
expect
(
response
).
to
be_ok
end
...
...
@@ -41,10 +41,18 @@ describe Projects::EnvironmentsController do
describe
'PATCH #update'
do
it
'responds with a 302'
do
patch
:update
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
environment
.
id
,
environment:
{
external_url:
'https://git.gitlab.com'
}
patch
_params
=
environment_params
.
merge
(
environment:
{
external_url:
'https://git.gitlab.com'
})
patch
:update
,
patch_params
expect
(
response
).
to
have_http_status
(
302
)
end
end
def
environment_params
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
environment
.
id
}
end
end
spec/models/environment_spec.rb
View file @
76e9b684
...
...
@@ -21,4 +21,12 @@ describe Environment, models: true do
is_expected
.
to
validate_uniqueness_of
(
:external_url
).
scoped_to
(
:project_id
)
end
describe
'#nullify_external_url'
do
it
'replaces a blank url with nil'
do
env
=
build
(
:environment
,
external_url:
""
)
expect
(
env
.
save
).
to
be
true
end
end
end
spec/requests/api/environments_spec.rb
View file @
76e9b684
...
...
@@ -5,7 +5,7 @@ describe API::API, api: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:non_member
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:private
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:project
)
{
create
(
:project
,
:private
,
namespace:
user
.
namespace
)
}
let!
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
before
do
...
...
@@ -14,7 +14,7 @@ describe API::API, api: true do
describe
'GET /projects/:id/environments'
do
context
'as member of the project'
do
it
'should return project
label
s'
do
it
'should return project
environment
s'
do
get
api
(
"/projects/
#{
project
.
id
}
/environments"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
...
...
@@ -34,7 +34,7 @@ describe API::API, api: true do
end
end
describe
'POST /projects/:id/
label
s'
do
describe
'POST /projects/:id/
environment
s'
do
context
'as a member'
do
it
'creates a environment with valid params'
do
post
api
(
"/projects/
#{
project
.
id
}
/environments"
,
user
),
name:
"mepmep"
...
...
@@ -50,11 +50,10 @@ describe API::API, api: true do
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 40
9
if environment already exists'
do
it
'should return 40
0
if environment already exists'
do
post
api
(
"/projects/
#{
project
.
id
}
/environments"
,
user
),
name:
environment
.
name
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Environment already exists'
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -87,11 +86,11 @@ describe API::API, api: true do
describe
'PUT /projects/:id/environments/:environment_id'
do
it
'should return 200 if name and external_url are changed'
do
put
api
(
"/projects/
#{
project
.
id
}
/environments/
#{
environment
.
id
}
"
,
user
),
name:
'Mepmep'
,
external_url:
'mepmep.whatever.ninja'
name:
'Mepmep'
,
external_url:
'
https://
mepmep.whatever.ninja'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'Mepmep'
)
expect
(
json_response
[
'external_url'
]).
to
eq
(
'mepmep.whatever.ninja'
)
expect
(
json_response
[
'external_url'
]).
to
eq
(
'
https://
mepmep.whatever.ninja'
)
end
it
'should return 404 if the environment does not exist'
do
...
...
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