diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-16 17:02:34 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-16 17:02:34 +0200 |
commit | dc9b1a81d33bdf9e8d615d6ac1a619de76d1cec3 (patch) | |
tree | 3361cb9678ccda837f55bccee63a762f40fe4f80 | |
parent | 6d68dbeb1dfab0512a1620b410b8d424a41d84c8 (diff) | |
download | gitlab-ci-dc9b1a81d33bdf9e8d615d6ac1a619de76d1cec3.tar.gz |
Better gitlab integration
-rw-r--r-- | app/assets/stylesheets/main.scss | 3 | ||||
-rw-r--r-- | app/helpers/builds_helper.rb | 38 | ||||
-rw-r--r-- | app/helpers/gitlab_helper.rb | 20 | ||||
-rw-r--r-- | app/models/build.rb | 16 | ||||
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | app/views/builds/show.html.haml | 26 | ||||
-rw-r--r-- | db/migrate/20121116144312_add_before_sha_to_build.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 3 |
8 files changed, 87 insertions, 32 deletions
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index a58658f..02badc2 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -89,6 +89,9 @@ pre.trace { &.alert{ margin-bottom: 6px; } + td { + border-bottom: 1px solid #fff; + } } } diff --git a/app/helpers/builds_helper.rb b/app/helpers/builds_helper.rb index 838338e..81307ea 100644 --- a/app/helpers/builds_helper.rb +++ b/app/helpers/builds_helper.rb @@ -1,20 +1,4 @@ module BuildsHelper - def gitlab_build_compare_link build, project - gitlab_url = project.gitlab_url - - prev_build = project.builds.where("id < #{build.id}").where(ref: build.ref).order('id desc').first - - compare_link = prev_build && prev_build.sha != build.sha - - if compare_link - gitlab_url << "/compare/#{prev_build.short_sha}...#{build.short_sha}" - link_to "Compare #{prev_build.short_sha}...#{build.short_sha}", gitlab_url - else - gitlab_url << "/commit/#{build.short_sha}" - link_to "#{build.short_sha}", gitlab_url - end - end - def build_duration build if build.started? from = build.started_at @@ -22,4 +6,26 @@ module BuildsHelper distance_of_time_in_words(from, to) end end + + def build_ref_link build + if build.gitlab? + gitlab_ref_link build.project, build.ref + else + build.ref + end + end + + def build_compare_link build + if build.gitlab? + gitlab_compare_link build.project, build.short_before_sha, build.short_sha + end + end + + def build_commit_link build + if build.gitlab? + gitlab_commit_link build.project, build.short_sha + else + build.short_sha + end + end end diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb new file mode 100644 index 0000000..d2859fa --- /dev/null +++ b/app/helpers/gitlab_helper.rb @@ -0,0 +1,20 @@ +module GitlabHelper + def gitlab_ref_link project, ref + gitlab_url = project.gitlab_url + gitlab_url << "/commits/#{ref}" + link_to ref, gitlab_url + end + + def gitlab_compare_link project, before, after + gitlab_url = project.gitlab_url + gitlab_url << "/compare/#{before}...#{after}" + + link_to "#{before}...#{after}", gitlab_url + end + + def gitlab_commit_link project, sha + gitlab_url = project.gitlab_url + gitlab_url << "/commit/#{sha}" + link_to sha, gitlab_url + end +end diff --git a/app/models/build.rb b/app/models/build.rb index 6a676a2..717f6eb 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -42,6 +42,18 @@ class Build < ActiveRecord::Base state :canceled, value: 'canceled' end + def before_sha + 'AAAAAAA' + end + + def compare? + gitlab? && before_sha + end + + def gitlab? + project.gitlab? + end + def git_author_name commit.author.name rescue @@ -63,6 +75,10 @@ class Build < ActiveRecord::Base update_attributes(trace: trace) end + def short_before_sha + before_sha[0..8] + end + def short_sha sha[0..8] end diff --git a/app/models/project.rb b/app/models/project.rb index 3510d6b..7089007 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -25,17 +25,23 @@ class Project < ActiveRecord::Base ref = ref.scan(/heads\/(.*)$/).flatten[0] end + before_sha = opts[:before] sha = opts[:after] || last_ref_sha(ref) data = { project_id: self.id, ref: ref, - sha: sha + sha: sha, + before_sha: before_sha } @build = Build.create(data) end + def gitlab? + 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` end diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml index 134258e..1e8fda6 100644 --- a/app/views/builds/show.html.haml +++ b/app/views/builds/show.html.haml @@ -45,22 +45,20 @@ %legend Commit %p %b ID: - #{@build.sha} + #{build_commit_link @build} + - if @build.compare? + %p + %b Compare: + #{build_compare_link @build} %p %b Branch: - #{@build.ref} - - if @build.git_author_name - %p - %b Author: - #{@build.git_author_name} - - if @build.git_commit_message - %p - %b Message: - #{@build.git_commit_message} - - if @project.gitlab_url - %p - %b Show on GitLab: - = gitlab_build_compare_link(@build, @project) + #{build_ref_link @build} + %p + %b Author: + #{@build.git_author_name} + %p + %b Message: + #{@build.git_commit_message} .clearfix %pre.trace#build-trace diff --git a/db/migrate/20121116144312_add_before_sha_to_build.rb b/db/migrate/20121116144312_add_before_sha_to_build.rb new file mode 100644 index 0000000..7b8cfd9 --- /dev/null +++ b/db/migrate/20121116144312_add_before_sha_to_build.rb @@ -0,0 +1,5 @@ +class AddBeforeShaToBuild < ActiveRecord::Migration + def change + add_column :builds, :before_sha, :string, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 8234cbd..cc21cfd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121115132252) do +ActiveRecord::Schema.define(:version => 20121116144312) do create_table "builds", :force => true do |t| t.integer "project_id" @@ -24,6 +24,7 @@ ActiveRecord::Schema.define(:version => 20121115132252) do t.string "sha" t.datetime "started_at" t.string "tmp_file" + t.string "before_sha" end create_table "projects", :force => true do |t| |