summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-10-12 15:45:46 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-10-12 15:55:12 +0200
commit69c04498ef0a49186a667fd44383b9b43690a91e (patch)
treee258463d00c42f296d4048f44b8743eb98161567
parent0aefeeb882b40d740b80f15ac6610a88a340d30b (diff)
downloadgitlab-ce-69c04498ef0a49186a667fd44383b9b43690a91e.tar.gz
Small bug fixes
-rw-r--r--app/models/ci/build.rb16
-rw-r--r--app/models/commit_status.rb23
-rw-r--r--app/views/projects/commit_statuses/_commit_status.html.haml16
-rw-r--r--doc/api/commits.md1
-rw-r--r--lib/api/commit_statuses.rb5
5 files changed, 39 insertions, 22 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 41ce522b2ff..cb6a1015210 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -212,15 +212,23 @@ module Ci
"#{dir_to_trace}/#{id}.log"
end
- def description
- name
- end
-
def target_url
Gitlab::Application.routes.url_helpers.
namespace_project_build_url(gl_project.namespace, gl_project, self)
end
+ def cancel_url
+ if active?
+ cancel_namespace_project_build_path(gl_project.namespace, gl_project, self, return_to: request.original_url)
+ end
+ end
+
+ def retry_url
+ if commands.present?
+ cancel_namespace_project_build_path(gl_project.namespace, gl_project, self, return_to: request.original_url)
+ end
+ end
+
private
def yaml_variables
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index a4896a76316..b6234c896e3 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -11,14 +11,14 @@ class CommitStatus < ActiveRecord::Base
alias_attribute :author, :user
- scope :running, ->() { where(status: 'running') }
- scope :pending, ->() { where(status: 'pending') }
- scope :success, ->() { where(status: 'success') }
- scope :failed, ->() { where(status: 'failed') }
- scope :running_or_pending, ->() { where(status:[:running, :pending]) }
- scope :latest, ->() { where(id: unscope(:select).select('max(id)').group(:name, :ref)).order(stage_idx: :asc) }
+ scope :running, -> { where(status: 'running') }
+ scope :pending, -> { where(status: 'pending') }
+ scope :success, -> { where(status: 'success') }
+ scope :failed, -> { where(status: 'failed') }
+ scope :running_or_pending, -> { where(status:[:running, :pending]) }
+ scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :ref)).order(stage_idx: :asc) }
scope :for_ref, ->(ref) { where(ref: [ref, nil]) }
- scope :running_or_pending, ->() { where(status: [:running, :pending]) }
+ scope :running_or_pending, -> { where(status: [:running, :pending]) }
state_machine :status, initial: :pending do
event :run do
@@ -55,6 +55,7 @@ class CommitStatus < ActiveRecord::Base
delegate :sha, :short_sha, :gl_project,
to: :commit, prefix: false
+ # TODO: this should be removed with all references
def before_sha
Gitlab::Git::BLANK_SHA
end
@@ -78,4 +79,12 @@ class CommitStatus < ActiveRecord::Base
Time.now - started_at
end
end
+
+ def cancel_url
+ nil
+ end
+
+ def retry_url
+ nil
+ end
end
diff --git a/app/views/projects/commit_statuses/_commit_status.html.haml b/app/views/projects/commit_statuses/_commit_status.html.haml
index f79929c70bf..14b814bb0d6 100644
--- a/app/views/projects/commit_statuses/_commit_status.html.haml
+++ b/app/views/projects/commit_statuses/_commit_status.html.haml
@@ -9,7 +9,7 @@
- else
%strong Build ##{commit_status.id}
- - if defined?(ref)
+ - if defined?(ref) && ref
%td
= commit_status.ref
@@ -17,7 +17,7 @@
= commit_status.stage
%td
- = commit_status.description
+ = commit_status.name
.pull-right
- if commit_status.tags.any?
- commit_status.tags.each do |tag|
@@ -36,17 +36,17 @@
- if commit_status.finished_at
%span #{time_ago_in_words commit_status.finished_at} ago
- - if defined?(coverage)
+ - if defined?(coverage) && coverage
%td.coverage
- if commit_status.try(:coverage)
#{commit_status.coverage}%
%td
- - if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project)
+ - if defined?(controls) && controls && current_user && can?(current_user, :manage_builds, gl_project)
.pull-right
- - if commit_status.active?
- = link_to cancel_namespace_project_build_path(gl_project.namespace, gl_project, commit_status, return_to: request.original_url), title: 'Cancel commit_status' do
+ - if commit_status.cancel_url
+ = link_to commit_status.cancel_url, title: 'Cancel' do
%i.fa.fa-remove.cred
- - elsif commit_status.commands.present?
- = link_to retry_namespace_project_build_path(gl_project.namespace, gl_project, commit_status, return_to: request.original_url), method: :post, title: 'Retry commit_status' do
+ - elsif commit_status.retry_url
+ = link_to commit_status.retry_url, method: :post, title: 'Retry' do
%i.fa.fa-repeat
diff --git a/doc/api/commits.md b/doc/api/commits.md
index 78144dd42ef..9f72adc6ed9 100644
--- a/doc/api/commits.md
+++ b/doc/api/commits.md
@@ -203,7 +203,6 @@ Parameters:
## Post the status to commit
Adds or updates a status of a commit.
-Optionally you can post comments on a specific line of a commit. Therefor both `path`, `line_new` and `line_old` are required.
```
POST /projects/:id/statuses/:sha
diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb
index ca750320e40..2a005d6a9f7 100644
--- a/lib/api/commit_statuses.rb
+++ b/lib/api/commit_statuses.rb
@@ -5,7 +5,6 @@ module API
class CommitStatus < Grape::API
resource :projects do
before { authenticate! }
- before { authorize! :read_commit_statuses, user_project }
# Get a commit's statuses
#
@@ -19,13 +18,14 @@ module API
# Examples:
# GET /projects/:id/repository/commits/:sha/statuses
get ':id/repository/commits/:sha/statuses' do
+ authorize! :read_commit_statuses, user_project
sha = params[:sha]
ci_commit = user_project.ci_commit(sha)
not_found! 'Commit' unless ci_commit
statuses = ci_commit.statuses
statuses = statuses.latest unless parse_boolean(params[:all])
statuses = statuses.where(ref: params[:ref]) if params[:ref].present?
- statuses = statuses.where(name: params[:stage]) if params[:stage].present?
+ statuses = statuses.where(stage: params[:stage]) if params[:stage].present?
statuses = statuses.where(name: params[:name]) if params[:name].present?
present paginate(statuses), with: Entities::CommitStatus
end
@@ -43,6 +43,7 @@ module API
# Examples:
# POST /projects/:id/statuses/:sha
post ':id/statuses/:sha' do
+ authorize! :create_commit_statuses, user_project
required_attributes! [:state]
attrs = attributes_for_keys [:ref, :target_url, :description, :context, :name]
commit = @project.commit(params[:sha])