diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-31 15:23:43 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-31 15:23:43 +0300 |
commit | c530c57092097c0b57b16fac2a454c9bcb0c1b2b (patch) | |
tree | a483d91cb5bbbc30404661e4016a012ec01679b4 | |
parent | 9a92b2efdc420c137157fc67538594e3d881952b (diff) | |
download | gitlab-ci-c530c57092097c0b57b16fac2a454c9bcb0c1b2b.tar.gz |
Remove repo reading logic from project. GitLab CI does not store repos any more
-rw-r--r-- | Gemfile | 6 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/models/build.rb | 28 | ||||
-rw-r--r-- | app/models/project.rb | 47 | ||||
-rw-r--r-- | app/views/projects/_form.html.haml | 27 | ||||
-rw-r--r-- | db/migrate/20130531112551_add_data_field_to_build.rb | 5 | ||||
-rw-r--r-- | db/migrate/20130531122131_remove_path_field_from_project.rb | 8 | ||||
-rw-r--r-- | db/schema.rb | 10 | ||||
-rw-r--r-- | db/seeds.rb | 37 | ||||
-rw-r--r-- | lib/api/entities.rb | 2 |
10 files changed, 82 insertions, 92 deletions
@@ -37,18 +37,12 @@ gem 'whenever', require: false # Format dates gem 'stamp' -# Git support -gem 'rugged', '~> 0.18.0.b1' - # Pagination gem 'kaminari' # State machine gem 'state_machine' -# Encoding detection -gem 'charlock_holmes' - # API gem 'grape' gem 'grape-entity' diff --git a/Gemfile.lock b/Gemfile.lock index b26d19e..162b116 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,7 +46,6 @@ GEM celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) - charlock_holmes (0.6.9) childprocess (0.3.6) ffi (~> 1.0, >= 1.0.6) chronic (0.9.0) @@ -201,7 +200,6 @@ GEM rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) rubyzip (0.9.9) - rugged (0.18.0.gh.de28323) sass (3.2.7) sass-rails (3.2.6) railties (~> 3.2.0) @@ -273,7 +271,6 @@ DEPENDENCIES annotate bootstrap-sass capybara - charlock_holmes coffee-rails (~> 3.2.1) coveralls devise @@ -299,7 +296,6 @@ DEPENDENCIES rb-fsevent rb-inotify rspec-rails - rugged (~> 0.18.0.b1) sass-rails (~> 3.2.3) settingslogic shoulda-matchers diff --git a/app/models/build.rb b/app/models/build.rb index de88ff5..7b6ded2 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -1,8 +1,10 @@ class Build < ActiveRecord::Base belongs_to :project + serialize :push_data + attr_accessible :project_id, :ref, :sha, :before_sha, - :status, :finished_at, :trace, :started_at + :status, :finished_at, :trace, :started_at, :push_data validates :sha, presence: true validates :ref, presence: true @@ -63,19 +65,11 @@ class Build < ActiveRecord::Base end def git_author_name - commit.author[:name] - rescue - nil + commit_data[:author][:name] if commit_data && commit_data[:author] end def git_commit_message - commit.message - rescue - nil - end - - def commit - @commit ||= project.last_commit(self.sha) + commit_data[:message] if commit_data end def short_before_sha @@ -107,8 +101,16 @@ class Build < ActiveRecord::Base project.scripts end - def path - project.path + def commit_data + push_data[:commits].each do |commit| + return commit if commit[:id] == sha + end + rescue + nil + end + + def repo_url + project.gitlab_url + '.git' end end diff --git a/app/models/project.rb b/app/models/project.rb index 991b41c..c0e42ab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -8,8 +8,7 @@ class Project < ActiveRecord::Base # # Validations # - validates_presence_of :name, :path, :scripts, :timeout, :token, :default_ref - validate :repo_present? + validates_presence_of :name, :scripts, :timeout, :token, :default_ref, :gitlab_url validates_uniqueness_of :name validates :polling_interval, @@ -25,14 +24,7 @@ class Project < ActiveRecord::Base self.token = SecureRandom.hex(15) if self.token.blank? end - def repo_present? - repo - rescue - errors.add(:path, 'Project path is not a git repository') - false - end - - def register_build opts={} + def register_build(opts={}) ref = opts[:ref] raise 'ref is not defined' unless ref @@ -42,13 +34,14 @@ class Project < ActiveRecord::Base end before_sha = opts[:before] - sha = opts[:after] || last_ref_sha(ref) + sha = opts[:after] data = { project_id: self.id, ref: ref, sha: sha, - before_sha: before_sha + before_sha: before_sha, + push_data: opts } @build = Build.create(data) @@ -58,14 +51,8 @@ class Project < ActiveRecord::Base gitlab_url.present? end - def last_ref_sha ref - `cd #{self.path} && git fetch && git log remotes/origin/#{ref} -1 --format=oneline | grep -e '^[a-z0-9]*' -o`.strip - end - def status - if last_build - last_build.status - end + last_build.status if last_build end def last_build @@ -108,24 +95,6 @@ class Project < ActiveRecord::Base end end - def repo - @repo ||= Rugged::Repository.new(path) - end - - def last_commit(ref = 'master') - branch = find_branch_by_name(ref) - - if branch - repo.lookup(branch.target) - else - repo.lookup(ref) - end - end - - def find_branch_by_name(name) - repo.branches.find { |branch| branch.name == name } - end - def tracked_refs @tracked_refs ||= default_ref.split(",").map{|ref| ref.strip} end @@ -134,10 +103,6 @@ class Project < ActiveRecord::Base self.token && self.token == token end - def schedule_id - "project-#{id}" - end - def no_running_builds? # Get running builds not later than 3 days ago to ignore hungs builds.running.where("updated_at > ?", 3.days.ago).empty? diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 4b07535..e905220 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -15,28 +15,23 @@ = f.label :name = f.text_field :name, class: 'input-xlarge', placeholder: 'my-project' .field - = f.label :token, "Token (Leave empty to generate random token)" - = f.text_field :token, class: 'input-xlarge', placeholder: 'xEeFCaDAB89' - .field - = f.label :public do - = f.check_box :public, class: 'input-xlarge' - %span Public (Anyone can see project and builds list) - - %fieldset - %legend Git - .field - = f.label :path - = f.text_field :path, class: 'input-xlarge', placeholder: '/home/gitlab_ci/projectname' + = f.label :gitlab_url, "GitLab url to project" + = f.text_field :gitlab_url, class: 'input-xlarge', placeholder: 'http://gitlab.domain.com/project-slug' .field - = f.label :default_ref, "Follow branches" + = f.label :default_ref, "Make tabs for next branches" = f.text_field :default_ref, class: 'input-xlarge', placeholder: 'master, stable' %small You will be able to filter builds by following branches + %fieldset - %legend GitLab + %legend Optional .field - = f.label :gitlab_url, "GitLab url to project" - = f.text_field :gitlab_url, class: 'input-xlarge', placeholder: 'http://gitlab.domain.com/project-slug' + = f.label :token, "Token (Leave empty to generate random token)" + = f.text_field :token, class: 'input-xlarge', placeholder: 'xEeFCaDAB89' + .field + = f.label :public do + = f.check_box :public, class: 'input-xlarge' + %span Public (Anyone can see project and builds list) .span6 diff --git a/db/migrate/20130531112551_add_data_field_to_build.rb b/db/migrate/20130531112551_add_data_field_to_build.rb new file mode 100644 index 0000000..ff897bc --- /dev/null +++ b/db/migrate/20130531112551_add_data_field_to_build.rb @@ -0,0 +1,5 @@ +class AddDataFieldToBuild < ActiveRecord::Migration + def change + add_column :builds, :push_data, :text + end +end diff --git a/db/migrate/20130531122131_remove_path_field_from_project.rb b/db/migrate/20130531122131_remove_path_field_from_project.rb new file mode 100644 index 0000000..684c164 --- /dev/null +++ b/db/migrate/20130531122131_remove_path_field_from_project.rb @@ -0,0 +1,8 @@ +class RemovePathFieldFromProject < ActiveRecord::Migration + def up + remove_column :projects, :path + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 299cb2b..ef1c9b8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,25 +11,25 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130129121754) do +ActiveRecord::Schema.define(:version => 20130531122131) do create_table "builds", :force => true do |t| t.integer "project_id" t.string "ref" t.string "status" t.datetime "finished_at" - t.text "trace" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.text "trace", :limit => 2147483647 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "sha" t.datetime "started_at" t.string "tmp_file" t.string "before_sha" + t.text "push_data" end create_table "projects", :force => true do |t| t.string "name", :null => false - t.string "path", :null => false t.integer "timeout", :default => 1800, :null => false t.text "scripts", :null => false t.datetime "created_at", :null => false diff --git a/db/seeds.rb b/db/seeds.rb index 58f2170..64804dc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -38,13 +38,38 @@ if Rails.env == 'development' project = FactoryGirl.create :project, name: "Six", + gitlab_url: 'https://dev.gitlab.org/gitlab/six', scripts: 'bundle exec rspec spec' - project.repo.walk('1c8a9df45').first(10).each_with_index do |commit, index| - build = project.register_build( - ref: 'master', - before: commit.parents.first.oid, - after: commit.oid - ) + + push_data = { + "before" => "1c8a9df454ef68c22c2a33cca8232bb50849e5c5", + "after" => "2e008a711430a16092cd6a20c225807cb3f51db7", + "ref" => "refs/heads/master", + "user_id" => 1, + "user_name" => "Dmitriy Zaporozhets", + "repository" => { + "name" => "six", + "url" => "git@dev.gitlab.org:gitlab/six.git", + "description" => "", + "homepage" => "https://dev.gitlab.org/gitlab/six" + }, + "commits" => [ + { + "id" => "2e008a711430a16092cd6a20c225807cb3f51db7", + "message" => "Added codeclimate badge", + "timestamp" => "2012-10-10T09:11:19+00:00", + "url" => "https://dev.gitlab.org/gitlab/six/commit/2e008a711430a16092cd6a20c225807cb3f51db7", + "author" => { + "name" => "Dmitriy Zaporozhets", + "email" => "dmitriy.zaporozhets@gmail.com" + } + } + ], + "total_commits_count" => 1 + } + + 10.times do + build = project.register_build(HashWithIndifferentAccess.new(push_data)) end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index fdbc29b..ce36939 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1,7 +1,7 @@ module API module Entities class Build < Grape::Entity - expose :id, :commands, :path, :ref, :sha + expose :id, :commands, :path, :ref, :sha, :project_id, :repo_url end end end |