Merge branch 'builds_feature' into 'master'
Expose builds feature Expose builds feature in project settings (as feature). Enable it by default for a new projects. I deliberately named it builds instead of CI, because we actualy allow to run tests using infrastructure built-in GitLab. I'm free to change it. ![Screen_Shot_2015-11-09_at_16.42.21](/uploads/a8af0a56fc0498688c0428ff22252d9c/Screen_Shot_2015-11-09_at_16.42.21.png) If we are ok, I'll add feature tests for it. /cc @sytses @dzaporozhets See merge request !1767
This commit is contained in:
commit
eaf27c6295
27 changed files with 144 additions and 149 deletions
|
@ -29,7 +29,7 @@ class Projects::ApplicationController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def ci_enabled
|
def ci_enabled
|
||||||
return render_404 unless @project.gitlab_ci?
|
return render_404 unless @project.builds_enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
def ci_project
|
def ci_project
|
||||||
|
|
|
@ -213,7 +213,8 @@ class ProjectsController < ApplicationController
|
||||||
params.require(:project).permit(
|
params.require(:project).permit(
|
||||||
:name, :path, :description, :issues_tracker, :tag_list,
|
:name, :path, :description, :issues_tracker, :tag_list,
|
||||||
:issues_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :default_branch,
|
:issues_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :default_branch,
|
||||||
:wiki_enabled, :visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar
|
:wiki_enabled, :visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar,
|
||||||
|
:builds_enabled
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ module ProjectsHelper
|
||||||
nav_tabs << :merge_requests
|
nav_tabs << :merge_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
if project.gitlab_ci? && can?(current_user, :read_build, project)
|
if project.builds_enabled? && can?(current_user, :read_build, project)
|
||||||
nav_tabs << :builds
|
nav_tabs << :builds
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,30 +66,6 @@ module Ci
|
||||||
class << self
|
class << self
|
||||||
include Ci::CurrentSettings
|
include Ci::CurrentSettings
|
||||||
|
|
||||||
def base_build_script
|
|
||||||
<<-eos
|
|
||||||
git submodule update --init
|
|
||||||
ls -la
|
|
||||||
eos
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse(project)
|
|
||||||
params = {
|
|
||||||
gitlab_id: project.id,
|
|
||||||
default_ref: project.default_branch || 'master',
|
|
||||||
email_add_pusher: current_application_settings.add_pusher,
|
|
||||||
email_only_broken_builds: current_application_settings.all_broken_builds,
|
|
||||||
}
|
|
||||||
|
|
||||||
project = Ci::Project.new(params)
|
|
||||||
project.build_missing_services
|
|
||||||
project
|
|
||||||
end
|
|
||||||
|
|
||||||
def already_added?(project)
|
|
||||||
where(gitlab_id: project.id).any?
|
|
||||||
end
|
|
||||||
|
|
||||||
def unassigned(runner)
|
def unassigned(runner)
|
||||||
joins("LEFT JOIN #{Ci::RunnerProject.table_name} ON #{Ci::RunnerProject.table_name}.project_id = #{Ci::Project.table_name}.id " \
|
joins("LEFT JOIN #{Ci::RunnerProject.table_name} ON #{Ci::RunnerProject.table_name}.project_id = #{Ci::Project.table_name}.id " \
|
||||||
"AND #{Ci::RunnerProject.table_name}.runner_id = #{runner.id}").
|
"AND #{Ci::RunnerProject.table_name}.runner_id = #{runner.id}").
|
||||||
|
|
|
@ -52,6 +52,7 @@ class Project < ActiveRecord::Base
|
||||||
default_value_for :visibility_level, gitlab_config_features.visibility_level
|
default_value_for :visibility_level, gitlab_config_features.visibility_level
|
||||||
default_value_for :issues_enabled, gitlab_config_features.issues
|
default_value_for :issues_enabled, gitlab_config_features.issues
|
||||||
default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests
|
default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests
|
||||||
|
default_value_for :builds_enabled, gitlab_config_features.builds
|
||||||
default_value_for :wiki_enabled, gitlab_config_features.wiki
|
default_value_for :wiki_enabled, gitlab_config_features.wiki
|
||||||
default_value_for :wall_enabled, false
|
default_value_for :wall_enabled, false
|
||||||
default_value_for :snippets_enabled, gitlab_config_features.snippets
|
default_value_for :snippets_enabled, gitlab_config_features.snippets
|
||||||
|
@ -457,10 +458,6 @@ class Project < ActiveRecord::Base
|
||||||
list.find { |service| service.to_param == name }
|
list.find { |service| service.to_param == name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitlab_ci?
|
|
||||||
gitlab_ci_service && gitlab_ci_service.active && gitlab_ci_project.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def ci_services
|
def ci_services
|
||||||
services.select { |service| service.category == :ci }
|
services.select { |service| service.category == :ci }
|
||||||
end
|
end
|
||||||
|
@ -782,9 +779,23 @@ class Project < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_ci
|
# TODO: this should be migrated to Project table,
|
||||||
|
# the same as issues_enabled
|
||||||
|
def builds_enabled
|
||||||
|
gitlab_ci_service && gitlab_ci_service.active
|
||||||
|
end
|
||||||
|
|
||||||
|
def builds_enabled?
|
||||||
|
builds_enabled
|
||||||
|
end
|
||||||
|
|
||||||
|
def builds_enabled=(value)
|
||||||
service = gitlab_ci_service || create_gitlab_ci_service
|
service = gitlab_ci_service || create_gitlab_ci_service
|
||||||
service.active = true
|
service.active = value
|
||||||
service.save
|
service.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable_ci
|
||||||
|
self.builds_enabled = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,7 @@ class GitPushService
|
||||||
|
|
||||||
# If CI was disabled but .gitlab-ci.yml file was pushed
|
# If CI was disabled but .gitlab-ci.yml file was pushed
|
||||||
# we enable CI automatically
|
# we enable CI automatically
|
||||||
if !project.gitlab_ci? && gitlab_ci_yaml?(newrev)
|
if !project.builds_enabled? && gitlab_ci_yaml?(newrev)
|
||||||
project.enable_ci
|
project.enable_ci
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Projects
|
||||||
new_project = CreateService.new(current_user, new_params).execute
|
new_project = CreateService.new(current_user, new_params).execute
|
||||||
|
|
||||||
if new_project.persisted?
|
if new_project.persisted?
|
||||||
if @project.gitlab_ci?
|
if @project.builds_enabled?
|
||||||
new_project.enable_ci
|
new_project.enable_ci
|
||||||
|
|
||||||
settings = @project.gitlab_ci_project.attributes.select do |attr_name, value|
|
settings = @project.gitlab_ci_project.attributes.select do |attr_name, value|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
%span
|
%span
|
||||||
Protected Branches
|
Protected Branches
|
||||||
|
|
||||||
- if @project.gitlab_ci?
|
- if @project.builds_enabled?
|
||||||
= nav_link(controller: :runners) do
|
= nav_link(controller: :runners) do
|
||||||
= link_to namespace_project_runners_path(@project.namespace, @project), title: 'Runners', data: {placement: 'right'} do
|
= link_to namespace_project_runners_path(@project.namespace, @project), title: 'Runners', data: {placement: 'right'} do
|
||||||
= icon('cog fw')
|
= icon('cog fw')
|
||||||
|
|
|
@ -57,7 +57,16 @@
|
||||||
= f.check_box :merge_requests_enabled
|
= f.check_box :merge_requests_enabled
|
||||||
%strong Merge Requests
|
%strong Merge Requests
|
||||||
%br
|
%br
|
||||||
%span.descr Submit changes to be merged upstream.
|
%span.descr Submit changes to be merged upstream
|
||||||
|
|
||||||
|
.form-group
|
||||||
|
.col-sm-offset-2.col-sm-10
|
||||||
|
.checkbox
|
||||||
|
= f.label :builds_enabled do
|
||||||
|
= f.check_box :builds_enabled
|
||||||
|
%strong Builds
|
||||||
|
%br
|
||||||
|
%span.descr Test and deploy your changes before merge
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-sm-offset-2.col-sm-10
|
.col-sm-offset-2.col-sm-10
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= link_to 'Contributors', namespace_project_graph_path
|
= link_to 'Contributors', namespace_project_graph_path
|
||||||
= nav_link(action: :commits) do
|
= nav_link(action: :commits) do
|
||||||
= link_to 'Commits', commits_namespace_project_graph_path
|
= link_to 'Commits', commits_namespace_project_graph_path
|
||||||
- if @project.gitlab_ci?
|
- if @project.builds_enabled?
|
||||||
= nav_link(action: :ci) do
|
= nav_link(action: :ci) do
|
||||||
= link_to ci_namespace_project_graph_path do
|
= link_to ci_namespace_project_graph_path do
|
||||||
Continuous Integration
|
Continuous Integration
|
||||||
|
|
|
@ -84,6 +84,7 @@ production: &base
|
||||||
merge_requests: true
|
merge_requests: true
|
||||||
wiki: true
|
wiki: true
|
||||||
snippets: false
|
snippets: false
|
||||||
|
builds: true
|
||||||
|
|
||||||
## Webhook settings
|
## Webhook settings
|
||||||
# Number of seconds to wait for HTTP response after sending webhook HTTP POST request (default: 10)
|
# Number of seconds to wait for HTTP response after sending webhook HTTP POST request (default: 10)
|
||||||
|
|
|
@ -171,6 +171,7 @@ Settings.gitlab.default_projects_features['issues'] = true if Settings.g
|
||||||
Settings.gitlab.default_projects_features['merge_requests'] = true if Settings.gitlab.default_projects_features['merge_requests'].nil?
|
Settings.gitlab.default_projects_features['merge_requests'] = true if Settings.gitlab.default_projects_features['merge_requests'].nil?
|
||||||
Settings.gitlab.default_projects_features['wiki'] = true if Settings.gitlab.default_projects_features['wiki'].nil?
|
Settings.gitlab.default_projects_features['wiki'] = true if Settings.gitlab.default_projects_features['wiki'].nil?
|
||||||
Settings.gitlab.default_projects_features['snippets'] = false if Settings.gitlab.default_projects_features['snippets'].nil?
|
Settings.gitlab.default_projects_features['snippets'] = false if Settings.gitlab.default_projects_features['snippets'].nil?
|
||||||
|
Settings.gitlab.default_projects_features['builds'] = true if Settings.gitlab.default_projects_features['builds'].nil?
|
||||||
Settings.gitlab.default_projects_features['visibility_level'] = Settings.send(:verify_constant, Gitlab::VisibilityLevel, Settings.gitlab.default_projects_features['visibility_level'], Gitlab::VisibilityLevel::PRIVATE)
|
Settings.gitlab.default_projects_features['visibility_level'] = Settings.send(:verify_constant, Gitlab::VisibilityLevel, Settings.gitlab.default_projects_features['visibility_level'], Gitlab::VisibilityLevel::PRIVATE)
|
||||||
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive') if Settings.gitlab['repository_downloads_path'].nil?
|
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive') if Settings.gitlab['repository_downloads_path'].nil?
|
||||||
Settings.gitlab['restricted_signup_domains'] ||= []
|
Settings.gitlab['restricted_signup_domains'] ||= []
|
||||||
|
|
|
@ -60,6 +60,7 @@ Parameters:
|
||||||
"path_with_namespace": "diaspora/diaspora-client",
|
"path_with_namespace": "diaspora/diaspora-client",
|
||||||
"issues_enabled": true,
|
"issues_enabled": true,
|
||||||
"merge_requests_enabled": true,
|
"merge_requests_enabled": true,
|
||||||
|
"builds_enabled": true,
|
||||||
"wiki_enabled": true,
|
"wiki_enabled": true,
|
||||||
"snippets_enabled": false,
|
"snippets_enabled": false,
|
||||||
"created_at": "2013-09-30T13: 46: 02Z",
|
"created_at": "2013-09-30T13: 46: 02Z",
|
||||||
|
@ -101,6 +102,7 @@ Parameters:
|
||||||
"path_with_namespace": "brightbox/puppet",
|
"path_with_namespace": "brightbox/puppet",
|
||||||
"issues_enabled": true,
|
"issues_enabled": true,
|
||||||
"merge_requests_enabled": true,
|
"merge_requests_enabled": true,
|
||||||
|
"builds_enabled": true,
|
||||||
"wiki_enabled": true,
|
"wiki_enabled": true,
|
||||||
"snippets_enabled": false,
|
"snippets_enabled": false,
|
||||||
"created_at": "2013-09-30T13:46:02Z",
|
"created_at": "2013-09-30T13:46:02Z",
|
||||||
|
@ -191,6 +193,7 @@ Parameters:
|
||||||
"path_with_namespace": "diaspora/diaspora-project-site",
|
"path_with_namespace": "diaspora/diaspora-project-site",
|
||||||
"issues_enabled": true,
|
"issues_enabled": true,
|
||||||
"merge_requests_enabled": true,
|
"merge_requests_enabled": true,
|
||||||
|
"builds_enabled": true,
|
||||||
"wiki_enabled": true,
|
"wiki_enabled": true,
|
||||||
"snippets_enabled": false,
|
"snippets_enabled": false,
|
||||||
"created_at": "2013-09-30T13: 46: 02Z",
|
"created_at": "2013-09-30T13: 46: 02Z",
|
||||||
|
@ -312,6 +315,7 @@ Parameters:
|
||||||
- `description` (optional) - short project description
|
- `description` (optional) - short project description
|
||||||
- `issues_enabled` (optional)
|
- `issues_enabled` (optional)
|
||||||
- `merge_requests_enabled` (optional)
|
- `merge_requests_enabled` (optional)
|
||||||
|
- `builds_enabled` (optional)
|
||||||
- `wiki_enabled` (optional)
|
- `wiki_enabled` (optional)
|
||||||
- `snippets_enabled` (optional)
|
- `snippets_enabled` (optional)
|
||||||
- `public` (optional) - if `true` same as setting visibility_level = 20
|
- `public` (optional) - if `true` same as setting visibility_level = 20
|
||||||
|
@ -334,6 +338,7 @@ Parameters:
|
||||||
- `default_branch` (optional) - 'master' by default
|
- `default_branch` (optional) - 'master' by default
|
||||||
- `issues_enabled` (optional)
|
- `issues_enabled` (optional)
|
||||||
- `merge_requests_enabled` (optional)
|
- `merge_requests_enabled` (optional)
|
||||||
|
- `builds_enabled` (optional)
|
||||||
- `wiki_enabled` (optional)
|
- `wiki_enabled` (optional)
|
||||||
- `snippets_enabled` (optional)
|
- `snippets_enabled` (optional)
|
||||||
- `public` (optional) - if `true` same as setting visibility_level = 20
|
- `public` (optional) - if `true` same as setting visibility_level = 20
|
||||||
|
@ -357,6 +362,7 @@ Parameters:
|
||||||
- `default_branch` (optional)
|
- `default_branch` (optional)
|
||||||
- `issues_enabled` (optional)
|
- `issues_enabled` (optional)
|
||||||
- `merge_requests_enabled` (optional)
|
- `merge_requests_enabled` (optional)
|
||||||
|
- `builds_enabled` (optional)
|
||||||
- `wiki_enabled` (optional)
|
- `wiki_enabled` (optional)
|
||||||
- `snippets_enabled` (optional)
|
- `snippets_enabled` (optional)
|
||||||
- `public` (optional) - if `true` same as setting visibility_level = 20
|
- `public` (optional) - if `true` same as setting visibility_level = 20
|
||||||
|
|
|
@ -62,7 +62,7 @@ module API
|
||||||
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
||||||
expose :name, :name_with_namespace
|
expose :name, :name_with_namespace
|
||||||
expose :path, :path_with_namespace
|
expose :path, :path_with_namespace
|
||||||
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
|
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled, :snippets_enabled, :created_at, :last_activity_at
|
||||||
expose :creator_id
|
expose :creator_id
|
||||||
expose :namespace
|
expose :namespace
|
||||||
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
|
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
|
||||||
|
|
|
@ -75,6 +75,7 @@ module API
|
||||||
# description (optional) - short project description
|
# description (optional) - short project description
|
||||||
# issues_enabled (optional)
|
# issues_enabled (optional)
|
||||||
# merge_requests_enabled (optional)
|
# merge_requests_enabled (optional)
|
||||||
|
# builds_enabled (optional)
|
||||||
# wiki_enabled (optional)
|
# wiki_enabled (optional)
|
||||||
# snippets_enabled (optional)
|
# snippets_enabled (optional)
|
||||||
# namespace_id (optional) - defaults to user namespace
|
# namespace_id (optional) - defaults to user namespace
|
||||||
|
@ -90,6 +91,7 @@ module API
|
||||||
:description,
|
:description,
|
||||||
:issues_enabled,
|
:issues_enabled,
|
||||||
:merge_requests_enabled,
|
:merge_requests_enabled,
|
||||||
|
:builds_enabled,
|
||||||
:wiki_enabled,
|
:wiki_enabled,
|
||||||
:snippets_enabled,
|
:snippets_enabled,
|
||||||
:namespace_id,
|
:namespace_id,
|
||||||
|
@ -117,6 +119,7 @@ module API
|
||||||
# default_branch (optional) - 'master' by default
|
# default_branch (optional) - 'master' by default
|
||||||
# issues_enabled (optional)
|
# issues_enabled (optional)
|
||||||
# merge_requests_enabled (optional)
|
# merge_requests_enabled (optional)
|
||||||
|
# builds_enabled (optional)
|
||||||
# wiki_enabled (optional)
|
# wiki_enabled (optional)
|
||||||
# snippets_enabled (optional)
|
# snippets_enabled (optional)
|
||||||
# public (optional) - if true same as setting visibility_level = 20
|
# public (optional) - if true same as setting visibility_level = 20
|
||||||
|
@ -132,6 +135,7 @@ module API
|
||||||
:default_branch,
|
:default_branch,
|
||||||
:issues_enabled,
|
:issues_enabled,
|
||||||
:merge_requests_enabled,
|
:merge_requests_enabled,
|
||||||
|
:builds_enabled,
|
||||||
:wiki_enabled,
|
:wiki_enabled,
|
||||||
:snippets_enabled,
|
:snippets_enabled,
|
||||||
:public,
|
:public,
|
||||||
|
@ -172,6 +176,7 @@ module API
|
||||||
# description (optional) - short project description
|
# description (optional) - short project description
|
||||||
# issues_enabled (optional)
|
# issues_enabled (optional)
|
||||||
# merge_requests_enabled (optional)
|
# merge_requests_enabled (optional)
|
||||||
|
# builds_enabled (optional)
|
||||||
# wiki_enabled (optional)
|
# wiki_enabled (optional)
|
||||||
# snippets_enabled (optional)
|
# snippets_enabled (optional)
|
||||||
# public (optional) - if true same as setting visibility_level = 20
|
# public (optional) - if true same as setting visibility_level = 20
|
||||||
|
@ -185,6 +190,7 @@ module API
|
||||||
:default_branch,
|
:default_branch,
|
||||||
:issues_enabled,
|
:issues_enabled,
|
||||||
:merge_requests_enabled,
|
:merge_requests_enabled,
|
||||||
|
:builds_enabled,
|
||||||
:wiki_enabled,
|
:wiki_enabled,
|
||||||
:snippets_enabled,
|
:snippets_enabled,
|
||||||
:public,
|
:public,
|
||||||
|
|
|
@ -31,16 +31,20 @@ FactoryGirl.define do
|
||||||
factory :ci_project_without_token, class: Ci::Project do
|
factory :ci_project_without_token, class: Ci::Project do
|
||||||
default_ref 'master'
|
default_ref 'master'
|
||||||
|
|
||||||
gl_project factory: :empty_project
|
|
||||||
|
|
||||||
shared_runners_enabled false
|
shared_runners_enabled false
|
||||||
|
|
||||||
factory :ci_project do
|
factory :ci_project do
|
||||||
token 'iPWx6WM4lhHNedGfBpPJNP'
|
token 'iPWx6WM4lhHNedGfBpPJNP'
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :ci_public_project do
|
initialize_with do
|
||||||
public true
|
# TODO:
|
||||||
|
# this is required, because builds_enabled is initialized when Project is created
|
||||||
|
# and this create gitlab_ci_project if builds is set to true
|
||||||
|
# here we take created gitlab_ci_project and update it's attributes
|
||||||
|
ci_project = create(:empty_project).ensure_gitlab_ci_project
|
||||||
|
ci_project.update_attributes(attributes)
|
||||||
|
ci_project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Ci::Project do
|
describe Ci::Project do
|
||||||
let(:gl_project) { FactoryGirl.create :empty_project }
|
let(:project) { FactoryGirl.create :ci_project }
|
||||||
let(:project) { FactoryGirl.create :ci_project, gl_project: gl_project }
|
let(:gl_project) { project.gl_project }
|
||||||
subject { project }
|
subject { project }
|
||||||
|
|
||||||
it { is_expected.to have_many(:runner_projects) }
|
it { is_expected.to have_many(:runner_projects) }
|
||||||
|
@ -194,18 +194,6 @@ describe Ci::Project do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Project.parse' do
|
|
||||||
let(:project) { FactoryGirl.create :project }
|
|
||||||
|
|
||||||
subject { Ci::Project.parse(project) }
|
|
||||||
|
|
||||||
it { is_expected.to be_valid }
|
|
||||||
it { is_expected.to be_kind_of(Ci::Project) }
|
|
||||||
it { expect(subject.name).to eq(project.name_with_namespace) }
|
|
||||||
it { expect(subject.gitlab_id).to eq(project.id) }
|
|
||||||
it { expect(subject.gitlab_url).to eq(project.web_url) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe :repo_url_with_auth do
|
describe :repo_url_with_auth do
|
||||||
let(:project) { FactoryGirl.create :ci_project }
|
let(:project) { FactoryGirl.create :ci_project }
|
||||||
subject { project.repo_url_with_auth }
|
subject { project.repo_url_with_auth }
|
||||||
|
|
|
@ -415,12 +415,15 @@ describe Project do
|
||||||
it { expect(project.ci_commit(commit.sha)).to eq(commit) }
|
it { expect(project.ci_commit(commit.sha)).to eq(commit) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :enable_ci do
|
describe :builds_enabled do
|
||||||
let(:project) { create :project }
|
let(:project) { create :project }
|
||||||
|
|
||||||
before { project.enable_ci }
|
before { project.builds_enabled = true }
|
||||||
|
|
||||||
it { expect(project.gitlab_ci?).to be_truthy }
|
subject { project.builds_enabled }
|
||||||
|
|
||||||
|
it { is_expected.to eq(project.gitlab_ci_service.active) }
|
||||||
|
it { expect(project.builds_enabled?).to be_truthy }
|
||||||
it { expect(project.gitlab_ci_project).to be_a(Ci::Project) }
|
it { expect(project.gitlab_ci_project).to be_a(Ci::Project) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,11 @@ describe API::API, api: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
|
it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
|
||||||
[project, project2, project3].each{ |project| project.build_missing_services }
|
[project, project2, project3].each do |project|
|
||||||
project2.gitlab_ci_service.update(active: true)
|
project.builds_enabled = false
|
||||||
|
project.build_missing_services
|
||||||
|
end
|
||||||
|
project2.builds_enabled = true
|
||||||
get api('/projects', user), { ci_enabled_first: 'true' }
|
get api('/projects', user), { ci_enabled_first: 'true' }
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(json_response).to be_an Array
|
expect(json_response).to be_an Array
|
||||||
|
|
|
@ -46,6 +46,7 @@ describe API::API, api: true do
|
||||||
delete api("/projects/#{project.id}/services/#{dashed_service}", user)
|
delete api("/projects/#{project.id}/services/#{dashed_service}", user)
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
project.send(service_method).reload
|
||||||
expect(project.send(service_method).activated?).to be_falsey
|
expect(project.send(service_method).activated?).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe Ci::API::API do
|
||||||
|
|
||||||
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
|
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
|
||||||
let(:project) { FactoryGirl.create(:ci_project) }
|
let(:project) { FactoryGirl.create(:ci_project) }
|
||||||
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
|
let(:gl_project) { project.gl_project }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_ci_commit_to_return_yaml_file
|
stub_ci_commit_to_return_yaml_file
|
||||||
|
@ -14,7 +14,7 @@ describe Ci::API::API do
|
||||||
describe "Builds API for runners" do
|
describe "Builds API for runners" do
|
||||||
let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
|
let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
|
||||||
let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
|
let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
|
||||||
let(:shared_gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: shared_project) }
|
let(:shared_gl_project) { shared_project.gl_project }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
|
FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
|
||||||
|
@ -160,15 +160,13 @@ describe Ci::API::API do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "using token as parameter" do
|
it "using token as parameter" do
|
||||||
settings = Gitlab::CurrentSettings::current_application_settings
|
stub_application_setting(max_artifacts_size: 0)
|
||||||
settings.update_attributes(max_artifacts_size: 0)
|
|
||||||
post authorize_url, { token: build.project.token, filesize: 100 }, headers
|
post authorize_url, { token: build.project.token, filesize: 100 }, headers
|
||||||
expect(response.status).to eq(413)
|
expect(response.status).to eq(413)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "using token as header" do
|
it "using token as header" do
|
||||||
settings = Gitlab::CurrentSettings::current_application_settings
|
stub_application_setting(max_artifacts_size: 0)
|
||||||
settings.update_attributes(max_artifacts_size: 0)
|
|
||||||
post authorize_url, { filesize: 100 }, headers_with_token
|
post authorize_url, { filesize: 100 }, headers_with_token
|
||||||
expect(response.status).to eq(413)
|
expect(response.status).to eq(413)
|
||||||
end
|
end
|
||||||
|
@ -220,8 +218,7 @@ describe Ci::API::API do
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
settings = Gitlab::CurrentSettings::current_application_settings
|
stub_application_setting(max_artifacts_size: 0)
|
||||||
settings.update_attributes(max_artifacts_size: 0)
|
|
||||||
upload_artifacts(file_upload, headers_with_token)
|
upload_artifacts(file_upload, headers_with_token)
|
||||||
expect(response.status).to eq(413)
|
expect(response.status).to eq(413)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe Ci::API::API, 'Commits' do
|
||||||
include ApiHelpers
|
include ApiHelpers
|
||||||
|
|
||||||
let(:project) { FactoryGirl.create(:ci_project) }
|
let(:project) { FactoryGirl.create(:ci_project) }
|
||||||
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
|
let(:gl_project) { project.gl_project }
|
||||||
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
|
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
|
||||||
|
|
||||||
let(:options) do
|
let(:options) do
|
||||||
|
|
|
@ -41,8 +41,8 @@ describe Ci::API::API do
|
||||||
describe "GET /projects/owned" do
|
describe "GET /projects/owned" do
|
||||||
let!(:gl_project1) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
|
let!(:gl_project1) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
|
||||||
let!(:gl_project2) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
|
let!(:gl_project2) {FactoryGirl.create(:empty_project, namespace: user.namespace)}
|
||||||
let!(:project1) { FactoryGirl.create(:ci_project, gl_project: gl_project1) }
|
let!(:project1) { gl_project1.ensure_gitlab_ci_project }
|
||||||
let!(:project2) { FactoryGirl.create(:ci_project, gl_project: gl_project2) }
|
let!(:project2) { gl_project2.ensure_gitlab_ci_project }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
project1.gl_project.team << [user, :developer]
|
project1.gl_project.team << [user, :developer]
|
||||||
|
@ -180,87 +180,53 @@ describe Ci::API::API do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /projects" do
|
describe "POST /projects/:id/runners/:id" do
|
||||||
let(:gl_project) { FactoryGirl.create :empty_project }
|
let(:project) { FactoryGirl.create(:ci_project) }
|
||||||
let(:project_info) do
|
let(:runner) { FactoryGirl.create(:ci_runner) }
|
||||||
{
|
|
||||||
gitlab_id: gl_project.id
|
it "should add the project to the runner" do
|
||||||
}
|
project.gl_project.team << [user, :master]
|
||||||
|
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
||||||
|
expect(response.status).to eq(201)
|
||||||
|
|
||||||
|
project.reload
|
||||||
|
expect(project.runners.first.id).to eq(runner.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:invalid_project_info) { {} }
|
it "should fail if it tries to link a non-existing project or runner" do
|
||||||
|
post ci_api("/projects/#{project.id}/runners/non-existing"), options
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
|
||||||
context "with valid project info" do
|
post ci_api("/projects/non-existing/runners/#{runner.id}"), options
|
||||||
before do
|
expect(response.status).to eq(404)
|
||||||
options.merge!(project_info)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a project with valid data" do
|
|
||||||
post ci_api("/projects"), options
|
|
||||||
expect(response.status).to eq(201)
|
|
||||||
expect(json_response['name']).to eq(gl_project.name_with_namespace)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid project info" do
|
it "non-manager is not authorized" do
|
||||||
before do
|
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
|
||||||
options.merge!(invalid_project_info)
|
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
||||||
end
|
expect(response.status).to eq(401)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should error with invalid data" do
|
describe "DELETE /projects/:id/runners/:id" do
|
||||||
post ci_api("/projects"), options
|
let(:project) { FactoryGirl.create(:ci_project) }
|
||||||
expect(response.status).to eq(400)
|
let(:runner) { FactoryGirl.create(:ci_runner) }
|
||||||
end
|
|
||||||
|
it "should remove the project from the runner" do
|
||||||
|
project.gl_project.team << [user, :master]
|
||||||
|
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
||||||
|
|
||||||
|
expect(project.runners).to be_present
|
||||||
|
delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
project.reload
|
||||||
|
expect(project.runners).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /projects/:id/runners/:id" do
|
it "non-manager is not authorized" do
|
||||||
let(:project) { FactoryGirl.create(:ci_project) }
|
delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
||||||
let(:runner) { FactoryGirl.create(:ci_runner) }
|
expect(response.status).to eq(401)
|
||||||
|
|
||||||
it "should add the project to the runner" do
|
|
||||||
project.gl_project.team << [user, :master]
|
|
||||||
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
|
||||||
expect(response.status).to eq(201)
|
|
||||||
|
|
||||||
project.reload
|
|
||||||
expect(project.runners.first.id).to eq(runner.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should fail if it tries to link a non-existing project or runner" do
|
|
||||||
post ci_api("/projects/#{project.id}/runners/non-existing"), options
|
|
||||||
expect(response.status).to eq(404)
|
|
||||||
|
|
||||||
post ci_api("/projects/non-existing/runners/#{runner.id}"), options
|
|
||||||
expect(response.status).to eq(404)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "non-manager is not authorized" do
|
|
||||||
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
|
|
||||||
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
|
||||||
expect(response.status).to eq(401)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "DELETE /projects/:id/runners/:id" do
|
|
||||||
let(:project) { FactoryGirl.create(:ci_project) }
|
|
||||||
let(:runner) { FactoryGirl.create(:ci_runner) }
|
|
||||||
|
|
||||||
it "should remove the project from the runner" do
|
|
||||||
project.gl_project.team << [user, :master]
|
|
||||||
post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
|
||||||
|
|
||||||
expect(project.runners).to be_present
|
|
||||||
delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
|
|
||||||
project.reload
|
|
||||||
expect(project.runners).to be_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
it "non-manager is not authorized" do
|
|
||||||
delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options
|
|
||||||
expect(response.status).to eq(401)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe Ci::API::API do
|
||||||
describe 'POST /projects/:project_id/refs/:ref/trigger' do
|
describe 'POST /projects/:project_id/refs/:ref/trigger' do
|
||||||
let!(:trigger_token) { 'secure token' }
|
let!(:trigger_token) { 'secure token' }
|
||||||
let!(:gl_project) { FactoryGirl.create(:project) }
|
let!(:gl_project) { FactoryGirl.create(:project) }
|
||||||
let!(:project) { FactoryGirl.create(:ci_project, gl_project: gl_project) }
|
let!(:project) { gl_project.ensure_gitlab_ci_project }
|
||||||
let!(:project2) { FactoryGirl.create(:ci_project) }
|
let!(:project2) { FactoryGirl.create(:ci_project) }
|
||||||
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
|
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
|
||||||
let(:options) do
|
let(:options) do
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Ci::CreateTriggerRequestService do
|
describe Ci::CreateTriggerRequestService do
|
||||||
let(:service) { Ci::CreateTriggerRequestService.new }
|
let(:service) { Ci::CreateTriggerRequestService.new }
|
||||||
let(:gl_project) { create(:project) }
|
let(:gl_project) { create(:project) }
|
||||||
let(:project) { create(:ci_project, gl_project: gl_project) }
|
let(:project) { gl_project.ensure_gitlab_ci_project }
|
||||||
let(:trigger) { create(:ci_trigger, project: project) }
|
let(:trigger) { create(:ci_trigger, project: project) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -70,6 +70,28 @@ describe Projects::CreateService do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'builds_enabled global setting' do
|
||||||
|
let(:project) { create_project(@user, @opts) }
|
||||||
|
|
||||||
|
subject { project.builds_enabled? }
|
||||||
|
|
||||||
|
context 'global builds_enabled false does not enable CI by default' do
|
||||||
|
before do
|
||||||
|
@opts.merge!(builds_enabled: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to be_falsey }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'global builds_enabled true does enable CI by default' do
|
||||||
|
before do
|
||||||
|
@opts.merge!(builds_enabled: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to be_truthy }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'restricted visibility level' do
|
context 'restricted visibility level' do
|
||||||
before do
|
before do
|
||||||
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
||||||
|
|
|
@ -46,7 +46,7 @@ describe Projects::ForkService do
|
||||||
it "fork and enable CI for fork" do
|
it "fork and enable CI for fork" do
|
||||||
@from_project.enable_ci
|
@from_project.enable_ci
|
||||||
@to_project = fork_project(@from_project, @to_user)
|
@to_project = fork_project(@from_project, @to_user)
|
||||||
expect(@to_project.gitlab_ci?).to be_truthy
|
expect(@to_project.builds_enabled?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue