summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/build.rb31
-rw-r--r--app/models/commit.rb39
-rw-r--r--app/models/job.rb49
-rw-r--r--app/models/project.rb34
-rw-r--r--app/models/project_services/hip_chat_message.rb4
-rw-r--r--app/models/project_services/slack_message.rb2
6 files changed, 22 insertions, 137 deletions
diff --git a/app/models/build.rb b/app/models/build.rb
index c9f1230..7305b28 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -14,7 +14,6 @@
# commit_id :integer
# coverage :float
# commands :text
-# job_id :integer
#
class Build < ActiveRecord::Base
@@ -23,7 +22,6 @@ class Build < ActiveRecord::Base
belongs_to :commit
belongs_to :project
belongs_to :runner
- belongs_to :job, -> { with_deleted }
validates :commit, presence: true
validates :status, presence: true
@@ -64,15 +62,8 @@ class Build < ActiveRecord::Base
def retry(build)
new_build = Build.new(status: :pending)
-
- if build.job
- new_build.commands = build.job.commands
- new_build.tag_list = build.job.tag_list
- else
- new_build.commands = build.commands
- end
-
- new_build.job_id = build.job_id
+ 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.save
@@ -109,8 +100,8 @@ class Build < ActiveRecord::Base
WebHookService.new.build_end(build)
end
- if build.commit.success? && !(build.job && build.job.deploy?)
- build.commit.create_deploy_builds(build.ref)
+ if build.commit.success? && !build.deploy?
+ build.commit.create_deploy_builds
end
project.execute_services(build)
@@ -206,18 +197,4 @@ class Build < ActiveRecord::Base
# so we just silentrly ignore error for now
end
end
-
- def job_name
- if job
- job.name
- end
- end
-
- def for_tag?
- if job && job.build_tags
- true
- else
- false
- end
- end
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 6c876bd..3bc38b6 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -15,7 +15,6 @@
class Commit < ActiveRecord::Base
belongs_to :project
has_many :builds, dependent: :destroy
- has_many :jobs, through: :builds
serialize :push_data
@@ -93,31 +92,19 @@ class Commit < ActiveRecord::Base
end
def create_builds
- project.jobs.where(build_branches: true).active.parallel.map do |job|
- create_build_from_job(job)
- end
- end
-
- def create_builds_for_tag(ref = '')
- project.jobs.where(build_tags: true).active.parallel.map do |job|
- create_build_from_job(job, ref)
+ filter_param = tag? ? :tags : :branches
+ config_processor.builds.each do |build_attrs|
+ if build_attrs[filter_param]
+ builds.create!({ project: project }.merge(build_attrs.extract!(:name, :commands, :tag_list)))
+ end
end
end
- def create_build_from_job(job, ref = '')
- build = builds.new(commands: job.commands)
- build.tag_list = job.tag_list
- build.project_id = project_id
- build.job = job
- build.save
- build
- end
-
def builds_without_retry
@builds_without_retry ||=
begin
- grouped_builds = builds.group_by(&:job)
- grouped_builds.map do |job, builds|
+ grouped_builds = builds.group_by(&:name)
+ grouped_builds.map do |name, builds|
builds.sort_by(&:id).last
end
end
@@ -127,11 +114,9 @@ class Commit < ActiveRecord::Base
@retried_builds ||= (builds - builds_without_retry)
end
- def create_deploy_builds(ref)
- project.jobs.deploy.active.each do |job|
- if job.run_for_ref?(ref)
- create_build_from_job(job)
- end
+ def create_deploy_builds
+ config_processor.deploy_builds_for_ref(ref).each do |build_attrs|
+ builds.create!({ project: project }.merge(build_attrs))
end
end
@@ -194,4 +179,8 @@ class Commit < ActiveRecord::Base
def matrix?
builds_without_retry.size > 1
end
+
+ def config_processor
+ @config_processor ||= GitlabCiYamlProcessor.new(push_data[:ci_yaml_file])
+ end
end
diff --git a/app/models/job.rb b/app/models/job.rb
deleted file mode 100644
index 110c96d..0000000
--- a/app/models/job.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# == Schema Information
-#
-# Table name: jobs
-#
-# id :integer not null, primary key
-# project_id :integer not null
-# commands :text
-# active :boolean default(TRUE), not null
-# created_at :datetime
-# updated_at :datetime
-# name :string(255)
-# build_branches :boolean default(TRUE), not null
-# build_tags :boolean default(FALSE), not null
-# job_type :string(255) default("parallel")
-# refs :string(255)
-# deleted_at :datetime
-#
-
-class Job < ActiveRecord::Base
- acts_as_paranoid
-
- belongs_to :project
- has_many :builds
-
- acts_as_taggable
-
- scope :active, ->() { where(active: true) }
- scope :archived, ->() { where(active: false) }
- scope :parallel, ->(){ where(job_type: "parallel") }
- scope :deploy, ->(){ where(job_type: "deploy") }
-
- validate :refs, length: { maximum: 255 }
-
- def deploy?
- job_type == "deploy"
- end
-
- def run_for_ref?(ref)
- if refs.present?
- refs.split(",").map(&:strip).each do |refs_val|
- return true if File.fnmatch(refs_val, ref)
- end
-
- false
- else
- true
- end
- end
-end
diff --git a/app/models/project.rb b/app/models/project.rb
index a1e1999..7aceeca 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -32,7 +32,6 @@ class Project < ActiveRecord::Base
has_many :runner_projects, dependent: :destroy
has_many :runners, through: :runner_projects
has_many :web_hooks, dependent: :destroy
- has_many :jobs, dependent: :destroy
has_many :events, dependent: :destroy
# Project services
@@ -41,8 +40,6 @@ class Project < ActiveRecord::Base
has_one :slack_service, dependent: :destroy
has_one :mail_service, dependent: :destroy
- accepts_nested_attributes_for :jobs, allow_destroy: true
-
#
# Validations
#
@@ -55,8 +52,6 @@ class Project < ActiveRecord::Base
presence: true,
if: ->(project) { project.always_build.present? }
- validate :validate_jobs
-
scope :public_only, ->() { where(public: true) }
before_validation :set_default_values
@@ -165,39 +160,10 @@ ls -la
self.timeout = value.to_i * 60
end
- def skip_ref?(ref_name)
- if skip_refs.present?
- skip_refs.delete(" ").split(",").each do |ref|
- return true if File.fnmatch(ref, ref_name)
- end
-
- false
- else
- false
- end
- end
-
- def create_commit_for_tag?(tag)
- jobs.where(build_tags: true).active.parallel.any? ||
- jobs.active.deploy.any?{ |job| job.run_for_ref?(tag)}
- end
-
def coverage_enabled?
coverage_regex.present?
end
- def build_default_job
- jobs.build(commands: Project.base_build_script)
- end
-
- def validate_jobs
- remaining_jobs = jobs.reject(&:marked_for_destruction?)
-
- if remaining_jobs.empty?
- errors.add(:jobs, "At least one foo")
- end
- end
-
# Build a clone-able repo url
# using http and basic auth
def repo_url_with_auth
diff --git a/app/models/project_services/hip_chat_message.rb b/app/models/project_services/hip_chat_message.rb
index a5e4aee..db0d58e 100644
--- a/app/models/project_services/hip_chat_message.rb
+++ b/app/models/project_services/hip_chat_message.rb
@@ -8,12 +8,14 @@ class HipChatMessage
def to_s
lines = Array.new
lines.push("<a href=\"#{RoutesHelper.project_url(project)}\">#{project.name}</a> - ")
+
if commit.matrix?
lines.push("<a href=\"#{RoutesHelper.project_ref_commit_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
else
first_build = commit.builds_without_retry.first
- lines.push("<a href=\"#{RoutesHelper.project_build_url(project, first_build)}\">Build '#{first_build.job_name}' ##{first_build.id}</a></br>")
+ lines.push("<a href=\"#{RoutesHelper.project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>")
end
+
lines.push("#{commit.short_sha} #{commit.git_author_name} - #{commit.git_commit_message}</br>")
lines.push("#{humanized_status(commit_status)} in #{commit.duration} second(s).")
lines.join('')
diff --git a/app/models/project_services/slack_message.rb b/app/models/project_services/slack_message.rb
index c95499e..15d6ee3 100644
--- a/app/models/project_services/slack_message.rb
+++ b/app/models/project_services/slack_message.rb
@@ -24,7 +24,7 @@ class SlackMessage
commit.builds_without_retry.each do |build|
next unless build.failed?
fields << {
- title: build.job_name,
+ title: build.name,
value: "Build <#{RoutesHelper.project_build_url(project, build)}|\##{build.id}> failed in #{build.duration.to_i} second(s)."
}
end