summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-30 14:07:04 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-30 14:07:04 +0000
commit1ca119930fc5f6125ca4d5db4e1a658d5df9dfcd (patch)
treec7a9a52134345a0e72a6f371c6256ea23468ab78
parent72b496b3a01043187a9e56d32bde3cb5f51980dd (diff)
parentf71f165f994bbdc5b98bf610f8306e7cad7f1740 (diff)
downloadgitlab-ce-1ca119930fc5f6125ca4d5db4e1a658d5df9dfcd.tar.gz
Merge branch 'cleanup-ci-helpers' into 'master'
Cleanup ci helpers Part of #2594 See merge request !1466
-rw-r--r--app/helpers/builds_helper.rb17
-rw-r--r--app/helpers/ci/application_helper.rb54
-rw-r--r--app/helpers/ci/builds_helper.rb19
-rw-r--r--app/helpers/ci/icons_helper.rb11
-rw-r--r--app/helpers/ci/runners_helper.rb22
-rw-r--r--app/helpers/ci/triggers_helper.rb7
-rw-r--r--app/helpers/ci/user_helper.rb15
-rw-r--r--app/helpers/ci_status_helper.rb36
-rw-r--r--app/helpers/runners_helper.rb20
-rw-r--r--app/helpers/time_helper.rb27
-rw-r--r--app/helpers/triggers_helper.rb5
-rw-r--r--app/mailers/ci/notify.rb1
-rw-r--r--spec/helpers/runners_helper_spec.rb (renamed from spec/helpers/ci/runners_helper_spec.rb)2
-rw-r--r--spec/helpers/time_helper_spec.rb (renamed from spec/helpers/ci/application_helper_spec.rb)2
14 files changed, 94 insertions, 144 deletions
diff --git a/app/helpers/builds_helper.rb b/app/helpers/builds_helper.rb
new file mode 100644
index 00000000000..b6658e52d09
--- /dev/null
+++ b/app/helpers/builds_helper.rb
@@ -0,0 +1,17 @@
+module BuildsHelper
+ def build_ref_link build
+ gitlab_ref_link build.project, build.ref
+ end
+
+ def build_compare_link build
+ gitlab_compare_link build.project, build.commit.short_before_sha, build.short_sha
+ end
+
+ def build_commit_link build
+ gitlab_commit_link build.project, build.short_sha
+ end
+
+ def build_url(build)
+ ci_project_build_url(build.project, build)
+ end
+end
diff --git a/app/helpers/ci/application_helper.rb b/app/helpers/ci/application_helper.rb
deleted file mode 100644
index 9fe6282bb81..00000000000
--- a/app/helpers/ci/application_helper.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-module Ci
- module ApplicationHelper
- def loader_html
- image_tag 'ci/loader.gif', alt: 'Loading'
- end
-
- def date_from_to(from, to)
- "#{from.to_s(:short)} - #{to.to_s(:short)}"
- end
-
- def duration_in_words(finished_at, started_at)
- if finished_at && started_at
- interval_in_seconds = finished_at.to_i - started_at.to_i
- elsif started_at
- interval_in_seconds = Time.now.to_i - started_at.to_i
- end
-
- time_interval_in_words(interval_in_seconds)
- end
-
- def time_interval_in_words(interval_in_seconds)
- minutes = interval_in_seconds / 60
- seconds = interval_in_seconds - minutes * 60
-
- if minutes >= 1
- "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}"
- else
- "#{pluralize(seconds, "second")}"
- end
- end
-
- def ci_icon_for_status(status)
- icon_name =
- case status
- when 'success'
- 'check-square'
- when 'failed'
- 'close'
- when 'running', 'pending'
- 'clock-o'
- else
- 'circle'
- end
-
- icon(icon_name)
- end
-
- def ci_status_with_icon(status)
- content_tag :span, class: "ci-status ci-#{status}" do
- ci_icon_for_status(status) + '&nbsp;'.html_safe + status
- end
- end
- end
-end
diff --git a/app/helpers/ci/builds_helper.rb b/app/helpers/ci/builds_helper.rb
deleted file mode 100644
index 5d6e785d951..00000000000
--- a/app/helpers/ci/builds_helper.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module Ci
- module BuildsHelper
- def build_ref_link build
- gitlab_ref_link build.project, build.ref
- end
-
- def build_compare_link build
- gitlab_compare_link build.project, build.commit.short_before_sha, build.short_sha
- end
-
- def build_commit_link build
- gitlab_commit_link build.project, build.short_sha
- end
-
- def build_url(build)
- ci_project_build_url(build.project, build)
- end
- end
-end
diff --git a/app/helpers/ci/icons_helper.rb b/app/helpers/ci/icons_helper.rb
deleted file mode 100644
index be40f79e880..00000000000
--- a/app/helpers/ci/icons_helper.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Ci
- module IconsHelper
- def boolean_to_icon(value)
- if value.to_s == "true"
- content_tag :i, nil, class: 'fa fa-circle cgreen'
- else
- content_tag :i, nil, class: 'fa fa-power-off clgray'
- end
- end
- end
-end
diff --git a/app/helpers/ci/runners_helper.rb b/app/helpers/ci/runners_helper.rb
deleted file mode 100644
index 03c9914641e..00000000000
--- a/app/helpers/ci/runners_helper.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-module Ci
- module RunnersHelper
- def runner_status_icon(runner)
- unless runner.contacted_at
- return content_tag :i, nil,
- class: "fa fa-warning-sign",
- title: "New runner. Has not connected yet"
- end
-
- status =
- if runner.active?
- runner.contacted_at > 3.hour.ago ? :online : :offline
- else
- :paused
- end
-
- content_tag :i, nil,
- class: "fa fa-circle runner-status-#{status}",
- title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago"
- end
- end
-end
diff --git a/app/helpers/ci/triggers_helper.rb b/app/helpers/ci/triggers_helper.rb
deleted file mode 100644
index 0d2438928ce..00000000000
--- a/app/helpers/ci/triggers_helper.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Ci
- module TriggersHelper
- def ci_build_trigger_url(project_id, ref_name)
- "#{Settings.gitlab_ci.url}/ci/api/v1/projects/#{project_id}/refs/#{ref_name}/trigger"
- end
- end
-end
diff --git a/app/helpers/ci/user_helper.rb b/app/helpers/ci/user_helper.rb
deleted file mode 100644
index c332d6ed9cf..00000000000
--- a/app/helpers/ci/user_helper.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module Ci
- module UserHelper
- def user_avatar_url(user = nil, size = nil, default = 'identicon')
- size = 40 if size.nil? || size <= 0
-
- if user.blank? || user.avatar_url.blank?
- 'ci/no_avatar.png'
- elsif /^(http(s?):\/\/(www|secure)\.gravatar\.com\/avatar\/(\w*))/ =~ user.avatar_url
- Regexp.last_match[0] + "?s=#{size}&d=#{default}"
- else
- user.avatar_url
- end
- end
- end
-end
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb
index 18c30ddb281..3a88ed7107e 100644
--- a/app/helpers/ci_status_helper.rb
+++ b/app/helpers/ci_status_helper.rb
@@ -4,19 +4,7 @@ module CiStatusHelper
end
def ci_status_icon(ci_commit)
- icon_name =
- case ci_commit.status
- when 'success'
- 'check'
- when 'failed'
- 'close'
- when 'running', 'pending'
- 'clock-o'
- else
- 'circle'
- end
-
- icon(icon_name)
+ ci_icon_for_status(ci_commit.status)
end
def ci_status_color(ci_commit)
@@ -31,4 +19,26 @@ module CiStatusHelper
'gray'
end
end
+
+ def ci_status_with_icon(status)
+ content_tag :span, class: "ci-status ci-#{status}" do
+ ci_icon_for_status(status) + '&nbsp;'.html_safe + status
+ end
+ end
+
+ def ci_icon_for_status(status)
+ icon_name =
+ case status
+ when 'success'
+ 'check'
+ when 'failed'
+ 'close'
+ when 'running', 'pending'
+ 'clock-o'
+ else
+ 'circle'
+ end
+
+ icon(icon_name)
+ end
end
diff --git a/app/helpers/runners_helper.rb b/app/helpers/runners_helper.rb
new file mode 100644
index 00000000000..5d7d06c8490
--- /dev/null
+++ b/app/helpers/runners_helper.rb
@@ -0,0 +1,20 @@
+module RunnersHelper
+ def runner_status_icon(runner)
+ unless runner.contacted_at
+ return content_tag :i, nil,
+ class: "fa fa-warning-sign",
+ title: "New runner. Has not connected yet"
+ end
+
+ status =
+ if runner.active?
+ runner.contacted_at > 3.hour.ago ? :online : :offline
+ else
+ :paused
+ end
+
+ content_tag :i, nil,
+ class: "fa fa-circle runner-status-#{status}",
+ title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago"
+ end
+end
diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb
new file mode 100644
index 00000000000..8142f733e76
--- /dev/null
+++ b/app/helpers/time_helper.rb
@@ -0,0 +1,27 @@
+module TimeHelper
+ def duration_in_words(finished_at, started_at)
+ if finished_at && started_at
+ interval_in_seconds = finished_at.to_i - started_at.to_i
+ elsif started_at
+ interval_in_seconds = Time.now.to_i - started_at.to_i
+ end
+
+ time_interval_in_words(interval_in_seconds)
+ end
+
+ def time_interval_in_words(interval_in_seconds)
+ minutes = interval_in_seconds / 60
+ seconds = interval_in_seconds - minutes * 60
+
+ if minutes >= 1
+ "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}"
+ else
+ "#{pluralize(seconds, "second")}"
+ end
+ end
+
+
+ def date_from_to(from, to)
+ "#{from.to_s(:short)} - #{to.to_s(:short)}"
+ end
+end
diff --git a/app/helpers/triggers_helper.rb b/app/helpers/triggers_helper.rb
new file mode 100644
index 00000000000..2a3a7e80fca
--- /dev/null
+++ b/app/helpers/triggers_helper.rb
@@ -0,0 +1,5 @@
+module TriggersHelper
+ def ci_build_trigger_url(project_id, ref_name)
+ "#{Settings.gitlab_ci.url}/ci/api/v1/projects/#{project_id}/refs/#{ref_name}/trigger"
+ end
+end
diff --git a/app/mailers/ci/notify.rb b/app/mailers/ci/notify.rb
index 4462da0d7d2..404842cf213 100644
--- a/app/mailers/ci/notify.rb
+++ b/app/mailers/ci/notify.rb
@@ -2,7 +2,6 @@ module Ci
class Notify < ActionMailer::Base
include Ci::Emails::Builds
- add_template_helper Ci::ApplicationHelper
add_template_helper Ci::GitlabHelper
default_url_options[:host] = Gitlab.config.gitlab.host
diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/runners_helper_spec.rb
index 6d0e2d3d1e1..b3d635a1932 100644
--- a/spec/helpers/ci/runners_helper_spec.rb
+++ b/spec/helpers/runners_helper_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Ci::RunnersHelper do
+describe RunnersHelper do
it "returns - not contacted yet" do
runner = FactoryGirl.build :ci_runner
expect(runner_status_icon(runner)).to include("not connected yet")
diff --git a/spec/helpers/ci/application_helper_spec.rb b/spec/helpers/time_helper_spec.rb
index 6a216715b7f..3f62527c5bb 100644
--- a/spec/helpers/ci/application_helper_spec.rb
+++ b/spec/helpers/time_helper_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Ci::ApplicationHelper do
+describe TimeHelper do
describe "#duration_in_words" do
it "returns minutes and seconds" do
intervals_in_words = {