summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-04 18:32:39 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-04 18:32:39 +0200
commit0b66f65d66c59dc00387272935bd17878ea13b95 (patch)
tree5a6b433db84e723812dacffacbc785e665cd3aaf
parent11218e13414814e00cbeffe05077718f856af897 (diff)
downloadgitlab-ci-0b66f65d66c59dc00387272935bd17878ea13b95.tar.gz
Add status method to commit controller for GitLab MR integration
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/commits_controller.rb12
-rw-r--r--app/models/commit.rb6
-rw-r--r--app/models/project.rb2
-rw-r--r--config/routes.rb6
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