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
be9aa7f1
Commit
be9aa7f1
authored
Jul 26, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an URL field to Environments
This MR adds a string (thus max 255 chars) field to the enviroments table to expose it later in other features.
parent
242f8377
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
133 additions
and
28 deletions
+133
-28
CHANGELOG
CHANGELOG
+1
-0
environments_controller.rb
app/controllers/projects/environments_controller.rb
+17
-6
environment.rb
app/models/environment.rb
+4
-0
_form.html.haml
app/views/projects/environments/_form.html.haml
+22
-7
edit.html.haml
app/views/projects/environments/edit.html.haml
+6
-0
new.html.haml
app/views/projects/environments/new.html.haml
+4
-10
show.html.haml
app/views/projects/environments/show.html.haml
+1
-1
routes.rb
config/routes.rb
+1
-1
20160725083350_add_external_url_to_enviroments.rb
db/migrate/20160725083350_add_external_url_to_enviroments.rb
+12
-0
schema.rb
db/schema.rb
+2
-1
environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+50
-0
environments.rb
spec/factories/environments.rb
+1
-0
environments_spec.rb
spec/features/environments_spec.rb
+2
-2
environment_spec.rb
spec/models/environment_spec.rb
+10
-0
No files found.
CHANGELOG
View file @
be9aa7f1
...
...
@@ -9,6 +9,7 @@ v 8.11.0 (unreleased)
- Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable
- Optimize maximum user access level lookup in loading of notes
- Add "No one can push" as an option for protected branches. !5081
- Environments have an url to link to
- Limit git rev-list output count to one in forced push check
- Clean up unused routes (Josef Strzibny)
- Add green outline to New Branch button. !5447 (winniehell)
...
...
app/controllers/projects/environments_controller.rb
View file @
be9aa7f1
...
...
@@ -2,8 +2,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
layout
'project'
before_action
:authorize_read_environment!
before_action
:authorize_create_environment!
,
only:
[
:new
,
:create
]
before_action
:authorize_update_environment!
,
only:
[
:destroy
]
before_action
:environment
,
only:
[
:show
,
:destroy
]
before_action
:authorize_update_environment!
,
only:
[
:
edit
,
:
destroy
]
before_action
:environment
,
only:
[
:show
,
:
edit
,
:update
,
:
destroy
]
def
index
@environments
=
project
.
environments
...
...
@@ -17,13 +17,24 @@ class Projects::EnvironmentsController < Projects::ApplicationController
@environment
=
project
.
environments
.
new
end
def
edit
end
def
create
@environment
=
project
.
environments
.
create
(
create
_params
)
@environment
=
project
.
environments
.
create
(
environment
_params
)
if
@environment
.
persisted?
redirect_to
namespace_project_environment_path
(
project
.
namespace
,
project
,
@environment
)
else
render
'new'
render
:new
end
end
def
update
if
@environment
.
update
(
environment_params
)
redirect_to
namespace_project_environment_path
(
project
.
namespace
,
project
,
@environment
)
else
render
:edit
end
end
...
...
@@ -39,8 +50,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
private
def
create
_params
params
.
require
(
:environment
).
permit
(
:name
)
def
environment
_params
params
.
require
(
:environment
).
permit
(
:name
,
:external_url
)
end
def
environment
...
...
app/models/environment.rb
View file @
be9aa7f1
...
...
@@ -10,6 +10,10 @@ class Environment < ActiveRecord::Base
format:
{
with:
Gitlab
::
Regex
.
environment_name_regex
,
message:
Gitlab
::
Regex
.
environment_name_regex_message
}
validates
:external_url
,
uniqueness:
{
scope: :project_id
},
length:
{
maximum:
255
}
def
last_deployment
deployments
.
last
end
...
...
app/views/projects/environments/_form.html.haml
View file @
be9aa7f1
=
form_for
@environment
,
url:
namespace_project_environments_path
(
@project
.
namespace
,
@project
),
html:
{
class:
'col-lg-9'
}
do
|
f
|
=
form_errors
(
@environment
)
.form-group
=
f
.
label
:name
,
'Name'
,
class:
'label-light'
=
f
.
text_field
:name
,
required:
true
,
class:
'form-control'
=
f
.
submit
'Create environment'
,
class:
'btn btn-create'
=
link_to
'Cancel'
,
namespace_project_environments_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-cancel'
.row.prepend-top-default.append-bottom-default
.col-lg-3
%h4
.prepend-top-0
Environments
%p
Environments allow you to track deployments of your application
=
succeed
"."
do
=
link_to
"Read more about environments"
,
help_page_path
(
"ci/environments"
)
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@environment
],
html:
{
class:
'col-lg-9'
}
do
|
f
|
=
form_errors
(
@environment
)
.form-group
=
f
.
label
:name
,
'Name'
,
class:
'label-light'
=
f
.
text_field
:name
,
required:
true
,
class:
'form-control'
.form-group
=
f
.
label
:external_url
,
'External URL'
,
class:
'label-light'
=
f
.
url_field
:external_url
,
class:
'form-control'
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save'
=
link_to
'Cancel'
,
namespace_project_environments_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-cancel'
app/views/projects/environments/edit.html.haml
0 → 100644
View file @
be9aa7f1
-
page_title
"Edit"
,
@environment
.
name
,
"Environments"
%h3
.page-title
Edit environment
%hr
=
render
'form'
app/views/projects/environments/new.html.haml
View file @
be9aa7f1
-
page_title
'New Environment'
.row.prepend-top-default.append-bottom-default
.col-lg-3
%h4
.prepend-top-0
New Environment
%p
Environments allow you to track deployments of your application
=
succeed
"."
do
=
link_to
"Read more about environments"
,
help_page_path
(
"ci/environments"
)
=
render
'form'
%h3
.page-title
New environment
%hr
=
render
'form'
app/views/projects/environments/show.html.haml
View file @
be9aa7f1
...
...
@@ -6,10 +6,10 @@
.top-area
.col-md-9
%h3
.page-title
=
@environment
.
name
.
capitalize
.col-md-3
.nav-controls
-
if
can?
(
current_user
,
:update_environment
,
@environment
)
=
link_to
'Edit'
,
edit_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
class:
'btn'
=
link_to
'Destroy'
,
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
data:
{
confirm:
'Are you sure you want to delete this environment?'
},
class:
'btn btn-danger'
,
method: :delete
-
if
@deployments
.
blank?
...
...
config/routes.rb
View file @
be9aa7f1
...
...
@@ -741,7 +741,7 @@ Rails.application.routes.draw do
end
end
resources
:environments
,
only:
[
:index
,
:show
,
:new
,
:create
,
:destroy
]
resources
:environments
,
constraints:
{
id:
/\d+/
}
resources
:builds
,
only:
[
:index
,
:show
],
constraints:
{
id:
/\d+/
}
do
collection
do
...
...
db/migrate/20160725083350_add_external_url_to_enviroments.rb
0 → 100644
View file @
be9aa7f1
# 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
DOWNTIME
=
false
def
change
add_column
(
:environments
,
:external_url
,
:string
)
end
end
db/schema.rb
View file @
be9aa7f1
...
...
@@ -427,9 +427,10 @@ ActiveRecord::Schema.define(version: 20160722221922) do
create_table
"environments"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
t
.
string
"name"
,
null:
false
t
.
string
"name"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"external_url"
end
add_index
"environments"
,
[
"project_id"
,
"name"
],
name:
"index_environments_on_project_id_and_name"
,
using: :btree
...
...
spec/controllers/projects/environments_controller_spec.rb
0 → 100644
View file @
be9aa7f1
require
'spec_helper'
describe
Projects
::
EnvironmentsController
do
let
(
:environment
)
{
create
(
:environment
)
}
let
(
:project
)
{
environment
.
project
}
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
user
,
:master
]
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
expect
(
response
).
to
be_ok
end
end
context
'with invalid id'
do
it
'responds with a status code 404'
do
get
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
12345
expect
(
response
).
to
be_not_found
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
expect
(
response
).
to
be_ok
end
end
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'
}
expect
(
response
).
to
have_http_status
(
302
)
end
end
end
spec/factories/environments.rb
View file @
be9aa7f1
...
...
@@ -3,5 +3,6 @@ FactoryGirl.define do
sequence
(
:name
)
{
|
n
|
"environment
#{
n
}
"
}
project
factory: :empty_project
sequence
(
:external_url
)
{
|
n
|
"https://env
#{
n
}
.example.gitlab.com"
}
end
end
spec/features/environments_spec.rb
View file @
be9aa7f1
...
...
@@ -140,7 +140,7 @@ feature 'Environments', feature: true do
context
'for valid name'
do
before
do
fill_in
(
'Name'
,
with:
'production'
)
click_on
'
Create environment
'
click_on
'
Save
'
end
scenario
'does create a new pipeline'
do
...
...
@@ -151,7 +151,7 @@ feature 'Environments', feature: true do
context
'for invalid name'
do
before
do
fill_in
(
'Name'
,
with:
'name with spaces'
)
click_on
'
Create environment
'
click_on
'
Save
'
end
scenario
'does show errors'
do
...
...
spec/models/environment_spec.rb
View file @
be9aa7f1
...
...
@@ -11,4 +11,14 @@ describe Environment, models: true do
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_within
(
0
..
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:external_url
).
is_within
(
0
..
255
)
}
# To circumvent a not null violation of the name column:
# https://github.com/thoughtbot/shoulda-matchers/issues/336
it
'validates uniqueness of :external_url'
do
create
(
:environment
)
is_expected
.
to
validate_uniqueness_of
(
:external_url
).
scoped_to
(
:project_id
)
end
end
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