Commit 64bfd9d7 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Remove ci_ prefix from all ci related things

parent 059c2c541d4c
......@@ -38,7 +38,7 @@ class Runners < Grape::API
)
elsif project = Project.find_by(runners_token: params[:token])
# Create a specific runner for project.
project.ci_runners.create(
project.runners.create(
description: params[:description],
tag_list: params[:tag_list]
)
......
......@@ -16,10 +16,10 @@ def initialize(project)
def push(from, to, format)
@labels << from.strftime(format)
@total << project.ci_builds.
@total << project.builds.
where("? > #{Ci::Build.table_name}.created_at AND #{Ci::Build.table_name}.created_at > ?", to, from).
count(:all)
@success << project.ci_builds.
@success << project.builds.
where("? > #{Ci::Build.table_name}.created_at AND #{Ci::Build.table_name}.created_at > ?", to, from).
success.count(:all)
end
......
......@@ -37,7 +37,7 @@
context "All builds" do
before do
@project.ci_builds.running_or_pending.each(&:success)
@project.builds.running_or_pending.each(&:success)
visit namespace_project_builds_path(@project.namespace, @project, scope: :all)
end
......
......@@ -21,9 +21,9 @@
@specific_runner = FactoryGirl.create :ci_specific_runner
@specific_runner2 = FactoryGirl.create :ci_specific_runner
@specific_runner3 = FactoryGirl.create :ci_specific_runner
@project.ci_runners << @specific_runner
@project2.ci_runners << @specific_runner2
@project3.ci_runners << @specific_runner3
@project.runners << @specific_runner
@project2.runners << @specific_runner2
@project3.runners << @specific_runner3
visit runners_path(@project)
end
......@@ -48,7 +48,7 @@
end
it "disables specific runner for project" do
@project2.ci_runners << @specific_runner
@project2.runners << @specific_runner
visit runners_path(@project)
within ".activated-specific-runners" do
......@@ -85,7 +85,7 @@
@project = FactoryGirl.create :empty_project
@project.team << [user, :master]
@specific_runner = FactoryGirl.create :ci_specific_runner
@project.ci_runners << @specific_runner
@project.runners << @specific_runner
end
it "shows runner information" do
......
......@@ -13,16 +13,16 @@
context 'create a trigger' do
before do
click_on 'Add Trigger'
expect(@project.ci_triggers.count).to eq(1)
expect(@project.triggers.count).to eq(1)
end
it 'contains trigger token' do
expect(page).to have_content(@project.ci_triggers.first.token)
expect(page).to have_content(@project.triggers.first.token)
end
it 'revokes the trigger' do
click_on 'Revoke'
expect(@project.ci_triggers.count).to eq(0)
expect(@project.triggers.count).to eq(0)
end
end
end
......@@ -18,7 +18,7 @@
click_on "Save changes"
expect(page).to have_content("Variables were successfully updated.")
expect(@project.ci_variables.count).to eq(1)
expect(@project.variables.count).to eq(1)
end
end
end
......@@ -232,7 +232,7 @@
end
before do
build.project.ci_variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value')
build.project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value')
end
it { is_expected.to eq(predefined_variables + yaml_variables + secure_variables) }
......@@ -264,7 +264,7 @@
describe :can_be_served? do
let(:runner) { FactoryGirl.create :ci_specific_runner }
before { build.project.ci_runners << runner }
before { build.project.runners << runner }
context 'runner without tags' do
it 'can handle builds without tags' do
......@@ -307,7 +307,7 @@
let(:runner) { FactoryGirl.create :ci_specific_runner }
before do
build.project.ci_runners << runner
build.project.runners << runner
runner.update_attributes(contacted_at: 1.second.ago)
end
......@@ -344,7 +344,7 @@
let(:runner) { FactoryGirl.create :ci_specific_runner, contacted_at: 1.second.ago }
before do
build.project.ci_runners << runner
build.project.runners << runner
runner.save
end
......
......@@ -118,8 +118,8 @@
runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:empty_project)
project1 = FactoryGirl.create(:empty_project)
project.ci_runners << runner
project1.ci_runners << runner
project.runners << runner
project1.runners << runner
expect(runner.belongs_to_one_project?).to be_falsey
end
......@@ -127,7 +127,7 @@
it "returns true" do
runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:empty_project)
project.ci_runners << runner
project.runners << runner
expect(runner.belongs_to_one_project?).to be_truthy
end
......
......@@ -54,13 +54,13 @@
it { is_expected.to have_one(:slack_service).dependent(:destroy) }
it { is_expected.to have_one(:pushover_service).dependent(:destroy) }
it { is_expected.to have_one(:asana_service).dependent(:destroy) }
it { is_expected.to have_many(:ci_commits) }
it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_builds) }
it { is_expected.to have_many(:ci_runner_projects) }
it { is_expected.to have_many(:ci_runners) }
it { is_expected.to have_many(:ci_variables) }
it { is_expected.to have_many(:ci_triggers) }
it { is_expected.to have_many(:ci_commits) }
it { is_expected.to have_many(:builds) }
it { is_expected.to have_many(:runner_projects) }
it { is_expected.to have_many(:runners) }
it { is_expected.to have_many(:variables) }
it { is_expected.to have_many(:triggers) }
end
describe 'modules' do
......@@ -519,7 +519,7 @@
end
it 'there is a specific runner' do
project.ci_runners << specific_runner
project.runners << specific_runner
expect(project.any_runners?).to be_truthy
end
......@@ -529,7 +529,7 @@
end
it 'checks the presence of specific runner' do
project.ci_runners << specific_runner
project.runners << specific_runner
expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy
end
end
......
......@@ -68,7 +68,7 @@
it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds('master', false, nil)
project.ci_variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......@@ -87,7 +87,7 @@
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds('master', false, nil, trigger_request)
project.ci_variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......
......@@ -34,7 +34,7 @@
before { post ci_api("/runners/register"), token: project.token }
it { expect(response.status).to eq(201) }
it { expect(project.ci_runners.size).to eq(1) }
it { expect(project.runners.size).to eq(1) }
end
it "should return 403 error if token is invalid" do
......
require 'spec_helper'
module Ci
describe CreateCommitService, services: true do
let(:service) { CreateCommitService.new }
let(:project) { FactoryGirl.create(:empty_project) }
let(:user) { nil }
before do
stub_ci_commit_to_return_yaml_file
end
describe :execute do
context 'valid params' do
let(:commit) do
service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: [ { message: "Message" } ]
)
end
it { expect(commit).to be_kind_of(Commit) }
it { expect(commit).to be_valid }
it { expect(commit).to be_persisted }
it { expect(commit).to eq(project.ci_commits.last) }
it { expect(commit.builds.first).to be_kind_of(Build) }
end
context "skip tag if there is no build for it" do
it "creates commit if there is appropriate job" do
result = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: [ { message: "Message" } ]
)
expect(result).to be_persisted
end
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
config = YAML.dump({ deploy: { deploy: "ls", only: ["0_1"] } })
stub_ci_commit_yaml_file(config)
result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
commits: [ { message: "Message" } ]
)
expect(result).to be_persisted
end
end
it 'skips commits without .gitlab-ci.yml' do
stub_ci_commit_yaml_file(nil)
result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
commits: [ { message: 'Message' } ]
)
expect(result).to be_persisted
expect(result.builds.any?).to be_falsey
expect(result.status).to eq('skipped')
expect(result.yaml_errors).to be_nil
end
it 'skips commits if yaml is invalid' do
message = 'message'
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
stub_ci_commit_yaml_file('invalid: file: file')
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq('failed')
expect(commit.yaml_errors).to_not be_nil
end
describe :ci_skip? do
let(:message) { "some message[ci skip]" }
before do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
end
it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
end
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { "some message" }
commits = [{ message: "some message" }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.first.name).to eq("staging")
end
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file: fiile')
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil
end
end
it "skips build creation if there are already builds" do
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { gitlab_ci_yaml }
commits = [{ message: "message" }]
commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.count(:all)).to eq(2)
commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.count(:all)).to eq(2)
end
it "creates commit with failed status if yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file')
commits = [{ message: "some message" }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.status).to eq("failed")
expect(commit.builds.any?).to be false
end
end
end
end
require 'spec_helper'
describe CreateCommitBuildsService, services: true do
let(:service) { CreateCommitBuildsService.new }
let(:project) { FactoryGirl.create(:empty_project) }
let(:user) { nil }
before do
stub_ci_commit_to_return_yaml_file
end
describe :execute do
context 'valid params' do
let(:commit) do
service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: [{ message: "Message" }]
)
end
it { expect(commit).to be_kind_of(Commit) }
it { expect(commit).to be_valid }
it { expect(commit).to be_persisted }
it { expect(commit).to eq(project.ci_commits.last) }
it { expect(commit.builds.first).to be_kind_of(Build) }
end
context "skip tag if there is no build for it" do
it "creates commit if there is appropriate job" do
result = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: [{ message: "Message" }]
)
expect(result).to be_persisted
end
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
config = YAML.dump({ deploy: { deploy: "ls", only: ["0_1"] } })
stub_ci_commit_yaml_file(config)
result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
commits: [{ message: "Message" }]
)
expect(result).to be_persisted
end
end
it 'skips commits without .gitlab-ci.yml' do
stub_ci_commit_yaml_file(nil)
result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
commits: [{ message: 'Message' }]
)
expect(result).to be_persisted
expect(result.builds.any?).to be_falsey
expect(result.status).to eq('skipped')
expect(result.yaml_errors).to be_nil
end
it 'skips commits if yaml is invalid' do
message = 'message'
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
stub_ci_commit_yaml_file('invalid: file: file')
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq('failed')
expect(commit.yaml_errors).to_not be_nil
end
describe :ci_skip? do
let(:message) { "some message[ci skip]" }
before do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
end
it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
end
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { "some message" }
commits = [{ message: "some message" }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.first.name).to eq("staging")
end
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file: fiile')
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil
end
end
it "skips build creation if there are already builds" do
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { gitlab_ci_yaml }
commits = [{ message: "message" }]
commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.count(:all)).to eq(2)
commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.count(:all)).to eq(2)
end
it "creates commit with failed status if yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file')
commits = [{ message: "some message" }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.status).to eq("failed")
expect(commit.builds.any?).to be false
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment