Commit 69c04498 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Small bug fixes

parent 0aefeeb8
...@@ -212,15 +212,23 @@ module Ci ...@@ -212,15 +212,23 @@ module Ci
"#{dir_to_trace}/#{id}.log" "#{dir_to_trace}/#{id}.log"
end end
def description
name
end
def target_url def target_url
Gitlab::Application.routes.url_helpers. Gitlab::Application.routes.url_helpers.
namespace_project_build_url(gl_project.namespace, gl_project, self) namespace_project_build_url(gl_project.namespace, gl_project, self)
end 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 private
def yaml_variables def yaml_variables
......
...@@ -11,14 +11,14 @@ class CommitStatus < ActiveRecord::Base ...@@ -11,14 +11,14 @@ class CommitStatus < ActiveRecord::Base
alias_attribute :author, :user alias_attribute :author, :user
scope :running, ->() { where(status: 'running') } scope :running, -> { where(status: 'running') }
scope :pending, ->() { where(status: 'pending') } scope :pending, -> { where(status: 'pending') }
scope :success, ->() { where(status: 'success') } scope :success, -> { where(status: 'success') }
scope :failed, ->() { where(status: 'failed') } scope :failed, -> { where(status: 'failed') }
scope :running_or_pending, ->() { where(status:[:running, :pending]) } 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 :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :ref)).order(stage_idx: :asc) }
scope :for_ref, ->(ref) { where(ref: [ref, nil]) } 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 state_machine :status, initial: :pending do
event :run do event :run do
...@@ -55,6 +55,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -55,6 +55,7 @@ class CommitStatus < ActiveRecord::Base
delegate :sha, :short_sha, :gl_project, delegate :sha, :short_sha, :gl_project,
to: :commit, prefix: false to: :commit, prefix: false
# TODO: this should be removed with all references
def before_sha def before_sha
Gitlab::Git::BLANK_SHA Gitlab::Git::BLANK_SHA
end end
...@@ -78,4 +79,12 @@ class CommitStatus < ActiveRecord::Base ...@@ -78,4 +79,12 @@ class CommitStatus < ActiveRecord::Base
Time.now - started_at Time.now - started_at
end end
end end
def cancel_url
nil
end
def retry_url
nil
end
end end
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- else - else
%strong Build ##{commit_status.id} %strong Build ##{commit_status.id}
- if defined?(ref) - if defined?(ref) && ref
%td %td
= commit_status.ref = commit_status.ref
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= commit_status.stage = commit_status.stage
%td %td
= commit_status.description = commit_status.name
.pull-right .pull-right
- if commit_status.tags.any? - if commit_status.tags.any?
- commit_status.tags.each do |tag| - commit_status.tags.each do |tag|
...@@ -36,17 +36,17 @@ ...@@ -36,17 +36,17 @@
- if commit_status.finished_at - if commit_status.finished_at
%span #{time_ago_in_words commit_status.finished_at} ago %span #{time_ago_in_words commit_status.finished_at} ago
- if defined?(coverage) - if defined?(coverage) && coverage
%td.coverage %td.coverage
- if commit_status.try(:coverage) - if commit_status.try(:coverage)
#{commit_status.coverage}% #{commit_status.coverage}%
%td %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 .pull-right
- if commit_status.active? - if commit_status.cancel_url
= link_to cancel_namespace_project_build_path(gl_project.namespace, gl_project, commit_status, return_to: request.original_url), title: 'Cancel commit_status' do = link_to commit_status.cancel_url, title: 'Cancel' do
%i.fa.fa-remove.cred %i.fa.fa-remove.cred
- elsif commit_status.commands.present? - elsif commit_status.retry_url
= 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 = link_to commit_status.retry_url, method: :post, title: 'Retry' do
%i.fa.fa-repeat %i.fa.fa-repeat
...@@ -203,7 +203,6 @@ Parameters: ...@@ -203,7 +203,6 @@ Parameters:
## Post the status to commit ## Post the status to commit
Adds or updates a status of a 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 POST /projects/:id/statuses/:sha
......
...@@ -5,7 +5,6 @@ module API ...@@ -5,7 +5,6 @@ module API
class CommitStatus < Grape::API class CommitStatus < Grape::API
resource :projects do resource :projects do
before { authenticate! } before { authenticate! }
before { authorize! :read_commit_statuses, user_project }
# Get a commit's statuses # Get a commit's statuses
# #
...@@ -19,13 +18,14 @@ module API ...@@ -19,13 +18,14 @@ module API
# Examples: # Examples:
# GET /projects/:id/repository/commits/:sha/statuses # GET /projects/:id/repository/commits/:sha/statuses
get ':id/repository/commits/:sha/statuses' do get ':id/repository/commits/:sha/statuses' do
authorize! :read_commit_statuses, user_project
sha = params[:sha] sha = params[:sha]
ci_commit = user_project.ci_commit(sha) ci_commit = user_project.ci_commit(sha)
not_found! 'Commit' unless ci_commit not_found! 'Commit' unless ci_commit
statuses = ci_commit.statuses statuses = ci_commit.statuses
statuses = statuses.latest unless parse_boolean(params[:all]) statuses = statuses.latest unless parse_boolean(params[:all])
statuses = statuses.where(ref: params[:ref]) if params[:ref].present? 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? statuses = statuses.where(name: params[:name]) if params[:name].present?
present paginate(statuses), with: Entities::CommitStatus present paginate(statuses), with: Entities::CommitStatus
end end
...@@ -43,6 +43,7 @@ module API ...@@ -43,6 +43,7 @@ module API
# Examples: # Examples:
# POST /projects/:id/statuses/:sha # POST /projects/:id/statuses/:sha
post ':id/statuses/:sha' do post ':id/statuses/:sha' do
authorize! :create_commit_statuses, user_project
required_attributes! [:state] required_attributes! [:state]
attrs = attributes_for_keys [:ref, :target_url, :description, :context, :name] attrs = attributes_for_keys [:ref, :target_url, :description, :context, :name]
commit = @project.commit(params[:sha]) commit = @project.commit(params[:sha])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment