diff options
89 files changed, 646 insertions, 585 deletions
diff --git a/CHANGELOG b/CHANGELOG index f34f79d18dd..492e4b9aebf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,9 @@ v 8.1.0 (unreleased) - Fix grammar in admin area "labels" .nothing-here-block when no labels exist. - Move CI runners page to project settings area - Move CI variables page to project settings area + - Move CI triggers page to project settings area + - Move CI project settings page to CE project settings area + - Fix bug when removed file was not appearing in merge request diff v 8.0.3 - Fix URL shown in Slack notifications @@ -33,6 +36,7 @@ v 8.0.2 - Use standard Markdown font in Markdown preview instead of fixed-width font (Stan Hu) - Fix Reply by email for non-UTF-8 messages. - Add option to use StartTLS with Reply by email IMAP server. + - Allow AWS S3 Server-Side Encryption with Amazon S3-Managed Keys for backups (Paul Beattie) v 8.0.1 - Remove git refs used internally by GitLab from network graph (Stan Hu) diff --git a/app/controllers/ci/admin/runners_controller.rb b/app/controllers/ci/admin/runners_controller.rb index dc3508b49dd..9a68add9083 100644 --- a/app/controllers/ci/admin/runners_controller.rb +++ b/app/controllers/ci/admin/runners_controller.rb @@ -12,7 +12,10 @@ module Ci def show @builds = @runner.builds.order('id DESC').first(30) @projects = Ci::Project.all - @projects = @projects.search(params[:search]) if params[:search].present? + if params[:search].present? + @gl_projects = ::Project.search(params[:search]) + @projects = @projects.where(gitlab_id: @gl_projects.select(:id)) + end @projects = @projects.where("ci_projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any? @projects = @projects.page(params[:page]).per(30) end diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 13766fb8f6f..e8788955eba 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -2,9 +2,9 @@ module Ci class ProjectsController < Ci::ApplicationController before_action :authenticate_user!, except: [:build, :badge, :show] before_action :authenticate_public_page!, only: :show - before_action :project, only: [:build, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml] + before_action :project, only: [:build, :show, :badge, :toggle_shared_runners, :dumped_yaml] before_action :authorize_access_project!, except: [:build, :badge, :show, :new, :disabled] - before_action :authorize_manage_project!, only: [:edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml] + before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml] before_action :authenticate_token!, only: [:build] before_action :no_cache, only: [:badge] skip_before_action :check_enable_flag!, only: [:disabled] @@ -23,28 +23,6 @@ module Ci @commits = @commits.page(params[:page]).per(20) end - def edit - end - - def update - if project.update_attributes(project_params) - Ci::EventService.new.change_project_settings(current_user, project) - - redirect_to :back, notice: 'Project was successfully updated.' - else - render action: "edit" - end - end - - def destroy - project.gl_project.gitlab_ci_service.update_attributes(active: false) - project.destroy - - Ci::EventService.new.remove_project(current_user, project) - - redirect_to ci_projects_url - end - # Project status badge # Image with build status for sha or ref def badge @@ -74,12 +52,5 @@ module Ci response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" end - - def project_params - params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build, - :polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients, - :email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token, - { variables_attributes: [:id, :key, :value, :_destroy] }) - end end end diff --git a/app/controllers/ci/triggers_controller.rb b/app/controllers/ci/triggers_controller.rb deleted file mode 100644 index a39cc5d3a56..00000000000 --- a/app/controllers/ci/triggers_controller.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Ci - class TriggersController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def index - @triggers = @project.triggers - @trigger = Ci::Trigger.new - end - - def create - @trigger = @project.triggers.new - @trigger.save - - if @trigger.valid? - redirect_to ci_project_triggers_path(@project) - else - @triggers = @project.triggers.select(&:persisted?) - render :index - end - end - - def destroy - trigger.destroy - - redirect_to ci_project_triggers_path(@project) - end - - private - - def trigger - @trigger ||= @project.triggers.find(params[:id]) - end - - def project - @project = Ci::Project.find(params[:project_id]) - end - end -end diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 56a63ce9758..519d6d6127e 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -33,6 +33,6 @@ class Projects::ApplicationController < ApplicationController end def ci_project - @ci_project ||= @project.gitlab_ci_project + @ci_project ||= @project.ensure_gitlab_ci_project end end diff --git a/app/controllers/projects/ci_settings_controller.rb b/app/controllers/projects/ci_settings_controller.rb new file mode 100644 index 00000000000..a263242a850 --- /dev/null +++ b/app/controllers/projects/ci_settings_controller.rb @@ -0,0 +1,36 @@ +class Projects::CiSettingsController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout "project_settings" + + def edit + end + + def update + if ci_project.update_attributes(project_params) + Ci::EventService.new.change_project_settings(current_user, ci_project) + + redirect_to edit_namespace_project_ci_settings_path(project.namespace, project), notice: 'Project was successfully updated.' + else + render action: "edit" + end + end + + def destroy + ci_project.destroy + Ci::EventService.new.remove_project(current_user, ci_project) + project.gitlab_ci_service.update_attributes(active: false) + + redirect_to project_path(project), notice: "CI was disabled for this project" + end + + protected + + def project_params + params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build, + :polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients, + :email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token, + { variables_attributes: [:id, :key, :value, :_destroy] }) + end +end diff --git a/app/controllers/projects/triggers_controller.rb b/app/controllers/projects/triggers_controller.rb new file mode 100644 index 00000000000..782ebd01b05 --- /dev/null +++ b/app/controllers/projects/triggers_controller.rb @@ -0,0 +1,35 @@ +class Projects::TriggersController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout 'project_settings' + + def index + @triggers = @ci_project.triggers + @trigger = Ci::Trigger.new + end + + def create + @trigger = @ci_project.triggers.new + @trigger.save + + if @trigger.valid? + redirect_to namespace_project_triggers_path(@project.namespace, @project) + else + @triggers = @ci_project.triggers.select(&:persisted?) + render :index + end + end + + def destroy + trigger.destroy + + redirect_to namespace_project_triggers_path(@project.namespace, @project) + end + + private + + def trigger + @trigger ||= @ci_project.triggers.find(params[:id]) + end +end diff --git a/app/helpers/builds_helper.rb b/app/helpers/builds_helper.rb new file mode 100644 index 00000000000..b6658e52d09 --- /dev/null +++ b/app/helpers/builds_helper.rb @@ -0,0 +1,17 @@ +module BuildsHelper + def build_ref_link build + gitlab_ref_link build.project, build.ref + end + + def build_compare_link build + gitlab_compare_link build.project, build.commit.short_before_sha, build.short_sha + end + + def build_commit_link build + gitlab_commit_link build.project, build.short_sha + end + + def build_url(build) + ci_project_build_url(build.project, build) + end +end diff --git a/app/helpers/ci/application_helper.rb b/app/helpers/ci/application_helper.rb deleted file mode 100644 index 9fe6282bb81..00000000000 --- a/app/helpers/ci/application_helper.rb +++ /dev/null @@ -1,54 +0,0 @@ -module Ci - module ApplicationHelper - def loader_html - image_tag 'ci/loader.gif', alt: 'Loading' - end - - def date_from_to(from, to) - "#{from.to_s(:short)} - #{to.to_s(:short)}" - end - - def duration_in_words(finished_at, started_at) - if finished_at && started_at - interval_in_seconds = finished_at.to_i - started_at.to_i - elsif started_at - interval_in_seconds = Time.now.to_i - started_at.to_i - end - - time_interval_in_words(interval_in_seconds) - end - - def time_interval_in_words(interval_in_seconds) - minutes = interval_in_seconds / 60 - seconds = interval_in_seconds - minutes * 60 - - if minutes >= 1 - "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}" - else - "#{pluralize(seconds, "second")}" - end - end - - def ci_icon_for_status(status) - icon_name = - case status - when 'success' - 'check-square' - when 'failed' - 'close' - when 'running', 'pending' - 'clock-o' - else - 'circle' - end - - icon(icon_name) - end - - def ci_status_with_icon(status) - content_tag :span, class: "ci-status ci-#{status}" do - ci_icon_for_status(status) + ' '.html_safe + status - end - end - end -end diff --git a/app/helpers/ci/builds_helper.rb b/app/helpers/ci/builds_helper.rb deleted file mode 100644 index 5d6e785d951..00000000000 --- a/app/helpers/ci/builds_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Ci - module BuildsHelper - def build_ref_link build - gitlab_ref_link build.project, build.ref - end - - def build_compare_link build - gitlab_compare_link build.project, build.commit.short_before_sha, build.short_sha - end - - def build_commit_link build - gitlab_commit_link build.project, build.short_sha - end - - def build_url(build) - ci_project_build_url(build.project, build) - end - end -end diff --git a/app/helpers/ci/gitlab_helper.rb b/app/helpers/ci/gitlab_helper.rb index 2b89a0ce93e..13e4d0fd9c3 100644 --- a/app/helpers/ci/gitlab_helper.rb +++ b/app/helpers/ci/gitlab_helper.rb @@ -27,9 +27,9 @@ module Ci commits = project.commits if commits.any? && commits.last.push_data[:ci_yaml_file] - "#{@project.gitlab_url}/edit/master/.gitlab-ci.yml" + "#{project.gitlab_url}/edit/master/.gitlab-ci.yml" else - "#{@project.gitlab_url}/new/master" + "#{project.gitlab_url}/new/master" end end end diff --git a/app/helpers/ci/icons_helper.rb b/app/helpers/ci/icons_helper.rb deleted file mode 100644 index be40f79e880..00000000000 --- a/app/helpers/ci/icons_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Ci - module IconsHelper - def boolean_to_icon(value) - if value.to_s == "true" - content_tag :i, nil, class: 'fa fa-circle cgreen' - else - content_tag :i, nil, class: 'fa fa-power-off clgray' - end - end - end -end diff --git a/app/helpers/ci/runners_helper.rb b/app/helpers/ci/runners_helper.rb deleted file mode 100644 index 03c9914641e..00000000000 --- a/app/helpers/ci/runners_helper.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Ci - module RunnersHelper - def runner_status_icon(runner) - unless runner.contacted_at - return content_tag :i, nil, - class: "fa fa-warning-sign", - title: "New runner. Has not connected yet" - end - - status = - if runner.active? - runner.contacted_at > 3.hour.ago ? :online : :offline - else - :paused - end - - content_tag :i, nil, - class: "fa fa-circle runner-status-#{status}", - title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago" - end - end -end diff --git a/app/helpers/ci/triggers_helper.rb b/app/helpers/ci/triggers_helper.rb deleted file mode 100644 index 0d2438928ce..00000000000 --- a/app/helpers/ci/triggers_helper.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Ci - module TriggersHelper - def ci_build_trigger_url(project_id, ref_name) - "#{Settings.gitlab_ci.url}/ci/api/v1/projects/#{project_id}/refs/#{ref_name}/trigger" - end - end -end diff --git a/app/helpers/ci/user_helper.rb b/app/helpers/ci/user_helper.rb deleted file mode 100644 index c332d6ed9cf..00000000000 --- a/app/helpers/ci/user_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Ci - module UserHelper - def user_avatar_url(user = nil, size = nil, default = 'identicon') - size = 40 if size.nil? || size <= 0 - - if user.blank? || user.avatar_url.blank? - 'ci/no_avatar.png' - elsif /^(http(s?):\/\/(www|secure)\.gravatar\.com\/avatar\/(\w*))/ =~ user.avatar_url - Regexp.last_match[0] + "?s=#{size}&d=#{default}" - else - user.avatar_url - end - end - end -end diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 18c30ddb281..3a88ed7107e 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -4,19 +4,7 @@ module CiStatusHelper end def ci_status_icon(ci_commit) - icon_name = - case ci_commit.status - when 'success' - 'check' - when 'failed' - 'close' - when 'running', 'pending' - 'clock-o' - else - 'circle' - end - - icon(icon_name) + ci_icon_for_status(ci_commit.status) end def ci_status_color(ci_commit) @@ -31,4 +19,26 @@ module CiStatusHelper 'gray' end end + + def ci_status_with_icon(status) + content_tag :span, class: "ci-status ci-#{status}" do + ci_icon_for_status(status) + ' '.html_safe + status + end + end + + def ci_icon_for_status(status) + icon_name = + case status + when 'success' + 'check' + when 'failed' + 'close' + when 'running', 'pending' + 'clock-o' + else + 'circle' + end + + icon(icon_name) + end end diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 6ffa1a7121d..9d718e13b85 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -167,4 +167,23 @@ module DiffHelper content_tag(:span, commit_id, class: 'monospace'), ].join(' ').html_safe end + + def commit_for_diff(diff) + if diff.deleted_file + @merge_request ? @merge_request.commits.last : @commit.parent_id + else + @commit + end + end + + def diff_file_html_data(project, diff_commit, diff_file) + { + blob_diff_path: namespace_project_blob_diff_path(project.namespace, project, + tree_join(diff_commit.id, diff_file.file_path)) + } + end + + def editable_diff?(diff) + !diff.deleted_file && @merge_request && @merge_request.source_project + end end diff --git a/app/helpers/runners_helper.rb b/app/helpers/runners_helper.rb new file mode 100644 index 00000000000..5d7d06c8490 --- /dev/null +++ b/app/helpers/runners_helper.rb @@ -0,0 +1,20 @@ +module RunnersHelper + def runner_status_icon(runner) + unless runner.contacted_at + return content_tag :i, nil, + class: "fa fa-warning-sign", + title: "New runner. Has not connected yet" + end + + status = + if runner.active? + runner.contacted_at > 3.hour.ago ? :online : :offline + else + :paused + end + + content_tag :i, nil, + class: "fa fa-circle runner-status-#{status}", + title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago" + end +end diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb new file mode 100644 index 00000000000..8142f733e76 --- /dev/null +++ b/app/helpers/time_helper.rb @@ -0,0 +1,27 @@ +module TimeHelper + def duration_in_words(finished_at, started_at) + if finished_at && started_at + interval_in_seconds = finished_at.to_i - started_at.to_i + elsif started_at + interval_in_seconds = Time.now.to_i - started_at.to_i + end + + time_interval_in_words(interval_in_seconds) + end + + def time_interval_in_words(interval_in_seconds) + minutes = interval_in_seconds / 60 + seconds = interval_in_seconds - minutes * 60 + + if minutes >= 1 + "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}" + else + "#{pluralize(seconds, "second")}" + end + end + + + def date_from_to(from, to) + "#{from.to_s(:short)} - #{to.to_s(:short)}" + end +end diff --git a/app/helpers/triggers_helper.rb b/app/helpers/triggers_helper.rb new file mode 100644 index 00000000000..2a3a7e80fca --- /dev/null +++ b/app/helpers/triggers_helper.rb @@ -0,0 +1,5 @@ +module TriggersHelper + def ci_build_trigger_url(project_id, ref_name) + "#{Settings.gitlab_ci.url}/ci/api/v1/projects/#{project_id}/refs/#{ref_name}/trigger" + end +end diff --git a/app/mailers/ci/notify.rb b/app/mailers/ci/notify.rb index 4462da0d7d2..404842cf213 100644 --- a/app/mailers/ci/notify.rb +++ b/app/mailers/ci/notify.rb @@ -2,7 +2,6 @@ module Ci class Notify < ActionMailer::Base include Ci::Emails::Builds - add_template_helper Ci::ApplicationHelper add_template_helper Ci::GitlabHelper default_url_options[:host] = Gitlab.config.gitlab.host diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 8096d4fa5ae..cda4fdd4982 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -30,7 +30,6 @@ module Ci LAZY_ATTRIBUTES = ['trace'] belongs_to :commit, class_name: 'Ci::Commit' - belongs_to :project, class_name: 'Ci::Project' belongs_to :runner, class_name: 'Ci::Runner' belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' @@ -80,7 +79,6 @@ module Ci new_build.commands = build.commands new_build.tag_list = build.tag_list new_build.commit_id = build.commit_id - new_build.project_id = build.project_id new_build.name = build.name new_build.allow_failure = build.allow_failure new_build.stage = build.stage @@ -137,7 +135,7 @@ module Ci state :canceled, value: 'canceled' end - delegate :sha, :short_sha, :before_sha, :ref, + delegate :sha, :short_sha, :before_sha, :ref, :project, to: :commit, prefix: false def trace_html @@ -188,7 +186,7 @@ module Ci end def project_id - commit.project_id + commit.project.id end def project_name diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index f102d0a7679..6d048779cde 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -18,8 +18,8 @@ module Ci class Commit < ActiveRecord::Base extend Ci::Model - - belongs_to :project, class_name: 'Ci::Project' + + belongs_to :gl_project, class_name: '::Project', foreign_key: :gl_project_id has_many :builds, dependent: :destroy, class_name: 'Ci::Build' has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest' @@ -36,6 +36,14 @@ module Ci sha end + def project + @project ||= gl_project.ensure_gitlab_ci_project + end + + def project_id + project.id + end + def last_build builds.order(:id).last end @@ -111,15 +119,14 @@ module Ci builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag) builds_attrs.map do |build_attrs| builds.create!({ - project: project, - name: build_attrs[:name], - commands: build_attrs[:script], - tag_list: build_attrs[:tags], - options: build_attrs[:options], - allow_failure: build_attrs[:allow_failure], - stage: build_attrs[:stage], - trigger_request: trigger_request, - }) + name: build_attrs[:name], + commands: build_attrs[:script], + tag_list: build_attrs[:tags], + options: build_attrs[:options], + allow_failure: build_attrs[:allow_failure], + stage: build_attrs[:stage], + trigger_request: trigger_request, + }) end end diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 8fb54b90d61..f0a8fc703b5 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -33,15 +33,12 @@ module Ci belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id - has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit' - has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' has_many :runners, through: :runner_projects, class_name: 'Ci::Runner' has_many :web_hooks, dependent: :destroy, class_name: 'Ci::WebHook' has_many :events, dependent: :destroy, class_name: 'Ci::Event' has_many :variables, dependent: :destroy, class_name: 'Ci::Variable' has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger' - has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit' # Project services has_many :services, dependent: :destroy, class_name: 'Ci::Service' @@ -51,19 +48,18 @@ module Ci accepts_nested_attributes_for :variables, allow_destroy: true + delegate :name_with_namespace, :path_with_namespace, :web_url, :http_url_to_repo, :ssh_url_to_repo, to: :gl_project + # # Validations # - validates_presence_of :name, :timeout, :token, :default_ref, - :path, :ssh_url_to_repo, :gitlab_id + validates_presence_of :timeout, :token, :default_ref, :gitlab_id validates_uniqueness_of :gitlab_id validates :polling_interval, - presence: true, - if: ->(project) { project.always_build.present? } - - scope :public_only, ->() { where(public: true) } + presence: true, + if: ->(project) { project.always_build.present? } before_validation :set_default_values @@ -79,11 +75,8 @@ module Ci def parse(project) params = { - name: project.name_with_namespace, gitlab_id: project.id, - path: project.path_with_namespace, default_ref: project.default_branch || 'master', - ssh_url_to_repo: project.ssh_url_to_repo, email_add_pusher: current_application_settings.add_pusher, email_only_broken_builds: current_application_settings.all_broken_builds, } @@ -104,15 +97,22 @@ module Ci end def ordered_by_last_commit_date - last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY project_id)" - joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.id = last_commit.project_id"). + last_commit_subquery = "(SELECT gl_project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY gl_project_id)" + joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.gitlab_id = last_commit.gl_project_id"). order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC") end + end - def search(query) - where("LOWER(#{Ci::Project.table_name}.name) LIKE :query", - query: "%#{query.try(:downcase)}%") - end + def name + name_with_namespace + end + + def path + path_with_namespace + end + + def gitlab_url + web_url end def any_runners? @@ -125,10 +125,11 @@ module Ci def set_default_values self.token = SecureRandom.hex(15) if self.token.blank? + self.default_ref ||= 'master' end def tracked_refs - @tracked_refs ||= default_ref.split(",").map{|ref| ref.strip} + @tracked_refs ||= default_ref.split(",").map { |ref| ref.strip } end def valid_token? token @@ -168,7 +169,7 @@ module Ci # using http and basic auth def repo_url_with_auth auth = "gitlab-ci-token:#{token}@" - url = gitlab_url + ".git" + url = http_url_to_repo + ".git" url.sub(/^https?:\/\//) do |prefix| prefix + auth end @@ -200,12 +201,16 @@ module Ci end end - def gitlab_url - File.join(Gitlab.config.gitlab.url, path) - end - def setup_finished? commits.any? end + + def commits + gl_project.ci_commits + end + + def builds + gl_project.ci_builds + end end end diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 1e9f78a3748..6838ccfaaab 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -41,6 +41,10 @@ module Ci query: "%#{query.try(:downcase)}%") end + def gl_projects_ids + projects.select(:gitlab_id) + end + def set_default_values self.token = SecureRandom.hex(15) if self.token.blank? end diff --git a/app/models/project.rb b/app/models/project.rb index e912c48467d..953b37e3f7a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -118,6 +118,8 @@ class Project < ActiveRecord::Base has_many :deploy_keys, through: :deploy_keys_projects has_many :users_star_projects, dependent: :destroy has_many :starrers, through: :users_star_projects, source: :user + has_many :ci_commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id + has_many :ci_builds, through: :ci_commits, source: :builds, dependent: :destroy, class_name: 'Ci::Build' has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id @@ -745,6 +747,10 @@ class Project < ActiveRecord::Base gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci? end + def ensure_gitlab_ci_project + gitlab_ci_project || create_gitlab_ci_project + end + def enable_ci(user) # Enable service service = gitlab_ci_service || create_gitlab_ci_service diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index 23ab206efba..436d4cfed81 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -70,11 +70,7 @@ class GitlabCiService < CiService def fork_registration(new_project, current_user) params = OpenStruct.new({ id: new_project.id, - name_with_namespace: new_project.name_with_namespace, - path_with_namespace: new_project.path_with_namespace, - web_url: new_project.web_url, - default_branch: new_project.default_branch, - ssh_url_to_repo: new_project.ssh_url_to_repo + default_branch: new_project.default_branch }) ci_project = Ci::Project.find_by!(gitlab_id: project.id) diff --git a/app/services/ci/register_build_service.rb b/app/services/ci/register_build_service.rb index 33f1c1e918d..71b61bbe389 100644 --- a/app/services/ci/register_build_service.rb +++ b/app/services/ci/register_build_service.rb @@ -8,10 +8,10 @@ module Ci builds = if current_runner.shared? # don't run projects which have not enables shared runners - builds.includes(:project).where(ci_projects: { shared_runners_enabled: true }) + builds.joins(commit: { gl_project: :gitlab_ci_project }).where(ci_projects: { shared_runners_enabled: true }) else # do run projects which are only assigned to this runner - builds.where(project_id: current_runner.projects) + builds.joins(:commit).where(ci_commits: { gl_project_id: current_runner.gl_projects_ids }) end builds = builds.order('created_at ASC') @@ -19,7 +19,7 @@ module Ci build = builds.find do |build| (build.tag_list - current_runner.tag_list).empty? end - + if build # In case when 2 runners try to assign the same build, second runner will be declined diff --git a/app/views/ci/admin/projects/_project.html.haml b/app/views/ci/admin/projects/_project.html.haml index c461206c72a..a342d6e1cf0 100644 --- a/app/views/ci/admin/projects/_project.html.haml +++ b/app/views/ci/admin/projects/_project.html.haml @@ -1,4 +1,4 @@ -- last_commit = project.last_commit +- last_commit = project.commits.last %tr %td = project.id diff --git a/app/views/layouts/ci/_nav_project.html.haml b/app/views/layouts/ci/_nav_project.html.haml index 4b0dc4fc2f5..3a2741367c1 100644 --- a/app/views/layouts/ci/_nav_project.html.haml +++ b/app/views/layouts/ci/_nav_project.html.haml @@ -16,11 +16,6 @@ = icon('link fw') %span Web Hooks - = nav_link path: 'triggers#index' do - = link_to ci_project_triggers_path(@project) do - = icon('retweet fw') - %span - Triggers = nav_link path: ['services#index', 'services#edit'] do = link_to ci_project_services_path(@project) do = icon('share fw') @@ -31,9 +26,3 @@ = icon('book fw') %span Events - %li.separate-item - = nav_link path: 'projects#edit' do - = link_to edit_ci_project_path(@project) do - = icon('cogs fw') - %span - Settings diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index 21d8655131f..b1a1d531846 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -1,6 +1,6 @@ %ul.nav.nav-sidebar = nav_link(path: ['root#index', 'projects#trending', 'projects#starred', 'dashboard/projects#index'], html_options: {class: 'home'}) do - = link_to root_path, title: 'Projects', data: {placement: 'right'} do + = link_to dashboard_projects_path, title: 'Projects', data: {placement: 'right'} do = icon('home fw') %span Projects diff --git a/app/views/layouts/nav/_project_settings.html.haml b/app/views/layouts/nav/_project_settings.html.haml index c8975fb8492..26cccb48f68 100644 --- a/app/views/layouts/nav/_project_settings.html.haml +++ b/app/views/layouts/nav/_project_settings.html.haml @@ -45,3 +45,13 @@ = icon('code fw') %span Variables + = nav_link path: 'triggers#index' do + = link_to namespace_project_triggers_path(@project.namespace, @project) do + = icon('retweet fw') + %span + Triggers + = nav_link path: 'ci_settings#edit' do + = link_to edit_namespace_project_ci_settings_path(@project.namespace, @project) do + = icon('building fw') + %span + CI Settings diff --git a/app/views/ci/projects/_form.html.haml b/app/views/projects/ci_settings/_form.html.haml index e782fd8a0f7..9f891f557a9 100644 --- a/app/views/ci/projects/_form.html.haml +++ b/app/views/projects/ci_settings/_form.html.haml @@ -1,17 +1,20 @@ +%h3.page-title + CI settings +%hr .bs-callout.help-callout %p If you want to test your .gitlab-ci.yml, you can use special tool - #{link_to "Lint", ci_lint_path} %p - Edit your - #{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@project)} + Edit your + #{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@ci_project)} -= nested_form_for [:ci, @project], html: { class: 'form-horizontal' } do |f| - - if @project.errors.any? += nested_form_for @ci_project, url: namespace_project_ci_settings_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f| + - if @ci_project.errors.any? #error_explanation - %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" + %p.lead= "#{pluralize(@ci_project.errors.count, "error")} prohibited this project from being saved:" .alert.alert-error %ul - - @project.errors.full_messages.each do |msg| + - @ci_project.errors.full_messages.each do |msg| %li= msg %fieldset @@ -93,8 +96,8 @@ = f.label :token, "CI token", class: 'control-label' .col-sm-10 = f.text_field :token, class: 'form-control', placeholder: 'xEeFCaDAB89' - + .form-actions = f.submit 'Save changes', class: 'btn btn-save' - - unless @project.new_record? - = link_to 'Remove Project', ci_project_path(@project), method: :delete, data: { confirm: 'Project will be removed. Are you sure?' }, class: 'btn btn-danger pull-right' + - unless @ci_project.new_record? + = link_to 'Remove Project', ci_project_path(@ci_project), method: :delete, data: { confirm: 'Project will be removed. Are you sure?' }, class: 'btn btn-danger pull-right' diff --git a/app/views/ci/projects/edit.html.haml b/app/views/projects/ci_settings/edit.html.haml index 876ae5182d4..e9040fe4337 100644 --- a/app/views/ci/projects/edit.html.haml +++ b/app/views/projects/ci_settings/edit.html.haml @@ -1,6 +1,6 @@ -- if @project.generated_yaml_config +- if @ci_project.generated_yaml_config %p.alert.alert-danger - CI Jobs are deprecated now, you can #{link_to "download", dumped_yaml_ci_project_path(@project)} + CI Jobs are deprecated now, you can #{link_to "download", dumped_yaml_ci_project_path(@ci_project)} or %a.preview-yml{:href => "#yaml-content", "data-toggle" => "modal"} preview yaml file which is based on your old jobs. @@ -8,7 +8,7 @@ = render 'form' -- if @project.generated_yaml_config +- if @ci_project.generated_yaml_config #yaml-content.modal.fade{"aria-hidden" => "true", "aria-labelledby" => ".gitlab-ci.yml", :role => "dialog", :tabindex => "-1"} .modal-dialog .modal-content @@ -16,6 +16,6 @@ %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} × %h4.modal-title Content of .gitlab-ci.yml .modal-body - = text_area_tag :yaml, @project.generated_yaml_config, size: "70x25", class: "form-control" + = text_area_tag :yaml, @ci_project.generated_yaml_config, size: "70x25", class: "form-control" .modal-footer %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index 2f24dc7c909..c5acafa2630 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -15,7 +15,12 @@ .files - diff_files.each_with_index do |diff_file, index| - = render 'projects/diffs/file', diff_file: diff_file, i: index, project: project + - diff_commit = commit_for_diff(diff_file.diff) + - blob = project.repository.blob_for_diff(diff_commit, diff_file.diff) + - next unless blob + + = render 'projects/diffs/file', i: index, project: project, + diff_file: diff_file, diff_commit: diff_commit, blob: blob - if @diff_timeout .alert.alert-danger diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index 99ee23a1ddc..4617b188150 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -1,24 +1,18 @@ -- blob = project.repository.blob_for_diff(@commit, diff_file.diff) -- return unless blob -- blob_diff_path = namespace_project_blob_diff_path(project.namespace, project, tree_join(@commit.id, diff_file.file_path)) -.diff-file{id: "diff-#{i}", data: {blob_diff_path: blob_diff_path }} +.diff-file{id: "diff-#{i}", data: diff_file_html_data(project, diff_commit, diff_file)} .diff-header{id: "file-path-#{hexdigest(diff_file.new_path || diff_file.old_path)}"} - - if diff_file.deleted_file - %span="#{diff_file.old_path} deleted" - - .diff-btn-group - - if @commit.parent_ids.present? - = view_file_btn(@commit.parent_id, diff_file, project) - - elsif diff_file.diff.submodule? + - if diff_file.diff.submodule? %span - submodule_item = project.repository.blob_at(@commit.id, diff_file.file_path) = submodule_link(submodule_item, @commit.id, project.repository) - else %span - - if diff_file.renamed_file + - if diff_file.deleted_file + = "#{diff_file.old_path} deleted" + - elsif diff_file.renamed_file = "#{diff_file.old_path} renamed to #{diff_file.new_path}" - else = diff_file.new_path + - if diff_file.mode_changed? %span.file-mode= "#{diff_file.diff.a_mode} → #{diff_file.diff.b_mode}" @@ -28,12 +22,12 @@ %i.fa.fa-comments - - if @merge_request && @merge_request.source_project + - if editable_diff?(diff_file) = edit_blob_link(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path, after: ' ', from_merge_request_id: @merge_request.id) - = view_file_btn(@commit.id, diff_file, project) + = view_file_btn(diff_commit.id, diff_file, project) .diff-content.diff-wrap-lines -# Skipp all non non-supported blobs diff --git a/app/views/ci/triggers/_trigger.html.haml b/app/views/projects/triggers/_trigger.html.haml index addfbfcb0d4..48b3b5c9920 100644 --- a/app/views/ci/triggers/_trigger.html.haml +++ b/app/views/projects/triggers/_trigger.html.haml @@ -11,4 +11,4 @@ %td .pull-right - = link_to 'Revoke', ci_project_trigger_path(@project, trigger), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-danger btn-sm btn-grouped" + = link_to 'Revoke', namespace_project_trigger_path(@project.namespace, @project, trigger), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-danger btn-sm btn-grouped" diff --git a/app/views/ci/triggers/index.html.haml b/app/views/projects/triggers/index.html.haml index 44374a1a4d5..17dcb78e256 100644 --- a/app/views/ci/triggers/index.html.haml +++ b/app/views/projects/triggers/index.html.haml @@ -12,11 +12,11 @@ %th Token %th Last used %th - = render @triggers + = render partial: 'trigger', collection: @triggers, as: :trigger - else %h4 No triggers -= form_for [:ci, @project, @trigger], html: { class: 'form-horizontal' } do |f| += form_for @trigger, url: url_for(controller: 'projects/triggers', action: 'create'), html: { class: 'form-horizontal' } do |f| .clearfix = f.submit "Add Trigger", class: 'btn btn-success pull-right' @@ -34,7 +34,7 @@ :plain curl -X POST \ -F token=TOKEN \ - #{ci_build_trigger_url(@project.id, 'REF_NAME')} + #{ci_build_trigger_url(@ci_project.id, 'REF_NAME')} %h3 Use .gitlab-ci.yml @@ -49,7 +49,7 @@ trigger: type: deploy script: - - "curl -X POST -F token=TOKEN #{ci_build_trigger_url(@project.id, 'REF_NAME')}" + - "curl -X POST -F token=TOKEN #{ci_build_trigger_url(@ci_project.id, 'REF_NAME')}" %h3 Pass build variables @@ -64,4 +64,4 @@ curl -X POST \ -F token=TOKEN \ -F "variables[RUN_NIGHTLY_BUILD]=true" \ - #{ci_build_trigger_url(@project.id, 'REF_NAME')} + #{ci_build_trigger_url(@ci_project.id, 'REF_NAME')} diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index 15930fc9079..c7174f86014 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -159,7 +159,7 @@ production: &base method: 'plain' # "tls" or "ssl" or "plain" bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' password: '_the_password_of_the_bind_user' - + # This setting specifies if LDAP server is Active Directory LDAP server. # For non AD servers it skips the AD specific queries. # If your LDAP server is not AD, set this to false. @@ -204,13 +204,13 @@ production: &base # The username will be used in paths for the user's own projects # (like `gitlab.example.com/username/project`) and when mentioning # them in issues, merge request and comments (like `@username`). - # If the attribute specified for `username` contains an email address, + # If the attribute specified for `username` contains an email address, # the GitLab username will be the part of the email address before the '@'. username: ['uid', 'userid', 'sAMAccountName'] email: ['mail', 'email', 'userPrincipalName'] # If no full name could be found at the attribute specified for `name`, - # the full name is determined using the attributes specified for + # the full name is determined using the attributes specified for # `first_name` and `last_name`. name: 'cn' first_name: 'givenName' @@ -252,28 +252,28 @@ production: &base # arguments, followed by optional 'args' which can be either a hash or an array. # Documentation for this is available at http://doc.gitlab.com/ce/integration/omniauth.html providers: - # - { name: 'google_oauth2', + # - { name: 'google_oauth2', # label: 'Google', - # app_id: 'YOUR_APP_ID', + # app_id: 'YOUR_APP_ID', # app_secret: 'YOUR_APP_SECRET', # args: { access_type: 'offline', approval_prompt: '' } } - # - { name: 'twitter', - # app_id: 'YOUR_APP_ID', + # - { name: 'twitter', + # app_id: 'YOUR_APP_ID', # app_secret: 'YOUR_APP_SECRET' } - # - { name: 'github', + # - { name: 'github', # label: 'GitHub', - # app_id: 'YOUR_APP_ID', + # app_id: 'YOUR_APP_ID', # app_secret: 'YOUR_APP_SECRET', # args: { scope: 'user:email' } } - # - { name: 'gitlab', + # - { name: 'gitlab', # label: 'GitLab.com', - # app_id: 'YOUR_APP_ID', + # app_id: 'YOUR_APP_ID', # app_secret: 'YOUR_APP_SECRET', # args: { scope: 'api' } } - # - { name: 'bitbucket', - # app_id: 'YOUR_APP_ID', + # - { name: 'bitbucket', + # app_id: 'YOUR_APP_ID', # app_secret: 'YOUR_APP_SECRET' } - # - { name: 'saml', + # - { name: 'saml', # label: 'Our SAML Provider', # args: { # assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback', @@ -319,6 +319,8 @@ production: &base # # Use multipart uploads when file size reaches 100MB, see # # http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html # multipart_chunk_size: 104857600 + # # Turns on AWS Server-Side Encryption with Amazon S3-Managed Keys for backups, this is optional + # # encryption: 'AES256' ## GitLab Shell settings gitlab_shell: diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 48601b67335..4e4a8ecbdb3 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -229,6 +229,7 @@ if Settings.backup['upload']['connection'] Settings.backup['upload']['connection'] = Hash[Settings.backup['upload']['connection'].map { |k, v| [k.to_sym, v] }] end Settings.backup['upload']['multipart_chunk_size'] ||= 104857600 +Settings.backup['upload']['encryption'] ||= nil # # Git diff --git a/config/routes.rb b/config/routes.rb index 776b606bf7d..6d96d8801cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,8 +53,6 @@ Gitlab::Application.routes.draw do end end - resources :triggers, only: [:index, :create, :destroy] - resources :runner_projects, only: [:create, :destroy] resources :events, only: [:index] @@ -591,6 +589,8 @@ Gitlab::Application.routes.draw do resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :protected_branches, only: [:index, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resource :variables, only: [:show, :update] + resources :triggers, only: [:index, :create, :destroy] + resource :ci_settings, only: [:edit, :update, :destroy] resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do member do diff --git a/db/migrate/20150924125150_add_project_id_to_ci_commit.rb b/db/migrate/20150924125150_add_project_id_to_ci_commit.rb new file mode 100644 index 00000000000..1a761fe0f86 --- /dev/null +++ b/db/migrate/20150924125150_add_project_id_to_ci_commit.rb @@ -0,0 +1,5 @@ +class AddProjectIdToCiCommit < ActiveRecord::Migration + def up + add_column :ci_commits, :gl_project_id, :integer + end +end diff --git a/db/migrate/20150924125436_migrate_project_id_for_ci_commits.rb b/db/migrate/20150924125436_migrate_project_id_for_ci_commits.rb new file mode 100644 index 00000000000..2be57b6062e --- /dev/null +++ b/db/migrate/20150924125436_migrate_project_id_for_ci_commits.rb @@ -0,0 +1,6 @@ +class MigrateProjectIdForCiCommits < ActiveRecord::Migration + def up + subquery = 'SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = ci_commits.project_id' + execute("UPDATE ci_commits SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") + end +end diff --git a/db/migrate/20150930095736_add_null_to_name_for_ci_projects.rb b/db/migrate/20150930095736_add_null_to_name_for_ci_projects.rb new file mode 100644 index 00000000000..a978fcda3ba --- /dev/null +++ b/db/migrate/20150930095736_add_null_to_name_for_ci_projects.rb @@ -0,0 +1,9 @@ +class ChangeNameOfCiProjects < ActiveRecord::Migration + def up + change_column_null :ci_projects, :name, true + end + + def down + change_column_null :ci_projects, :name, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 01ccda7a75e..4ce6cee86e5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150920161119) do +ActiveRecord::Schema.define(version: 20150930095736) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -115,9 +115,10 @@ ActiveRecord::Schema.define(version: 20150920161119) do t.text "push_data" t.datetime "created_at" t.datetime "updated_at" - t.boolean "tag", default: false + t.boolean "tag", default: false t.text "yaml_errors" t.datetime "committed_at" + t.integer "gl_project_id" end add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree @@ -157,7 +158,7 @@ ActiveRecord::Schema.define(version: 20150920161119) do add_index "ci_jobs", ["project_id"], name: "index_ci_jobs_on_project_id", using: :btree create_table "ci_projects", force: true do |t| - t.string "name", null: false + t.string "name" t.integer "timeout", default: 3600, null: false t.datetime "created_at" t.datetime "updated_at" diff --git a/doc/ci/api/projects.md b/doc/ci/api/projects.md index 54584db0938..5585191e826 100644 --- a/doc/ci/api/projects.md +++ b/doc/ci/api/projects.md @@ -100,8 +100,6 @@ Parameters: * `name` (required) - The name of the project * `gitlab_id` (required) - The ID of the project on the Gitlab instance - * `path` (required) - The gitlab project path - * `ssh_url_to_repo` (required) - The gitlab SSH url to the repo * `default_ref` (optional) - The branch to run on (default to `master`) ### Update Project @@ -114,9 +112,6 @@ authenticated user has access to. Parameters: * `name` - The name of the project - * `gitlab_id` - The ID of the project on the Gitlab instance - * `path` - The gitlab project path - * `ssh_url_to_repo` - The gitlab SSH url to the repo * `default_ref` - The branch to run on (default to `master`) ### Remove Project diff --git a/doc/migrate_ci_to_ce/README.md b/doc/migrate_ci_to_ce/README.md index 2725bf343ee..56bf7a14182 100644 --- a/doc/migrate_ci_to_ce/README.md +++ b/doc/migrate_ci_to_ce/README.md @@ -143,7 +143,7 @@ sudo gitlab-ctl stop ci-sidekiq # Source sudo service gitlab_ci stop cd /home/gitlab_ci/gitlab-ci -sudo -u gitlab_ci -H bundle exec whenever --clear-crontab +sudo -u gitlab_ci -H bundle exec whenever --clear-crontab RAILS_ENV=production ``` ### II. Moving data diff --git a/doc/raketasks/backup_restore.md b/doc/raketasks/backup_restore.md index 4ff5e74d438..b212964436f 100644 --- a/doc/raketasks/backup_restore.md +++ b/doc/raketasks/backup_restore.md @@ -95,6 +95,8 @@ For installations from source: aws_secret_access_key: 'secret123' # The remote 'directory' to store your backups. For S3, this would be the bucket name. remote_directory: 'my.s3.bucket' + # Turns on AWS Server-Side Encryption with Amazon S3-Managed Keys for backups, this is optional + # encryption: 'AES256' ``` If you are uploading your backups to S3 you will probably want to create a new diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature index 947f668e432..83055188bac 100644 --- a/features/project/merge_requests.feature +++ b/features/project/merge_requests.feature @@ -115,40 +115,40 @@ Feature: Project Merge Requests Given project "Shop" have "Bug NS-05" open merge request with diffs inside And I visit merge request page "Bug NS-05" And I click on the Changes tab - And I leave a comment like "Line is wrong" on line 39 of the second file - And I click link "Hide inline discussion" of the second file - Then I should not see a comment like "Line is wrong here" in the second file + And I leave a comment like "Line is wrong" on line 39 of the third file + And I click link "Hide inline discussion" of the third file + Then I should not see a comment like "Line is wrong here" in the third file @javascript Scenario: I show comments on a merge request diff with comments in a single file Given project "Shop" have "Bug NS-05" open merge request with diffs inside And I visit merge request page "Bug NS-05" And I click on the Changes tab - And I leave a comment like "Line is wrong" on line 39 of the second file - Then I should see a comment like "Line is wrong" in the second file + And I leave a comment like "Line is wrong" on line 39 of the third file + Then I should see a comment like "Line is wrong" in the third file @javascript Scenario: I hide comments on a merge request diff with comments in multiple files Given project "Shop" have "Bug NS-05" open merge request with diffs inside And I visit merge request page "Bug NS-05" And I click on the Changes tab - And I leave a comment like "Line is correct" on line 12 of the first file - And I leave a comment like "Line is wrong" on line 39 of the second file - And I click link "Hide inline discussion" of the second file - Then I should not see a comment like "Line is wrong here" in the second file - And I should still see a comment like "Line is correct" in the first file + And I leave a comment like "Line is correct" on line 12 of the second file + And I leave a comment like "Line is wrong" on line 39 of the third file + And I click link "Hide inline discussion" of the third file + Then I should not see a comment like "Line is wrong here" in the third file + And I should still see a comment like "Line is correct" in the second file @javascript Scenario: I show comments on a merge request diff with comments in multiple files Given project "Shop" have "Bug NS-05" open merge request with diffs inside And I visit merge request page "Bug NS-05" And I click on the Changes tab - And I leave a comment like "Line is correct" on line 12 of the first file - And I leave a comment like "Line is wrong" on line 39 of the second file - And I click link "Hide inline discussion" of the second file - And I click link "Show inline discussion" of the second file - Then I should see a comment like "Line is wrong" in the second file - And I should still see a comment like "Line is correct" in the first file + And I leave a comment like "Line is correct" on line 12 of the second file + And I leave a comment like "Line is wrong" on line 39 of the third file + And I click link "Hide inline discussion" of the third file + And I click link "Show inline discussion" of the third file + Then I should see a comment like "Line is wrong" in the third file + And I should still see a comment like "Line is correct" in the second file @javascript Scenario: I unfold diff @@ -163,8 +163,8 @@ Feature: Project Merge Requests Given project "Shop" have "Bug NS-05" open merge request with diffs inside And I visit merge request page "Bug NS-05" And I click on the Changes tab - And I leave a comment like "Line is correct" on line 12 of the first file - And I leave a comment like "Line is wrong" on line 39 of the second file + And I leave a comment like "Line is correct" on line 12 of the second file + And I leave a comment like "Line is wrong" on line 39 of the third file And I click Side-by-side Diff tab Then I should see comments on the side-by-side diff page diff --git a/features/steps/project/commits/commits.rb b/features/steps/project/commits/commits.rb index 56f1f06fb06..47f58091b93 100644 --- a/features/steps/project/commits/commits.rb +++ b/features/steps/project/commits/commits.rb @@ -104,7 +104,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps step 'commit has ci status' do @project.enable_ci(@user) - create :ci_commit, project: @project.gitlab_ci_project, sha: sample_commit.id + create :ci_commit, gl_project: @project, sha: sample_commit.id end step 'I see commit ci info' do diff --git a/features/steps/project/merge_requests.rb b/features/steps/project/merge_requests.rb index c92998631ff..875bf6c4676 100644 --- a/features/steps/project/merge_requests.rb +++ b/features/steps/project/merge_requests.rb @@ -224,43 +224,43 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps end end - step 'I click link "Hide inline discussion" of the second file' do - page.within '.files [id^=diff]:nth-child(2)' do + step 'I click link "Hide inline discussion" of the third file' do + page.within '.files [id^=diff]:nth-child(3)' do find('.js-toggle-diff-comments').trigger('click') end end - step 'I click link "Show inline discussion" of the second file' do - page.within '.files [id^=diff]:nth-child(2)' do + step 'I click link "Show inline discussion" of the third file' do + page.within '.files [id^=diff]:nth-child(3)' do find('.js-toggle-diff-comments').trigger('click') end end - step 'I should not see a comment like "Line is wrong" in the second file' do - page.within '.files [id^=diff]:nth-child(2)' do + step 'I should not see a comment like "Line is wrong" in the third file' do + page.within '.files [id^=diff]:nth-child(3)' do expect(page).not_to have_visible_content "Line is wrong" end end - step 'I should see a comment like "Line is wrong" in the second file' do - page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do + step 'I should see a comment like "Line is wrong" in the third file' do + page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do expect(page).to have_visible_content "Line is wrong" end end - step 'I should not see a comment like "Line is wrong here" in the second file' do - page.within '.files [id^=diff]:nth-child(2)' do + step 'I should not see a comment like "Line is wrong here" in the third file' do + page.within '.files [id^=diff]:nth-child(3)' do expect(page).not_to have_visible_content "Line is wrong here" end end - step 'I should see a comment like "Line is wrong here" in the second file' do - page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do + step 'I should see a comment like "Line is wrong here" in the third file' do + page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do expect(page).to have_visible_content "Line is wrong here" end end - step 'I leave a comment like "Line is correct" on line 12 of the first file' do + step 'I leave a comment like "Line is correct" on line 12 of the second file' do init_diff_note_first_file page.within(".js-discussion-note-form") do @@ -268,12 +268,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps click_button "Add Comment" end - page.within ".files [id^=diff]:nth-child(1) .note-body > .note-text" do + page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do expect(page).to have_content "Line is correct" end end - step 'I leave a comment like "Line is wrong" on line 39 of the second file' do + step 'I leave a comment like "Line is wrong" on line 39 of the third file' do init_diff_note_second_file page.within(".js-discussion-note-form") do @@ -282,8 +282,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps end end - step 'I should still see a comment like "Line is correct" in the first file' do - page.within '.files [id^=diff]:nth-child(1) .note-body > .note-text' do + step 'I should still see a comment like "Line is correct" in the second file' do + page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do expect(page).to have_visible_content "Line is correct" end end @@ -303,7 +303,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps end step 'I should see comments on the side-by-side diff page' do - page.within '.files [id^=diff]:nth-child(1) .parallel .note-body > .note-text' do + page.within '.files [id^=diff]:nth-child(2) .parallel .note-body > .note-text' do expect(page).to have_visible_content "Line is correct" end end diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index fa841f67510..fc51cec150e 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -204,6 +204,6 @@ module SharedProject step 'project "Shop" has CI build' do project = Project.find_by(name: "Shop") - create :ci_commit, project: project.gitlab_ci_project, sha: project.commit.sha + create :ci_commit, gl_project: project, sha: project.commit.sha end end diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb index ac63f89c6ec..5c42f25f4a2 100644 --- a/lib/backup/manager.rb +++ b/lib/backup/manager.rb @@ -45,7 +45,8 @@ module Backup directory = connection.directories.get(remote_directory) if directory.files.create(key: tar_file, body: File.open(tar_file), public: false, - multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size) + multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size, + encryption: Gitlab.config.backup.upload.encryption) $progress.puts "done".green else puts "uploading backup to #{remote_directory} failed".red @@ -55,7 +56,7 @@ module Backup def cleanup $progress.print "Deleting tmp directories ... " - + backup_contents.each do |dir| next unless File.exist?(File.join(Gitlab.config.backup.path, dir)) @@ -75,7 +76,7 @@ module Backup if keep_time > 0 removed = 0 - + Dir.chdir(Gitlab.config.backup.path) do file_list = Dir.glob('*_gitlab_backup.tar') file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } diff --git a/lib/ci/api/projects.rb b/lib/ci/api/projects.rb index 66bcf65e8c4..d719ad9e8d5 100644 --- a/lib/ci/api/projects.rb +++ b/lib/ci/api/projects.rb @@ -75,23 +75,17 @@ module Ci # Create Gitlab CI project using Gitlab project info # # Parameters: - # name (required) - The name of the project # gitlab_id (required) - The gitlab id of the project - # path (required) - The gitlab project path, ex. randx/six - # ssh_url_to_repo (required) - The gitlab ssh url to the repo # default_ref - The branch to run against (defaults to `master`) # Example Request: # POST /projects post do - required_attributes! [:name, :gitlab_id, :ssh_url_to_repo] + required_attributes! [:gitlab_id] filtered_params = { - name: params[:name], gitlab_id: params[:gitlab_id], # we accept gitlab_url for backward compatibility for a while (added to 7.11) - path: params[:path] || params[:gitlab_url].sub(/.*\/(.*\/.*)$/, '\1'), - default_ref: params[:default_ref] || 'master', - ssh_url_to_repo: params[:ssh_url_to_repo] + default_ref: params[:default_ref] || 'master' } project = Ci::Project.new(filtered_params) @@ -109,11 +103,7 @@ module Ci # # Parameters: # id (required) - The ID of a project - # name - The name of the project - # gitlab_id - The gitlab id of the project - # path - The gitlab project path, ex. randx/six - # ssh_url_to_repo - The gitlab ssh url to the repo - # default_ref - The branch to run against (defaults to `master`) + # default_ref - The branch to run against (defaults to `master`) # Example Request: # PUT /projects/:id put ":id" do @@ -121,12 +111,7 @@ module Ci unauthorized! unless can?(current_user, :admin_project, project.gl_project) - attrs = attributes_for_keys [:name, :gitlab_id, :path, :gitlab_url, :default_ref, :ssh_url_to_repo] - - # we accept gitlab_url for backward compatibility for a while (added to 7.11) - if attrs[:gitlab_url] && !attrs[:path] - attrs[:path] = attrs[:gitlab_url].sub(/.*\/(.*\/.*)$/, '\1') - end + attrs = attributes_for_keys [:default_ref] if project.update_attributes(attrs) present project, with: Entities::Project diff --git a/spec/controllers/ci/commits_controller_spec.rb b/spec/controllers/ci/commits_controller_spec.rb index b71e7505731..cc39ce7687c 100644 --- a/spec/controllers/ci/commits_controller_spec.rb +++ b/spec/controllers/ci/commits_controller_spec.rb @@ -1,14 +1,10 @@ require "spec_helper" describe Ci::CommitsController do - before do - @project = FactoryGirl.create :ci_project - end - describe "GET /status" do it "returns status of commit" do - commit = FactoryGirl.create :ci_commit, project: @project - get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id + commit = FactoryGirl.create :ci_commit + get :status, id: commit.sha, ref_id: commit.ref, project_id: commit.project.id expect(response).to be_success expect(response.code).to eq('200') @@ -16,8 +12,8 @@ describe Ci::CommitsController do end it "returns not_found status" do - commit = FactoryGirl.create :ci_commit, project: @project - get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id + commit = FactoryGirl.create :ci_commit + get :status, id: commit.sha, ref_id: "deploy", project_id: commit.project.id expect(response).to be_success expect(response.code).to eq('200') diff --git a/spec/factories/ci/commits.rb b/spec/factories/ci/commits.rb index 70930c789c3..9c7a0e9cbe0 100644 --- a/spec/factories/ci/commits.rb +++ b/spec/factories/ci/commits.rb @@ -51,6 +51,8 @@ FactoryGirl.define do } end + gl_project factory: :empty_project + factory :ci_commit_without_jobs do after(:create) do |commit, evaluator| commit.push_data[:ci_yaml_file] = YAML.dump({}) diff --git a/spec/factories/ci/projects.rb b/spec/factories/ci/projects.rb index e6bd0685f8d..111e1a82816 100644 --- a/spec/factories/ci/projects.rb +++ b/spec/factories/ci/projects.rb @@ -29,21 +29,9 @@ FactoryGirl.define do factory :ci_project_without_token, class: Ci::Project do - sequence :name do |n| - "GitLab / gitlab-shell#{n}" - end - default_ref 'master' - sequence :path do |n| - "gitlab/gitlab-shell#{n}" - end - - sequence :ssh_url_to_repo do |n| - "git@demo.gitlab.com:gitlab/gitlab-shell#{n}.git" - end - - gl_project factory: :project + gl_project factory: :empty_project factory :ci_project do token 'iPWx6WM4lhHNedGfBpPJNP' diff --git a/spec/features/ci/admin/builds_spec.rb b/spec/features/ci/admin/builds_spec.rb index 88ef9c144af..ee757206a03 100644 --- a/spec/features/ci/admin/builds_spec.rb +++ b/spec/features/ci/admin/builds_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' describe "Admin Builds" do - let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:commit) { FactoryGirl.create :ci_commit } let(:build) { FactoryGirl.create :ci_build, commit: commit } before do diff --git a/spec/features/ci/admin/runners_spec.rb b/spec/features/ci/admin/runners_spec.rb index b25121f0806..b83744f53a8 100644 --- a/spec/features/ci/admin/runners_spec.rb +++ b/spec/features/ci/admin/runners_spec.rb @@ -2,8 +2,7 @@ require 'spec_helper' describe "Admin Runners" do before do - skip_ci_admin_auth - login_as :user + login_as :admin end describe "Runners page" do @@ -20,16 +19,16 @@ describe "Admin Runners" do describe 'search' do before do - FactoryGirl.create :ci_runner, description: 'foo' - FactoryGirl.create :ci_runner, description: 'bar' + FactoryGirl.create :ci_runner, description: 'runner-foo' + FactoryGirl.create :ci_runner, description: 'runner-bar' search_form = find('#runners-search') - search_form.fill_in 'search', with: 'foo' + search_form.fill_in 'search', with: 'runner-foo' search_form.click_button 'Search' end - it { expect(page).to have_content("foo") } - it { expect(page).not_to have_content("bar") } + it { expect(page).to have_content("runner-foo") } + it { expect(page).not_to have_content("runner-bar") } end end @@ -37,8 +36,8 @@ describe "Admin Runners" do let(:runner) { FactoryGirl.create :ci_runner } before do - FactoryGirl.create(:ci_project, name: "foo") - FactoryGirl.create(:ci_project, name: "bar") + @project1 = FactoryGirl.create(:ci_project) + @project2 = FactoryGirl.create(:ci_project) visit ci_admin_runner_path(runner) end @@ -47,19 +46,19 @@ describe "Admin Runners" do end describe 'projects' do - it { expect(page).to have_content("foo") } - it { expect(page).to have_content("bar") } + it { expect(page).to have_content(@project1.name_with_namespace) } + it { expect(page).to have_content(@project2.name_with_namespace) } end describe 'search' do before do search_form = find('#runner-projects-search') - search_form.fill_in 'search', with: 'foo' + search_form.fill_in 'search', with: @project1.gl_project.name search_form.click_button 'Search' end - it { expect(page).to have_content("foo") } - it { expect(page).not_to have_content("bar") } + it { expect(page).to have_content(@project1.name_with_namespace) } + it { expect(page).not_to have_content(@project2.name_with_namespace) } end end end diff --git a/spec/features/ci/builds_spec.rb b/spec/features/ci/builds_spec.rb index 2f020e524e2..d65699dbefa 100644 --- a/spec/features/ci/builds_spec.rb +++ b/spec/features/ci/builds_spec.rb @@ -3,16 +3,15 @@ require 'spec_helper' describe "Builds" do context :private_project do before do - @project = FactoryGirl.create :ci_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit @build = FactoryGirl.create :ci_build, commit: @commit login_as :user - @project.gl_project.team << [@user, :master] + @commit.project.gl_project.team << [@user, :master] end describe "GET /:project/builds/:id" do before do - visit ci_project_build_path(@project, @build) + visit ci_project_build_path(@commit.project, @build) end it { expect(page).to have_content @commit.sha[0..7] } @@ -23,7 +22,7 @@ describe "Builds" do describe "GET /:project/builds/:id/cancel" do before do @build.run! - visit cancel_ci_project_build_path(@project, @build) + visit cancel_ci_project_build_path(@commit.project, @build) end it { expect(page).to have_content 'canceled' } @@ -33,7 +32,7 @@ describe "Builds" do describe "POST /:project/builds/:id/retry" do before do @build.cancel! - visit ci_project_build_path(@project, @build) + visit ci_project_build_path(@commit.project, @build) click_link 'Retry' end @@ -45,13 +44,15 @@ describe "Builds" do context :public_project do describe "Show page public accessible" do before do - @project = FactoryGirl.create :ci_public_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit + @commit.project.public = true + @commit.project.save + @runner = FactoryGirl.create :ci_specific_runner @build = FactoryGirl.create :ci_build, commit: @commit, runner: @runner stub_gitlab_calls - visit ci_project_build_path(@project, @build) + visit ci_project_build_path(@commit.project, @build) end it { expect(page).to have_content @commit.sha[0..7] } diff --git a/spec/features/ci/commits_spec.rb b/spec/features/ci/commits_spec.rb index 40a62ca4574..657a9dabe9e 100644 --- a/spec/features/ci/commits_spec.rb +++ b/spec/features/ci/commits_spec.rb @@ -5,11 +5,10 @@ describe "Commits" do context "Authenticated user" do before do - @project = FactoryGirl.create :ci_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit @build = FactoryGirl.create :ci_build, commit: @commit login_as :user - @project.gl_project.team << [@user, :master] + @commit.project.gl_project.team << [@user, :master] end describe "GET /:project/commits/:sha" do @@ -51,8 +50,10 @@ describe "Commits" do context "Public pages" do before do - @project = FactoryGirl.create :ci_public_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit + @commit.project.public = true + @commit.project.save + @build = FactoryGirl.create :ci_build, commit: @commit end diff --git a/spec/features/ci/projects_spec.rb b/spec/features/ci/projects_spec.rb index 7c8cd1ce5c7..c633acf85fb 100644 --- a/spec/features/ci/projects_spec.rb +++ b/spec/features/ci/projects_spec.rb @@ -17,22 +17,4 @@ describe "Projects" do it { expect(page).to have_content @project.name } it { expect(page).to have_content 'All commits' } end - - describe "GET /ci/projects/:id/edit" do - before do - visit edit_ci_project_path(@project) - end - - it { expect(page).to have_content @project.name } - it { expect(page).to have_content 'Build Schedule' } - - it "updates configuration" do - fill_in 'Timeout', with: '70' - click_button 'Save changes' - - expect(page).to have_content 'was successfully updated' - - expect(find_field('Timeout').value).to eq '70' - end - end end diff --git a/spec/features/ci_settings_spec.rb b/spec/features/ci_settings_spec.rb new file mode 100644 index 00000000000..7e25e883018 --- /dev/null +++ b/spec/features/ci_settings_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe "CI settings" do + let(:user) { create(:user) } + before { login_as(user) } + + before do + @project = FactoryGirl.create :ci_project + @gl_project = @project.gl_project + @gl_project.team << [user, :master] + visit edit_namespace_project_ci_settings_path(@gl_project.namespace, @gl_project) + end + + it { expect(page).to have_content 'Build Schedule' } + + it "updates configuration" do + fill_in 'Timeout', with: '70' + click_button 'Save changes' + expect(page).to have_content 'was successfully updated' + expect(find_field('Timeout').value).to eq '70' + end +end diff --git a/spec/features/ci/triggers_spec.rb b/spec/features/triggers_spec.rb index c6afeb74628..69492d58878 100644 --- a/spec/features/ci/triggers_spec.rb +++ b/spec/features/triggers_spec.rb @@ -1,13 +1,14 @@ require 'spec_helper' describe 'Triggers' do - let(:user) { create(:user) } + let(:user) { create(:user) } + before { login_as(user) } before do - login_as(user) @project = FactoryGirl.create :ci_project - @project.gl_project.team << [user, :master] - visit ci_project_triggers_path(@project) + @gl_project = @project.gl_project + @gl_project.team << [user, :master] + visit namespace_project_triggers_path(@gl_project.namespace, @gl_project) end context 'create a trigger' do diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/runners_helper_spec.rb index 6d0e2d3d1e1..b3d635a1932 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/runners_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Ci::RunnersHelper do +describe RunnersHelper do it "returns - not contacted yet" do runner = FactoryGirl.build :ci_runner expect(runner_status_icon(runner)).to include("not connected yet") diff --git a/spec/helpers/ci/application_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 6a216715b7f..3f62527c5bb 100644 --- a/spec/helpers/ci/application_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Ci::ApplicationHelper do +describe TimeHelper do describe "#duration_in_words" do it "returns minutes and seconds" do intervals_in_words = { diff --git a/spec/lib/ci/charts_spec.rb b/spec/lib/ci/charts_spec.rb index 24894e81983..83e2ad220b8 100644 --- a/spec/lib/ci/charts_spec.rb +++ b/spec/lib/ci/charts_spec.rb @@ -4,13 +4,12 @@ describe "Charts" do context "build_times" do before do - @project = FactoryGirl.create(:ci_project) - @commit = FactoryGirl.create(:ci_commit, project: @project) + @commit = FactoryGirl.create(:ci_commit) FactoryGirl.create(:ci_build, commit: @commit) end it 'should return build times in minutes' do - chart = Ci::Charts::BuildTime.new(@project) + chart = Ci::Charts::BuildTime.new(@commit.project) expect(chart.build_times).to eq([2]) end end diff --git a/spec/mailers/ci/notify_spec.rb b/spec/mailers/ci/notify_spec.rb index 20d8ddcd135..b83fb41603b 100644 --- a/spec/mailers/ci/notify_spec.rb +++ b/spec/mailers/ci/notify_spec.rb @@ -5,8 +5,7 @@ describe Ci::Notify do include EmailSpec::Matchers before do - @project = FactoryGirl.create :ci_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit @build = FactoryGirl.create :ci_build, commit: @commit end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ce801152042..82623bd8190 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -27,7 +27,8 @@ require 'spec_helper' describe Ci::Build do let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } + let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } let(:build) { FactoryGirl.create :ci_build, commit: commit } it { is_expected.to belong_to(:commit) } diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb index 586c9dc23a7..5429151c8d9 100644 --- a/spec/models/ci/commit_spec.rb +++ b/spec/models/ci/commit_spec.rb @@ -19,11 +19,12 @@ require 'spec_helper' describe Ci::Commit do let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } - let(:commit_with_project) { FactoryGirl.create :ci_commit, project: project } + let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } + let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let(:commit_with_project) { FactoryGirl.create :ci_commit, gl_project: gl_project } let(:config_processor) { Ci::GitlabCiYamlProcessor.new(gitlab_ci_yaml) } - it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:gl_project) } it { is_expected.to have_many(:builds) } it { is_expected.to validate_presence_of :before_sha } it { is_expected.to validate_presence_of :sha } @@ -65,7 +66,8 @@ describe Ci::Commit do project = FactoryGirl.create :ci_project, email_add_pusher: true, email_recipients: '' - commit = FactoryGirl.create :ci_commit, project: project + gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project + commit = FactoryGirl.create :ci_commit, gl_project: gl_project expected = 'commit_pusher_email' allow(commit).to receive(:push_data) { { user_email: expected } } expect(commit.project_recipients).to eq([expected]) @@ -75,7 +77,8 @@ describe Ci::Commit do project = FactoryGirl.create :ci_project, email_add_pusher: true, email_recipients: 'rec1 rec2' - commit = FactoryGirl.create :ci_commit, project: project + gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project + commit = FactoryGirl.create :ci_commit, gl_project: gl_project expected = 'commit_pusher_email' allow(commit).to receive(:push_data) { { user_email: expected } } expect(commit.project_recipients).to eq(['rec1', 'rec2', expected]) @@ -85,7 +88,8 @@ describe Ci::Commit do project = FactoryGirl.create :ci_project, email_add_pusher: false, email_recipients: 'rec1 rec2' - commit = FactoryGirl.create :ci_commit, project: project + gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project + commit = FactoryGirl.create :ci_commit, gl_project: gl_project expect(commit.project_recipients).to eq(['rec1', 'rec2']) end @@ -93,7 +97,8 @@ describe Ci::Commit do project = FactoryGirl.create :ci_project, email_add_pusher: true, email_recipients: 'rec1 rec1 rec2' - commit = FactoryGirl.create :ci_commit, project: project + gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project + commit = FactoryGirl.create :ci_commit, gl_project: gl_project expected = 'rec2' allow(commit).to receive(:push_data) { { user_email: expected } } expect(commit.project_recipients).to eq(['rec1', 'rec2']) @@ -219,8 +224,7 @@ describe Ci::Commit do end describe "#finished_at" do - let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:commit) { FactoryGirl.create :ci_commit } it "returns finished_at of latest build" do build = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 60 @@ -238,7 +242,8 @@ describe Ci::Commit do describe "coverage" do let(:project) { FactoryGirl.create :ci_project, coverage_regex: "/.*/" } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } + let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } it "calculates average when there are two builds with coverage" do FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit diff --git a/spec/models/ci/mail_service_spec.rb b/spec/models/ci/mail_service_spec.rb index b5f37b349db..0d9f85959ba 100644 --- a/spec/models/ci/mail_service_spec.rb +++ b/spec/models/ci/mail_service_spec.rb @@ -32,7 +32,8 @@ describe Ci::MailService do describe 'failed build' do let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true) } - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) } before do @@ -54,7 +55,8 @@ describe Ci::MailService do describe 'successfull build' do let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true, email_only_broken_builds: false) } - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } before do @@ -81,7 +83,8 @@ describe Ci::MailService do email_only_broken_builds: false, email_recipients: "jeroen@example.com") end - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } before do @@ -109,7 +112,8 @@ describe Ci::MailService do email_only_broken_builds: true, email_recipients: "jeroen@example.com") end - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } before do @@ -137,7 +141,8 @@ describe Ci::MailService do email_only_broken_builds: false, email_recipients: "jeroen@example.com") end - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } before do @@ -159,7 +164,8 @@ describe Ci::MailService do email_only_broken_builds: true, email_recipients: "jeroen@example.com") end - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) } before do diff --git a/spec/models/ci/project_services/hip_chat_message_spec.rb b/spec/models/ci/project_services/hip_chat_message_spec.rb index 49ac0860259..1903c036924 100644 --- a/spec/models/ci/project_services/hip_chat_message_spec.rb +++ b/spec/models/ci/project_services/hip_chat_message_spec.rb @@ -3,10 +3,8 @@ require 'spec_helper' describe Ci::HipChatMessage do subject { Ci::HipChatMessage.new(build) } - let(:project) { FactoryGirl.create(:ci_project) } - context "One build" do - let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) } + let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) } let(:build) do commit.create_builds @@ -37,7 +35,7 @@ describe Ci::HipChatMessage do end context "Several builds" do - let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) } + let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) } let(:build) do commit.builds.first diff --git a/spec/models/ci/project_services/hip_chat_service_spec.rb b/spec/models/ci/project_services/hip_chat_service_spec.rb index 063d46b84d4..d9ccc855edf 100644 --- a/spec/models/ci/project_services/hip_chat_service_spec.rb +++ b/spec/models/ci/project_services/hip_chat_service_spec.rb @@ -33,15 +33,14 @@ describe Ci::HipChatService do describe "Execute" do let(:service) { Ci::HipChatService.new } - let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:commit) { FactoryGirl.create :ci_commit } let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' } let(:api_url) { 'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6' } before do allow(service).to receive_messages( - project: project, - project_id: project.id, + project: commit.project, + project_id: commit.project_id, notify_only_broken_builds: false, hipchat_room: 123, hipchat_token: 'a1b2c3d4e5f6' diff --git a/spec/models/ci/project_services/slack_message_spec.rb b/spec/models/ci/project_services/slack_message_spec.rb index f5335903728..7b541802d7d 100644 --- a/spec/models/ci/project_services/slack_message_spec.rb +++ b/spec/models/ci/project_services/slack_message_spec.rb @@ -3,10 +3,8 @@ require 'spec_helper' describe Ci::SlackMessage do subject { Ci::SlackMessage.new(commit) } - let(:project) { FactoryGirl.create :ci_project } - context "One build" do - let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) } + let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) } let(:build) do commit.create_builds @@ -43,7 +41,7 @@ describe Ci::SlackMessage do end context "Several builds" do - let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) } + let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) } context 'when all matrix builds succeeded' do let(:color) { 'good' } diff --git a/spec/models/ci/project_services/slack_service_spec.rb b/spec/models/ci/project_services/slack_service_spec.rb index 0524f472432..1ac7dfe568d 100644 --- a/spec/models/ci/project_services/slack_service_spec.rb +++ b/spec/models/ci/project_services/slack_service_spec.rb @@ -31,16 +31,15 @@ describe Ci::SlackService do describe "Execute" do let(:slack) { Ci::SlackService.new } - let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:commit) { FactoryGirl.create :ci_commit } let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' } let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } let(:notify_only_broken_builds) { false } before do allow(slack).to receive_messages( - project: project, - project_id: project.id, + project: commit.project, + project_id: commit.project_id, webhook: webhook_url, notify_only_broken_builds: notify_only_broken_builds ) diff --git a/spec/models/ci/project_spec.rb b/spec/models/ci/project_spec.rb index 261ea69f5b4..dec4720a711 100644 --- a/spec/models/ci/project_spec.rb +++ b/spec/models/ci/project_spec.rb @@ -28,13 +28,20 @@ require 'spec_helper' describe Ci::Project do - subject { FactoryGirl.build :ci_project } + let(:gl_project) { FactoryGirl.create :empty_project } + let(:project) { FactoryGirl.create :ci_project, gl_project: gl_project } + subject { project } + + it { is_expected.to have_many(:runner_projects) } + it { is_expected.to have_many(:runners) } + it { is_expected.to have_many(:web_hooks) } + it { is_expected.to have_many(:events) } + it { is_expected.to have_many(:variables) } + it { is_expected.to have_many(:triggers) } + it { is_expected.to have_many(:services) } - it { is_expected.to have_many(:commits) } - - it { is_expected.to validate_presence_of :name } it { is_expected.to validate_presence_of :timeout } - it { is_expected.to validate_presence_of :default_ref } + it { is_expected.to validate_presence_of :gitlab_id } describe 'before_validation' do it 'should set an random token if none provided' do @@ -48,43 +55,107 @@ describe Ci::Project do end end + describe :name_with_namespace do + subject { project.name_with_namespace } + + it { is_expected.to eq(project.name) } + it { is_expected.to eq(gl_project.name_with_namespace) } + end + + describe :path_with_namespace do + subject { project.path_with_namespace } + + it { is_expected.to eq(project.path) } + it { is_expected.to eq(gl_project.path_with_namespace) } + end + + describe :path_with_namespace do + subject { project.web_url } + + it { is_expected.to eq(gl_project.web_url) } + end + + describe :web_url do + subject { project.web_url } + + it { is_expected.to eq(project.gitlab_url) } + it { is_expected.to eq(gl_project.web_url) } + end + + describe :http_url_to_repo do + subject { project.http_url_to_repo } + + it { is_expected.to eq(gl_project.http_url_to_repo) } + end + + describe :ssh_url_to_repo do + subject { project.ssh_url_to_repo } + + it { is_expected.to eq(gl_project.ssh_url_to_repo) } + end + + describe :commits do + subject { project.commits } + + before do + FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project + end + + it { is_expected.to eq(gl_project.ci_commits) } + end + + describe :builds do + subject { project.builds } + + before do + commit = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project + FactoryGirl.create :ci_build, commit: commit + end + + it { is_expected.to eq(gl_project.ci_builds) } + end + describe "ordered_by_last_commit_date" do it "returns ordered projects" do - newest_project = FactoryGirl.create :ci_project - oldest_project = FactoryGirl.create :ci_project - project_without_commits = FactoryGirl.create :ci_project + newest_project = FactoryGirl.create :empty_project + newest_ci_project = newest_project.ensure_gitlab_ci_project + oldest_project = FactoryGirl.create :empty_project + oldest_ci_project = oldest_project.ensure_gitlab_ci_project + project_without_commits = FactoryGirl.create :empty_project + ci_project_without_commits = project_without_commits.ensure_gitlab_ci_project - FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: newest_project - FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: oldest_project + FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: newest_project + FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: oldest_project - expect(Ci::Project.ordered_by_last_commit_date).to eq([newest_project, oldest_project, project_without_commits]) + expect(Ci::Project.ordered_by_last_commit_date).to eq([newest_ci_project, oldest_ci_project, ci_project_without_commits]) end end describe 'ordered commits' do - let(:project) { FactoryGirl.create :ci_project } + let(:project) { FactoryGirl.create :empty_project } it 'returns ordered list of commits' do - commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project - commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project - expect(project.commits).to eq([commit2, commit1]) + commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project + commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: project + expect(project.ci_commits).to eq([commit2, commit1]) end it 'returns commits ordered by committed_at and id, with nulls last' do - commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project - commit2 = FactoryGirl.create :ci_commit, committed_at: nil, project: project - commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project - commit4 = FactoryGirl.create :ci_commit, committed_at: nil, project: project - expect(project.commits).to eq([commit2, commit4, commit3, commit1]) + commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project + commit2 = FactoryGirl.create :ci_commit, committed_at: nil, gl_project: project + commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: project + commit4 = FactoryGirl.create :ci_commit, committed_at: nil, gl_project: project + expect(project.ci_commits).to eq([commit2, commit4, commit3, commit1]) end end context :valid_project do - let(:project) { FactoryGirl.create :ci_project } + let(:commit) { FactoryGirl.create(:ci_commit) } context :project_with_commit_and_builds do + let(:project) { commit.project } + before do - commit = FactoryGirl.create(:ci_commit, project: project) FactoryGirl.create(:ci_build, commit: commit) end @@ -165,13 +236,6 @@ describe Ci::Project do it { is_expected.to include(project.gitlab_url[7..-1]) } end - describe :search do - let!(:project) { FactoryGirl.create(:ci_project, name: "foo") } - - it { expect(Ci::Project.search('fo')).to include(project) } - it { expect(Ci::Project.search('bar')).to be_empty } - end - describe :any_runners do it "there are no runners available" do project = FactoryGirl.create(:ci_project) diff --git a/spec/models/ci/service_spec.rb b/spec/models/ci/service_spec.rb index 2c575056b08..2df70e88888 100644 --- a/spec/models/ci/service_spec.rb +++ b/spec/models/ci/service_spec.rb @@ -29,13 +29,12 @@ describe Ci::Service do end describe "Testable" do - let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:commit) { FactoryGirl.create :ci_commit } let(:build) { FactoryGirl.create :ci_build, commit: commit } before do allow(@service).to receive_messages( - project: project + project: commit.project ) build @testable = @service.can_test? diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9e7b6f5cb30..ba8897b95d9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -404,10 +404,12 @@ describe Project do describe :ci_commit do let(:project) { create :project } - let(:ci_project) { create :ci_project, gl_project: project } - let(:commit) { create :ci_commit, project: ci_project } + let(:commit) { create :ci_commit, gl_project: project } - before { project.create_gitlab_ci_service(active: true) } + before do + project.ensure_gitlab_ci_project + project.create_gitlab_ci_service(active: true) + end it { expect(project.ci_commit(commit.sha)).to eq(commit) } end diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb index c25d1823306..bad250fbf48 100644 --- a/spec/requests/ci/api/builds_spec.rb +++ b/spec/requests/ci/api/builds_spec.rb @@ -5,10 +5,12 @@ describe Ci::API::API do let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) } let(:project) { FactoryGirl.create(:ci_project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } describe "Builds API for runners" do let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") } let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") } + let(:shared_gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: shared_project) } before do FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id @@ -16,7 +18,7 @@ describe Ci::API::API do describe "POST /builds/register" do it "should start a build" do - commit = FactoryGirl.create(:ci_commit, project: project) + commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) commit.create_builds build = commit.builds.first @@ -34,7 +36,7 @@ describe Ci::API::API do end it "should return 404 error if no builds for specific runner" do - commit = FactoryGirl.create(:ci_commit, project: shared_project) + commit = FactoryGirl.create(:ci_commit, gl_project: shared_gl_project) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' ) post ci_api("/builds/register"), token: runner.token @@ -43,7 +45,7 @@ describe Ci::API::API do end it "should return 404 error if no builds for shared runner" do - commit = FactoryGirl.create(:ci_commit, project: project) + commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' ) post ci_api("/builds/register"), token: shared_runner.token @@ -52,7 +54,7 @@ describe Ci::API::API do end it "returns options" do - commit = FactoryGirl.create(:ci_commit, project: project) + commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) commit.create_builds post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } @@ -62,7 +64,7 @@ describe Ci::API::API do end it "returns variables" do - commit = FactoryGirl.create(:ci_commit, project: project) + commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) commit.create_builds project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") @@ -77,7 +79,7 @@ describe Ci::API::API do it "returns variables for triggers" do trigger = FactoryGirl.create(:ci_trigger, project: project) - commit = FactoryGirl.create(:ci_commit, project: project) + commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) commit.create_builds(trigger_request) @@ -95,7 +97,7 @@ describe Ci::API::API do end describe "PUT /builds/:id" do - let(:commit) { FactoryGirl.create(:ci_commit, project: project)} + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project)} let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) } it "should update a running build" do diff --git a/spec/requests/ci/api/commits_spec.rb b/spec/requests/ci/api/commits_spec.rb index e89b6651499..a41c321a300 100644 --- a/spec/requests/ci/api/commits_spec.rb +++ b/spec/requests/ci/api/commits_spec.rb @@ -4,7 +4,8 @@ describe Ci::API::API, 'Commits' do include ApiHelpers let(:project) { FactoryGirl.create(:ci_project) } - let(:commit) { FactoryGirl.create(:ci_commit, project: project) } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } let(:options) do { diff --git a/spec/requests/ci/api/projects_spec.rb b/spec/requests/ci/api/projects_spec.rb index 409f47fa448..53f7f91cc1f 100644 --- a/spec/requests/ci/api/projects_spec.rb +++ b/spec/requests/ci/api/projects_spec.rb @@ -134,7 +134,7 @@ describe Ci::API::API do describe "PUT /projects/:id" do let!(:project) { FactoryGirl.create(:ci_project) } - let!(:project_info) { { name: "An updated name!" } } + let!(:project_info) { { default_ref: "develop" } } before do options.merge!(project_info) @@ -144,7 +144,7 @@ describe Ci::API::API do project.gl_project.team << [user, :master] put ci_api("/projects/#{project.id}"), options expect(response.status).to eq(200) - expect(json_response["name"]).to eq(project_info[:name]) + expect(json_response["default_ref"]).to eq(project_info[:default_ref]) end it "fails to update a non-existing project" do @@ -181,12 +181,10 @@ describe Ci::API::API do end describe "POST /projects" do + let(:gl_project) { FactoryGirl.create :empty_project } let(:project_info) do { - name: "My project", - gitlab_id: 1, - path: "testing/testing", - ssh_url_to_repo: "ssh://example.com/testing/testing.git" + gitlab_id: gl_project.id } end @@ -200,7 +198,7 @@ describe Ci::API::API do 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(project_info[:name]) + expect(json_response['name']).to eq(gl_project.name_with_namespace) end end diff --git a/spec/requests/ci/api/triggers_spec.rb b/spec/requests/ci/api/triggers_spec.rb index ff6fdbdd6f1..bbe98e7dacd 100644 --- a/spec/requests/ci/api/triggers_spec.rb +++ b/spec/requests/ci/api/triggers_spec.rb @@ -6,6 +6,7 @@ describe Ci::API::API do describe 'POST /projects/:project_id/refs/:ref/trigger' do let!(:trigger_token) { 'secure token' } let!(:project) { FactoryGirl.create(:ci_project) } + let!(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } let!(:project2) { FactoryGirl.create(:ci_project) } let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) } let(:options) do @@ -33,7 +34,7 @@ describe Ci::API::API do context 'Have a commit' do before do - @commit = FactoryGirl.create(:ci_commit, project: project) + @commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) end it 'should create builds' do diff --git a/spec/requests/ci/builds_spec.rb b/spec/requests/ci/builds_spec.rb index 998c386ead4..f68116c52aa 100644 --- a/spec/requests/ci/builds_spec.rb +++ b/spec/requests/ci/builds_spec.rb @@ -2,14 +2,13 @@ require 'spec_helper' describe "Builds" do before do - @project = FactoryGirl.create :ci_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit @build = FactoryGirl.create :ci_build, commit: @commit end describe "GET /:project/builds/:id/status.json" do before do - get status_ci_project_build_path(@project, @build), format: :json + get status_ci_project_build_path(@commit.project, @build), format: :json end it { expect(response.status).to eq(200) } diff --git a/spec/requests/ci/commits_spec.rb b/spec/requests/ci/commits_spec.rb index fb317670339..3ab8c915dfd 100644 --- a/spec/requests/ci/commits_spec.rb +++ b/spec/requests/ci/commits_spec.rb @@ -2,13 +2,12 @@ require 'spec_helper' describe "Commits" do before do - @project = FactoryGirl.create :ci_project - @commit = FactoryGirl.create :ci_commit, project: @project + @commit = FactoryGirl.create :ci_commit end describe "GET /:project/refs/:ref_name/commits/:id/status.json" do before do - get status_ci_project_ref_commits_path(@project, @commit.ref, @commit.sha), format: :json + get status_ci_project_ref_commits_path(@commit.project, @commit.ref, @commit.sha), format: :json end it { expect(response.status).to eq(200) } diff --git a/spec/services/ci/create_trigger_request_service_spec.rb b/spec/services/ci/create_trigger_request_service_spec.rb index d12cd9773dc..525a24cc200 100644 --- a/spec/services/ci/create_trigger_request_service_spec.rb +++ b/spec/services/ci/create_trigger_request_service_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Ci::CreateTriggerRequestService do let(:service) { Ci::CreateTriggerRequestService.new } let(:project) { FactoryGirl.create :ci_project } + let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } let(:trigger) { FactoryGirl.create :ci_trigger, project: project } describe :execute do @@ -10,7 +11,7 @@ describe Ci::CreateTriggerRequestService do subject { service.execute(project, trigger, 'master') } before do - @commit = FactoryGirl.create :ci_commit, project: project + @commit = FactoryGirl.create :ci_commit, gl_project: gl_project end it { expect(subject).to be_kind_of(Ci::TriggerRequest) } @@ -27,7 +28,7 @@ describe Ci::CreateTriggerRequestService do subject { service.execute(project, trigger, 'master') } before do - FactoryGirl.create :ci_commit_without_jobs, project: project + FactoryGirl.create :ci_commit_without_jobs, gl_project: gl_project end it { expect(subject).to be_nil } @@ -37,9 +38,9 @@ describe Ci::CreateTriggerRequestService do subject { service.execute(project, trigger, 'master') } before do - @commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project - @commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project - @commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, project: project + @commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: gl_project + @commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project + @commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, gl_project: gl_project end context 'retries latest one' do diff --git a/spec/services/ci/event_service_spec.rb b/spec/services/ci/event_service_spec.rb index 9b330a90ae2..1264e17ff5e 100644 --- a/spec/services/ci/event_service_spec.rb +++ b/spec/services/ci/event_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Ci::EventService do - let(:project) { FactoryGirl.create :ci_project, name: "GitLab / gitlab-shell" } + let(:project) { FactoryGirl.create :ci_project } let(:user) { double(username: "root", id: 1) } before do @@ -12,7 +12,7 @@ describe Ci::EventService do it "creates event" do Ci::EventService.new.remove_project(user, project) - expect(Ci::Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been removed by root") + expect(Ci::Event.admin.last.description).to eq("Project \"#{project.name_with_namespace}\" has been removed by root") end end @@ -20,7 +20,7 @@ describe Ci::EventService do it "creates event" do Ci::EventService.new.create_project(user, project) - expect(Ci::Event.admin.last.description).to eq("Project \"GitLab / gitlab-shell\" has been created by root") + expect(Ci::Event.admin.last.description).to eq("Project \"#{project.name_with_namespace}\" has been created by root") end end diff --git a/spec/services/ci/image_for_build_service_spec.rb b/spec/services/ci/image_for_build_service_spec.rb index 7565eb8f032..d7242d684c6 100644 --- a/spec/services/ci/image_for_build_service_spec.rb +++ b/spec/services/ci/image_for_build_service_spec.rb @@ -4,7 +4,8 @@ module Ci describe ImageForBuildService do let(:service) { ImageForBuildService.new } let(:project) { FactoryGirl.create(:ci_project) } - let(:commit) { FactoryGirl.create(:ci_commit, project: project, ref: 'master') } + let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) } + let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project, ref: 'master') } let(:build) { FactoryGirl.create(:ci_build, commit: commit) } describe :execute do diff --git a/spec/services/ci/register_build_service_spec.rb b/spec/services/ci/register_build_service_spec.rb index 7b5af6c3dd0..781764627ac 100644 --- a/spec/services/ci/register_build_service_spec.rb +++ b/spec/services/ci/register_build_service_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' module Ci describe RegisterBuildService do let!(:service) { RegisterBuildService.new } - let!(:project) { FactoryGirl.create :ci_project } - let!(:commit) { FactoryGirl.create :ci_commit, project: project } - let!(:pending_build) { FactoryGirl.create :ci_build, project: project, commit: commit } + let!(:gl_project) { FactoryGirl.create :empty_project } + let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } before do - specific_runner.assign_to(project) + specific_runner.assign_to(gl_project.ensure_gitlab_ci_project) end describe :execute do @@ -47,8 +47,7 @@ module Ci context 'allow shared runners' do before do - project.shared_runners_enabled = true - project.save + gl_project.gitlab_ci_project.update(shared_runners_enabled: true) end context 'shared runner' do diff --git a/spec/services/ci/web_hook_service_spec.rb b/spec/services/ci/web_hook_service_spec.rb index cebdd145e40..aa48fcbcbfd 100644 --- a/spec/services/ci/web_hook_service_spec.rb +++ b/spec/services/ci/web_hook_service_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' describe Ci::WebHookService do let(:project) { FactoryGirl.create :ci_project } - let(:commit) { FactoryGirl.create :ci_commit, project: project } + let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } + let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:hook) { FactoryGirl.create :ci_web_hook, project: project } |