diff options
-rw-r--r-- | app/controllers/commits_controller.rb | 12 | ||||
-rw-r--r-- | app/models/commit.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | config/routes.rb | 6 |
4 files changed, 19 insertions, 7 deletions
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 2b82f14..929841e 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -1,16 +1,24 @@ class CommitsController < ApplicationController before_filter :authenticate_user!, except: [:status] before_filter :project + before_filter :commit before_filter :authorize_access_project!, except: [:status] def show - @commit = project.commits.find_by(sha: params[:id]) @builds = @commit.builds end + def status + render json: @commit.to_json(only: [:id, :sha], methods: [:status, :coverage]) + end + private def project - @project = Project.find(params[:project_id]) + @project ||= Project.find(params[:project_id]) + end + + def commit + @commit ||= project.commits.find_by(sha: params[:id]) end end diff --git a/app/models/commit.rb b/app/models/commit.rb index 60d7c3d..5a01667 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -122,10 +122,10 @@ class Commit < ActiveRecord::Base def status if success? 'success' - elsif running? - 'running' elsif pending? 'pending' + elsif running? + 'running' else 'failed' end @@ -139,7 +139,7 @@ class Commit < ActiveRecord::Base def running? builds_without_retry.any? do |build| - build.running? + build.running? || build.pending? end end diff --git a/app/models/project.rb b/app/models/project.rb index b885f4a..c428e74 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -131,7 +131,7 @@ ls -la end def last_build - @last_build ||= commits.last.last_build + @last_build ||= commits.last.last_build if commits.any? end def last_build_date diff --git a/config/routes.rb b/config/routes.rb index 209033f..70a5148 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,11 @@ GitlabCi::Application.routes.draw do end resource :charts, only: [:show] - resources :commits, only: [:show] + resources :commits, only: [:show] do + member do + get :status + end + end resources :builds, only: [:show] do member do |