summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-08 19:49:57 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-08 19:49:57 +0200
commit1310f4e01c7c48357e8c7254e3c03c944c9935e5 (patch)
treef64a59452d2866f9f280bc05a04853c02aaff3d5
parent8cc88dac27c6cb919e505266e59add66649c852b (diff)
downloadgitlab-ci-1310f4e01c7c48357e8c7254e3c03c944c9935e5.tar.gz
GitLab init integration and advanced build
-rw-r--r--app/assets/stylesheets/main.scss4
-rw-r--r--app/helpers/builds_helper.rb15
-rw-r--r--app/models/build.rb12
-rw-r--r--app/models/project.rb7
-rw-r--r--app/views/builds/show.html.haml16
-rw-r--r--app/views/projects/_form.html.haml56
-rw-r--r--app/views/projects/edit.html.haml14
-rw-r--r--app/views/projects/new.html.haml5
-rw-r--r--app/views/projects/show.html.haml2
-rw-r--r--db/migrate/20121108160657_add_gitlab_url_to_project.rb5
-rw-r--r--db/migrate/20121108174237_add_started_at_to_build.rb5
-rw-r--r--db/schema.rb4
-rw-r--r--lib/runner.rb2
13 files changed, 109 insertions, 38 deletions
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index ad82d32..4370bc6 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -123,3 +123,7 @@ pre.trace {
}
h3.error { color: #B94A48; }
+
+.padded {
+ padding: 20px;
+}
diff --git a/app/helpers/builds_helper.rb b/app/helpers/builds_helper.rb
index d621e99..50ba3e4 100644
--- a/app/helpers/builds_helper.rb
+++ b/app/helpers/builds_helper.rb
@@ -1,2 +1,17 @@
module BuildsHelper
+ def gitlab_build_compare_link build, project
+ gitlab_url = project.gitlab_url
+
+ prev_build = project.builds.where("id < #{build.id}").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}", '#'
+ else
+ gitlab_url << "/commit/#{build.short_sha}"
+ link_to "#{build.short_sha}", gitlab_url
+ end
+ end
end
diff --git a/app/models/build.rb b/app/models/build.rb
index 8c25178..80031b6 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -2,7 +2,7 @@ class Build < ActiveRecord::Base
belongs_to :project
attr_accessible :project_id, :ref, :sha,
- :status, :finished_at, :trace
+ :status, :finished_at, :trace, :started_at
def failed?
status == 'fail'
@@ -12,6 +12,12 @@ class Build < ActiveRecord::Base
status == 'success'
end
+ def git_author_name
+ project.last_commit(self.sha).author.name
+ rescue
+ nil
+ end
+
def running?
status == 'running'
end
@@ -37,6 +43,10 @@ class Build < ActiveRecord::Base
update_attributes(trace: ansi_color_codes(trace))
end
+ def short_sha
+ sha[0..8]
+ end
+
def ansi_color_codes(string)
string.gsub("\e[0m", '</span>').
gsub(/\e\[(\d+)m/, "<span class=\"color\\1\">")
diff --git a/app/models/project.rb b/app/models/project.rb
index 41adc21..d5082af 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1,5 +1,5 @@
class Project < ActiveRecord::Base
- attr_accessible :name, :path, :scripts, :timeout, :token, :default_ref
+ attr_accessible :name, :path, :scripts, :timeout, :token, :default_ref, :gitlab_url
validates_presence_of :name, :path, :scripts, :timeout, :token, :default_ref
@@ -16,12 +16,13 @@ class Project < ActiveRecord::Base
def register_build opts={}
ref = opts[:ref] || default_ref || 'master'
+ sha = opts[:after] || last_commit(ref).sha
data = {
project_id: self.id,
status: 'running',
ref: ref,
- sha: last_commit(ref)
+ sha: sha
}
@build = Build.create(data)
@@ -60,7 +61,7 @@ class Project < ActiveRecord::Base
end
def last_commit(ref)
- repo.commits(ref, 1).first.sha
+ repo.commits(ref, 1).first
end
end
diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml
index 80c50a0..29d6322 100644
--- a/app/views/builds/show.html.haml
+++ b/app/views/builds/show.html.haml
@@ -15,6 +15,22 @@
.right
%span= @build.updated_at.stamp('19:00 Aug 27')
= @build.status
+
+- if @build.git_author_name
+ %p
+ %b Author:
+ #{@build.git_author_name}
+- if @project.gitlab_url
+ %p
+ %b GitLab:
+ = gitlab_build_compare_link(@build, @project)
+- if @build.started_at
+ %p
+ %b Duration:
+ #{distance_of_time_in_words(@build.started_at, @build.updated_at)}
+%p
+ %b Finished:
+ #{time_ago_in_words(@build.updated_at)} ago
.clearfix
%pre.trace#build-trace
= preserve do
diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml
index 9a74527..1fe06ca 100644
--- a/app/views/projects/_form.html.haml
+++ b/app/views/projects/_form.html.haml
@@ -7,24 +7,44 @@
- @project.errors.full_messages.each do |msg|
%li= msg
- .field
- = f.label :name
- = f.text_field :name, class: 'input-xxlarge'
- .field
- = f.label :timeout
- = f.number_field :timeout, class: 'input-xxlarge'
- .field
- = f.label :path
- = f.text_field :path, class: 'input-xxlarge'
- .field
- = f.label :default_ref, "Default branch"
- = f.text_field :default_ref, class: 'input-xxlarge'
- .field
- = f.label :token
- = f.text_field :token, class: 'input-xxlarge'
- .field
- = f.label :scripts
- = f.text_area :scripts, class: 'input-xxlarge'
+ .row-fluid
+ .span6
+ %fieldset
+ %legend Project
+ .field
+ = f.label :name
+ = f.text_field :name, class: 'input-xlarge', placeholder: 'my-project'
+ .field
+ = f.label :token
+ = f.text_field :token, class: 'input-xlarge', placeholder: 'xEeFCaDAB89'
+ %fieldset
+ %legend Git
+ .field
+ = f.label :path
+ = f.text_field :path, class: 'input-xlarge', placeholder: '/home/gitlab_ci/projectname'
+ .field
+ = f.label :default_ref, "Default branch"
+ = f.text_field :default_ref, class: 'input-xlarge', placeholder: 'master'
+
+ %fieldset
+ %legend GitLab
+ .field
+ = f.label :gitlab_url, "GitLab url to project"
+ = f.text_field :gitlab_url, class: 'input-xlarge', placeholder: 'http://gitlab.domain.com/project-slug'
+
+ .span6
+
+ %fieldset
+ %legend Build
+ .field
+ = f.label :timeout, 'Timeout (in seconds)'
+ = f.number_field :timeout, class: 'input-xlarge'
+ .field
+ = f.label :scripts
+ = f.text_area :scripts, class: 'input-xxlarge', rows: 18
+
.form-actions
= f.submit 'Save', class: 'btn btn-primary'
= link_to 'Cancel', projects_path, class: 'btn'
+ - unless @project.new_record?
+ = link_to 'Remove Project', project_path(@project), method: :delete, confirm: 'Project will be removed. Are you sure?', class: 'btn btn-danger right'
diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml
index 8cc54ff..ee8b5b7 100644
--- a/app/views/projects/edit.html.haml
+++ b/app/views/projects/edit.html.haml
@@ -1,14 +1,6 @@
%h3 Editing project
-
-%hr
-&larr;
-= link_to 'Back', project_path(@project)
+= link_to project_path(@project) do
+ &larr; Back to project
%hr
-= render 'form'
-
-.alert.alert-error
- .right
- %span After project will be removed there is no way to restore builds information
- = link_to 'Remove Project', project_path(@project), method: :delete, confirm: 'Project will be removed. Are you sure?', class: 'btn btn-danger'
- .clearfix
+= render 'form'
diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml
index 38b7976..c287d33 100644
--- a/app/views/projects/new.html.haml
+++ b/app/views/projects/new.html.haml
@@ -1,7 +1,6 @@
%h3 New project
-%hr
-&larr;
-= link_to 'Back', projects_path
+= link_to projects_path do
+ &larr; Back to projects
%hr
= render 'form'
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index 0718b82..2f43d21 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -1,5 +1,7 @@
%h3
Project: #{@project.name}
+ - if @project.gitlab_url
+ %small= link_to 'View on GitLab', @project.gitlab_url
.right
%a.btn.btn-small{href: run_project_path(@project)} Run
%a.btn.btn-small{href: edit_project_path(@project)}
diff --git a/db/migrate/20121108160657_add_gitlab_url_to_project.rb b/db/migrate/20121108160657_add_gitlab_url_to_project.rb
new file mode 100644
index 0000000..8a4e8fd
--- /dev/null
+++ b/db/migrate/20121108160657_add_gitlab_url_to_project.rb
@@ -0,0 +1,5 @@
+class AddGitlabUrlToProject < ActiveRecord::Migration
+ def change
+ add_column :projects, :gitlab_url, :string, null: true
+ end
+end
diff --git a/db/migrate/20121108174237_add_started_at_to_build.rb b/db/migrate/20121108174237_add_started_at_to_build.rb
new file mode 100644
index 0000000..b4d65c7
--- /dev/null
+++ b/db/migrate/20121108174237_add_started_at_to_build.rb
@@ -0,0 +1,5 @@
+class AddStartedAtToBuild < ActiveRecord::Migration
+ def change
+ add_column :builds, :started_at, :datetime, null: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a27fd12..b534971 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 => 20121106143042) do
+ActiveRecord::Schema.define(:version => 20121108174237) do
create_table "builds", :force => true do |t|
t.integer "project_id"
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define(:version => 20121106143042) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "sha"
+ t.datetime "started_at"
end
create_table "projects", :force => true do |t|
@@ -33,6 +34,7 @@ ActiveRecord::Schema.define(:version => 20121106143042) do
t.datetime "updated_at", :null => false
t.string "token"
t.string "default_ref"
+ t.string "gitlab_url"
end
create_table "users", :force => true do |t|
diff --git a/lib/runner.rb b/lib/runner.rb
index 529cec3..110e75f 100644
--- a/lib/runner.rb
+++ b/lib/runner.rb
@@ -24,7 +24,7 @@ class Runner
path = project.path
commands = project.scripts
-
+ build.update_attributes(started_at: Time.now)
Dir.chdir(path) do
commands.each_line do |line|