Commit 69c04498 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Small bug fixes

parent 0aefeeb8
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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])
......
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