summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-12 16:46:44 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-12 16:46:44 -0800
commitdc95ddbea2840de800f5bd2e93de993a335db476 (patch)
tree7c0317df5e9980b1485b90ab0a30b8a5a2c41f04
parentc8ada3322b211d13fb26adb2ceac054aced5ee6f (diff)
downloadgitlab-ci-dc95ddbea2840de800f5bd2e93de993a335db476.tar.gz
Add tags to jobs and runners
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock3
-rw-r--r--app/models/job.rb2
-rw-r--r--app/models/runner.rb4
-rw-r--r--app/views/jobs/_edit.html.haml48
-rw-r--r--app/views/jobs/_list.html.haml19
-rw-r--r--app/views/jobs/index.html.haml50
-rw-r--r--app/views/runners/_runner.html.haml4
-rw-r--r--app/views/runners/edit.html.haml9
-rw-r--r--app/views/runners/index.html.haml1
-rw-r--r--db/migrate/20150113001832_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb31
-rw-r--r--db/migrate/20150113001833_add_missing_unique_indices.acts_as_taggable_on_engine.rb20
-rw-r--r--db/migrate/20150113001834_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb15
-rw-r--r--db/migrate/20150113001835_add_missing_taggable_index.acts_as_taggable_on_engine.rb10
-rw-r--r--db/schema.rb22
15 files changed, 197 insertions, 44 deletions
diff --git a/Gemfile b/Gemfile
index bc5dff2..c60f7f0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,6 +14,9 @@ gem 'activerecord-deprecated_finders'
gem 'activerecord-session_store'
gem "nested_form"
+# tag runners
+gem 'acts-as-taggable-on', '~> 3.4'
+
# DB
gem 'mysql2', group: :mysql
gem 'pg', group: :postgres
diff --git a/Gemfile.lock b/Gemfile.lock
index ff43d0b..ef577b3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -29,6 +29,8 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
+ acts-as-taggable-on (3.4.3)
+ activerecord (>= 3.2, < 5)
addressable (2.3.5)
annotate (2.6.0)
activerecord (>= 2.3.0)
@@ -311,6 +313,7 @@ PLATFORMS
DEPENDENCIES
activerecord-deprecated_finders
activerecord-session_store
+ acts-as-taggable-on (~> 3.4)
annotate
bootstrap-sass (~> 3.0)
capybara
diff --git a/app/models/job.rb b/app/models/job.rb
index 057702f..c21fce7 100644
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -17,6 +17,8 @@ class Job < ActiveRecord::Base
belongs_to :project
has_many :builds
+ acts_as_taggable
+
scope :active, ->() { where(active: true) }
scope :archived, ->() { where(active: false) }
end
diff --git a/app/models/runner.rb b/app/models/runner.rb
index d252a39..582407a 100644
--- a/app/models/runner.rb
+++ b/app/models/runner.rb
@@ -16,13 +16,15 @@ class Runner < ActiveRecord::Base
has_one :last_build, ->() { order('id DESC') }, class_name: 'Build'
- attr_accessible :token, :description
+ attr_accessible :token, :description, :tag_list
before_validation :set_default_values
scope :specific, ->() { where(id: RunnerProject.select(:runner_id)) }
scope :shared, ->() { where.not(id: RunnerProject.select(:runner_id)) }
+ acts_as_taggable
+
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
end
diff --git a/app/views/jobs/_edit.html.haml b/app/views/jobs/_edit.html.haml
new file mode 100644
index 0000000..533471a
--- /dev/null
+++ b/app/views/jobs/_edit.html.haml
@@ -0,0 +1,48 @@
+= nested_form_for @project, html: { class: 'form-horizontal' } do |f|
+ - if @project.errors.any?
+ #error_explanation
+ %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:"
+ .alert.alert-error
+ %ul
+ - @project.errors.full_messages.each do |msg|
+ %li= msg
+
+ = f.fields_for :jobs do |job_form|
+ .form-group
+ = f.label :name, 'Name', class: 'control-label'
+ .col-sm-10
+ = job_form.text_field :name, class: 'form-control', placeholder: "Ex. cucumber"
+ .form-group
+ = f.label :build_branches, 'Events', class: 'control-label'
+ .col-sm-10
+ .checkbox
+ = f.label :build_branches, 'Push a new commit', class: ''
+ = job_form.check_box :build_branches
+ .checkbox
+ = f.label :build_tags, 'Push a new tag', class: ''
+ = job_form.check_box :build_tags
+ .form-group
+ = label_tag :tag_list, class: 'control-label' do
+ Tags
+ .col-sm-10
+ = job_form.text_field :tag_list, class: 'form-control'
+ .help-block
+ You can setup jobs to only use runners with specific tags.
+ Leave blank if you want this job to use any runner
+
+ .form-group
+ = f.label :commands, 'Script', class: 'control-label'
+ .col-sm-10
+ = job_form.text_area :commands, class: 'form-control', rows: 10, placeholder: "bundle exec rake spec"
+ %p.light
+ All lines will be concatenated in one file and executed.
+ %br
+ If you change the working directory or the environment in one line - it will affect the next lines too
+ = job_form.link_to_remove "Remove this job", class: 'btn btn-danger pull-right'
+ %hr
+ %p
+ = f.link_to_add "Add a job", :jobs, class: 'btn btn-success col-sm-offset-2'
+
+ .form-actions
+ = f.submit 'Save changes', class: 'btn btn-save'
+
diff --git a/app/views/jobs/_list.html.haml b/app/views/jobs/_list.html.haml
new file mode 100644
index 0000000..440985b
--- /dev/null
+++ b/app/views/jobs/_list.html.haml
@@ -0,0 +1,19 @@
+%table.table
+ %thead
+ %tr
+ %th Name
+ %th Build commits
+ %th Build tags
+ %th Tags
+
+ %tbody
+ - @project.jobs.each do |job|
+ %tr
+ %td= job.name
+ %td= check_box_tag nil, nil, job.build_branches, disabled: true
+ %td= check_box_tag nil, nil, job.build_tags, disabled: true
+ %td
+ - job.tag_list.each do |tag|
+ %span.label.label-primary
+ = tag
+
diff --git a/app/views/jobs/index.html.haml b/app/views/jobs/index.html.haml
index 7622c96..bc3570e 100644
--- a/app/views/jobs/index.html.haml
+++ b/app/views/jobs/index.html.haml
@@ -1,42 +1,16 @@
+.btn-group.pull-right
+ = link_to project_jobs_path(@project), class: "btn #{'active' unless params[:list]}" do
+ %i.icon-edit
+ Edit
+ = link_to project_jobs_path(@project, list: 'true'), class: "btn #{'active' if params[:list]}" do
+ %i.icon-list
+ List
%p.slead
Jobs are scripts you want CI to run on each push to repository
-%hr
-
-= nested_form_for @project, html: { class: 'form-horizontal' } do |f|
- - if @project.errors.any?
- #error_explanation
- %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:"
- .alert.alert-error
- %ul
- - @project.errors.full_messages.each do |msg|
- %li= msg
- = f.fields_for :jobs do |job_form|
- .form-group
- = f.label :name, 'Name', class: 'control-label'
- .col-sm-10
- = job_form.text_field :name, class: 'form-control', placeholder: "Ex. cucumber"
- .form-group
- = f.label :build_branches, 'Events', class: 'control-label'
- .col-sm-10
- .checkbox
- = f.label :build_branches, 'Push a new commit', class: ''
- = job_form.check_box :build_branches
- .checkbox
- = f.label :build_tags, 'Push a new tag', class: ''
- = job_form.check_box :build_tags
- .form-group
- = f.label :commands, 'Script', class: 'control-label'
- .col-sm-10
- = job_form.text_area :commands, class: 'form-control', rows: 10, placeholder: "bundle exec rake spec"
- %p.light
- All lines will be concatenated in one file and executed.
- %br
- If you change the working directory or the environment in one line - it will affect the next lines too
- = job_form.link_to_remove "Remove this job", class: 'btn btn-danger pull-right'
- %hr
- %p
- = f.link_to_add "Add a job", :jobs, class: 'btn btn-success col-sm-offset-2'
+%hr
- .form-actions
- = f.submit 'Save changes', class: 'btn btn-save'
+- if params[:list]
+ = render 'list'
+- else
+ = render 'edit'
diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml
index 8be67b6..8401c65 100644
--- a/app/views/runners/_runner.html.haml
+++ b/app/views/runners/_runner.html.haml
@@ -10,6 +10,10 @@
- if build = runner.builds.last
= link_to "##{build.id}", [build.project, build]
%td
+ - runner.tag_list.each do |tag|
+ %span.label.label-primary
+ = tag
+ %td
#{time_ago_in_words(runner.created_at)} ago
%td
.pull-right
diff --git a/app/views/runners/edit.html.haml b/app/views/runners/edit.html.haml
index a7b4d2f..e70a283 100644
--- a/app/views/runners/edit.html.haml
+++ b/app/views/runners/edit.html.haml
@@ -11,10 +11,11 @@
Description
.col-sm-10
= f.text_field :description, class: 'form-control'
- -#.form-group
- = label_tag :labels, class: 'control-label' do
- Description
+ .form-group
+ = label_tag :tag_list, class: 'control-label' do
+ Tags
.col-sm-10
- = f.text_field :labels, class: 'form-control'
+ = f.text_field :tag_list, class: 'form-control'
+ .help-block You can setup jobs to only use runners with specific tags
.form-actions
= f.submit 'Save', class: 'btn btn-save'
diff --git a/app/views/runners/index.html.haml b/app/views/runners/index.html.haml
index 692416a..af8c3fc 100644
--- a/app/views/runners/index.html.haml
+++ b/app/views/runners/index.html.haml
@@ -26,6 +26,7 @@
%th Runner token
%th Description
%th Last build
+ %th Tags
%th Registered
%th
diff --git a/db/migrate/20150113001832_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20150113001832_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb
new file mode 100644
index 0000000..6bbd559
--- /dev/null
+++ b/db/migrate/20150113001832_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb
@@ -0,0 +1,31 @@
+# This migration comes from acts_as_taggable_on_engine (originally 1)
+class ActsAsTaggableOnMigration < ActiveRecord::Migration
+ def self.up
+ create_table :tags do |t|
+ t.string :name
+ end
+
+ create_table :taggings do |t|
+ t.references :tag
+
+ # You should make sure that the column created is
+ # long enough to store the required class names.
+ t.references :taggable, polymorphic: true
+ t.references :tagger, polymorphic: true
+
+ # Limit is created to prevent MySQL error on index
+ # length for MyISAM table type: http://bit.ly/vgW2Ql
+ t.string :context, limit: 128
+
+ t.datetime :created_at
+ end
+
+ add_index :taggings, :tag_id
+ add_index :taggings, [:taggable_id, :taggable_type, :context]
+ end
+
+ def self.down
+ drop_table :taggings
+ drop_table :tags
+ end
+end
diff --git a/db/migrate/20150113001833_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20150113001833_add_missing_unique_indices.acts_as_taggable_on_engine.rb
new file mode 100644
index 0000000..4ca676f
--- /dev/null
+++ b/db/migrate/20150113001833_add_missing_unique_indices.acts_as_taggable_on_engine.rb
@@ -0,0 +1,20 @@
+# This migration comes from acts_as_taggable_on_engine (originally 2)
+class AddMissingUniqueIndices < ActiveRecord::Migration
+ def self.up
+ add_index :tags, :name, unique: true
+
+ remove_index :taggings, :tag_id
+ remove_index :taggings, [:taggable_id, :taggable_type, :context]
+ add_index :taggings,
+ [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
+ unique: true, name: 'taggings_idx'
+ end
+
+ def self.down
+ remove_index :tags, :name
+
+ remove_index :taggings, name: 'taggings_idx'
+ add_index :taggings, :tag_id
+ add_index :taggings, [:taggable_id, :taggable_type, :context]
+ end
+end
diff --git a/db/migrate/20150113001834_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20150113001834_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb
new file mode 100644
index 0000000..8edb508
--- /dev/null
+++ b/db/migrate/20150113001834_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb
@@ -0,0 +1,15 @@
+# This migration comes from acts_as_taggable_on_engine (originally 3)
+class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
+ def self.up
+ add_column :tags, :taggings_count, :integer, default: 0
+
+ ActsAsTaggableOn::Tag.reset_column_information
+ ActsAsTaggableOn::Tag.find_each do |tag|
+ ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
+ end
+ end
+
+ def self.down
+ remove_column :tags, :taggings_count
+ end
+end
diff --git a/db/migrate/20150113001835_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20150113001835_add_missing_taggable_index.acts_as_taggable_on_engine.rb
new file mode 100644
index 0000000..71f2d7f
--- /dev/null
+++ b/db/migrate/20150113001835_add_missing_taggable_index.acts_as_taggable_on_engine.rb
@@ -0,0 +1,10 @@
+# This migration comes from acts_as_taggable_on_engine (originally 4)
+class AddMissingTaggableIndex < ActiveRecord::Migration
+ def self.up
+ add_index :taggings, [:taggable_id, :taggable_type, :context]
+ end
+
+ def self.down
+ remove_index :taggings, [:taggable_id, :taggable_type, :context]
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3a95481..6193199 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: 20150111062026) do
+ActiveRecord::Schema.define(version: 20150113001835) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -118,6 +118,26 @@ ActiveRecord::Schema.define(version: 20150111062026) do
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
+ create_table "taggings", force: true do |t|
+ t.integer "tag_id"
+ t.integer "taggable_id"
+ t.string "taggable_type"
+ t.integer "tagger_id"
+ t.string "tagger_type"
+ t.string "context", limit: 128
+ t.datetime "created_at"
+ end
+
+ add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
+ add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
+
+ create_table "tags", force: true do |t|
+ t.string "name"
+ t.integer "taggings_count", default: 0
+ end
+
+ add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
+
create_table "web_hooks", force: true do |t|
t.string "url", null: false
t.integer "project_id", null: false