Commit be9aa7f1 authored by Z.J. van de Weg's avatar Z.J. van de Weg

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
...@@ -9,6 +9,7 @@ v 8.11.0 (unreleased) ...@@ -9,6 +9,7 @@ v 8.11.0 (unreleased)
- Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable - Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable
- Optimize maximum user access level lookup in loading of notes - Optimize maximum user access level lookup in loading of notes
- Add "No one can push" as an option for protected branches. !5081 - 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 - Limit git rev-list output count to one in forced push check
- Clean up unused routes (Josef Strzibny) - Clean up unused routes (Josef Strzibny)
- Add green outline to New Branch button. !5447 (winniehell) - Add green outline to New Branch button. !5447 (winniehell)
......
...@@ -2,8 +2,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -2,8 +2,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
layout 'project' layout 'project'
before_action :authorize_read_environment! before_action :authorize_read_environment!
before_action :authorize_create_environment!, only: [:new, :create] before_action :authorize_create_environment!, only: [:new, :create]
before_action :authorize_update_environment!, only: [:destroy] before_action :authorize_update_environment!, only: [:edit, :destroy]
before_action :environment, only: [:show, :destroy] before_action :environment, only: [:show, :edit, :update, :destroy]
def index def index
@environments = project.environments @environments = project.environments
...@@ -17,13 +17,24 @@ def new ...@@ -17,13 +17,24 @@ def new
@environment = project.environments.new @environment = project.environments.new
end end
def edit
end
def create def create
@environment = project.environments.create(create_params) @environment = project.environments.create(environment_params)
if @environment.persisted? if @environment.persisted?
redirect_to namespace_project_environment_path(project.namespace, project, @environment) redirect_to namespace_project_environment_path(project.namespace, project, @environment)
else 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
end end
...@@ -39,8 +50,8 @@ def destroy ...@@ -39,8 +50,8 @@ def destroy
private private
def create_params def environment_params
params.require(:environment).permit(:name) params.require(:environment).permit(:name, :external_url)
end end
def environment def environment
......
...@@ -10,6 +10,10 @@ class Environment < ActiveRecord::Base ...@@ -10,6 +10,10 @@ class Environment < ActiveRecord::Base
format: { with: Gitlab::Regex.environment_name_regex, format: { with: Gitlab::Regex.environment_name_regex,
message: Gitlab::Regex.environment_name_regex_message } message: Gitlab::Regex.environment_name_regex_message }
validates :external_url,
uniqueness: { scope: :project_id },
length: { maximum: 255 }
def last_deployment def last_deployment
deployments.last deployments.last
end end
......
= form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { class: 'col-lg-9' } do |f| .row.prepend-top-default.append-bottom-default
= form_errors(@environment) .col-lg-3
.form-group %h4.prepend-top-0
= f.label :name, 'Name', class: 'label-light' Environments
= f.text_field :name, required: true, class: 'form-control' %p
= f.submit 'Create environment', class: 'btn btn-create' Environments allow you to track deployments of your application
= link_to 'Cancel', namespace_project_environments_path(@project.namespace, @project), class: 'btn btn-cancel' = 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'
- page_title "Edit", @environment.name, "Environments"
%h3.page-title
Edit environment
%hr
= render 'form'
- page_title 'New Environment' - page_title 'New Environment'
.row.prepend-top-default.append-bottom-default %h3.page-title
.col-lg-3 New environment
%h4.prepend-top-0 %hr
New Environment = render 'form'
%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'
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
.top-area .top-area
.col-md-9 .col-md-9
%h3.page-title= @environment.name.capitalize %h3.page-title= @environment.name.capitalize
.col-md-3 .col-md-3
.nav-controls .nav-controls
- if can?(current_user, :update_environment, @environment) - 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 = 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? - if @deployments.blank?
......
...@@ -741,7 +741,7 @@ ...@@ -741,7 +741,7 @@
end end
end end
resources :environments, only: [:index, :show, :new, :create, :destroy] resources :environments, constraints: { id: /\d+/ }
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do collection do
......
# 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
...@@ -427,9 +427,10 @@ ...@@ -427,9 +427,10 @@
create_table "environments", force: :cascade do |t| create_table "environments", force: :cascade do |t|
t.integer "project_id" t.integer "project_id"
t.string "name", null: false t.string "name", null: false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "external_url"
end end
add_index "environments", ["project_id", "name"], name: "index_environments_on_project_id_and_name", using: :btree add_index "environments", ["project_id", "name"], name: "index_environments_on_project_id_and_name", using: :btree
......
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
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
sequence(:name) { |n| "environment#{n}" } sequence(:name) { |n| "environment#{n}" }
project factory: :empty_project project factory: :empty_project
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
end end
end end
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
context 'for valid name' do context 'for valid name' do
before do before do
fill_in('Name', with: 'production') fill_in('Name', with: 'production')
click_on 'Create environment' click_on 'Save'
end end
scenario 'does create a new pipeline' do scenario 'does create a new pipeline' do
...@@ -151,7 +151,7 @@ ...@@ -151,7 +151,7 @@
context 'for invalid name' do context 'for invalid name' do
before do before do
fill_in('Name', with: 'name with spaces') fill_in('Name', with: 'name with spaces')
click_on 'Create environment' click_on 'Save'
end end
scenario 'does show errors' do scenario 'does show errors' do
......
...@@ -11,4 +11,14 @@ ...@@ -11,4 +11,14 @@
it { is_expected.to validate_presence_of(:name) } 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_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(: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 end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment