summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/commits_controller.rb7
-rw-r--r--spec/controllers/commits_controller_spec.rb27
3 files changed, 33 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e9c6cd7..5994671 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@ v7.13.0
v7.12.1
- Runner without tag should pick builds without tag only
+ - Explicit error in the GitLab when commit not found.
v7.12.0
- Endless scroll on the dashboard
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 88306f3..45b2c57 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -2,16 +2,19 @@ class CommitsController < ApplicationController
before_filter :authenticate_user!, except: [:status, :show]
before_filter :authenticate_public_page!, only: :show
before_filter :project
- before_filter :commit
before_filter :authorize_access_project!, except: [:status, :show, :cancel]
before_filter :authorize_project_developer!, only: [:cancel]
+ before_filter :commit, only: :show
def show
@builds = @commit.builds
end
def status
- render json: @commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
+ commit = Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id])
+ render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
+ rescue ActiveRecord::RecordNotFound
+ render json: { status: "not_found" }
end
def cancel
diff --git a/spec/controllers/commits_controller_spec.rb b/spec/controllers/commits_controller_spec.rb
new file mode 100644
index 0000000..f32d6f8
--- /dev/null
+++ b/spec/controllers/commits_controller_spec.rb
@@ -0,0 +1,27 @@
+require "spec_helper"
+
+describe CommitsController do
+ before do
+ @project = FactoryGirl.create :project
+ end
+
+ describe "GET /status" do
+ it "returns status of commit" do
+ commit = FactoryGirl.create :commit, project: @project
+ get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id
+
+ expect(response).to be_success
+ expect(response.code).to eq('200')
+ JSON.parse(response.body)["status"] == "pending"
+ end
+
+ it "returns not_found status" do
+ commit = FactoryGirl.create :commit, project: @project
+ get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id
+
+ expect(response).to be_success
+ expect(response.code).to eq('200')
+ JSON.parse(response.body)["status"] == "not_found"
+ end
+ end
+end