summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-10 22:33:39 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-10 22:33:39 -0800
commit7a0937fc5952cc6849fc14829d5686e8b8bf9dd0 (patch)
tree3f50681201f7c5582170fec4bb5c15834aa8f11f
parent627281639ae2749dbd4aad4d7c9930591399ef2a (diff)
downloadgitlab-ci-7a0937fc5952cc6849fc14829d5686e8b8bf9dd0.tar.gz
Job can serve branches or tags or both
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/commit.rb11
-rw-r--r--app/services/create_commit_service.rb16
-rw-r--r--app/views/projects/_form.html.haml9
-rw-r--r--db/migrate/20150111062026_add_filter_to_jobs.rb6
-rw-r--r--db/schema.rb8
6 files changed, 43 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e825c1a..cf3e2df 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ v5.4
- Remove progress output from schedule_builds cron job
- Fix schedule_builds rake task
- Fix test webhook button
+ - Job can be branch specific or tag specifi or both
v5.3
- Remove annoying 'Done' message from schedule_builds cron job
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 0e10033..13630bc 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -97,7 +97,16 @@ class Commit < ActiveRecord::Base
end
def create_builds
- project.jobs.active.map do |job|
+ project.jobs.where(build_branches: true).active.map do |job|
+ build = builds.new(commands: job.commands)
+ build.job = job
+ build.save
+ build
+ end
+ end
+
+ def create_builds_for_tag
+ project.jobs.where(build_tags: true).active.map do |job|
build = builds.new(commands: job.commands)
build.job = job
build.save
diff --git a/app/services/create_commit_service.rb b/app/services/create_commit_service.rb
index 64d86d3..879c1ad 100644
--- a/app/services/create_commit_service.rb
+++ b/app/services/create_commit_service.rb
@@ -2,12 +2,14 @@ class CreateCommitService
def execute(project, params)
before_sha = params[:before]
sha = params[:after]
- ref = params[:ref]
+ origin_ref = params[:ref]
- if ref && ref.include?('refs/heads/')
- ref = ref.scan(/heads\/(.*)$/).flatten[0]
+ unless origin_ref && sha
+ return false
end
+ ref = origin_ref.gsub(/\Arefs\/(tags|heads)\//, '')
+
# Skip branch removal
if sha == Git::BLANK_SHA
return false
@@ -38,7 +40,13 @@ class CreateCommitService
}
commit = project.commits.create(data)
- commit.create_builds
+
+ if origin_ref.start_with?('refs/tags/')
+ commit.create_builds_for_tag
+ else
+ commit.create_builds
+ end
+
commit
end
diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml
index da63494..f0181bb 100644
--- a/app/views/projects/_form.html.haml
+++ b/app/views/projects/_form.html.haml
@@ -15,6 +15,15 @@
.col-sm-10
= job_form.text_field :name, class: 'form-control', placeholder: "Ex. cucumber"
.form-group
+ .col-sm-2
+ .col-sm-10
+ .checkbox
+ = f.label :build_branches, 'Build branches', class: ''
+ = job_form.check_box :build_branches
+ .checkbox
+ = f.label :build_tags, 'Build tags', class: ''
+ = job_form.check_box :build_tags
+ .form-group
= f.label :commands, 'Build steps', class: 'control-label'
.col-sm-10
= job_form.text_area :commands, class: 'form-control', rows: 14, placeholder: "bundle exec rake spec"
diff --git a/db/migrate/20150111062026_add_filter_to_jobs.rb b/db/migrate/20150111062026_add_filter_to_jobs.rb
new file mode 100644
index 0000000..90e422d
--- /dev/null
+++ b/db/migrate/20150111062026_add_filter_to_jobs.rb
@@ -0,0 +1,6 @@
+class AddFilterToJobs < ActiveRecord::Migration
+ def change
+ add_column :jobs, :build_branches, :boolean, default: true, null: false
+ add_column :jobs, :build_tags, :boolean, default: false, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2993509..3a95481 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: 20141201153755) do
+ActiveRecord::Schema.define(version: 20150111062026) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -58,12 +58,14 @@ ActiveRecord::Schema.define(version: 20141201153755) do
add_index "commits", ["sha"], name: "index_commits_on_sha", using: :btree
create_table "jobs", force: true do |t|
- t.integer "project_id", null: false
+ t.integer "project_id", null: false
t.text "commands"
- t.boolean "active", default: true, null: false
+ t.boolean "active", default: true, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
+ t.boolean "build_branches", default: true, null: false
+ t.boolean "build_tags", default: false, null: false
end
add_index "jobs", ["project_id"], name: "index_jobs_on_project_id", using: :btree