diff options
| author | Valery Sizov <valery@gitlab.com> | 2015-06-24 12:16:55 +0000 |
|---|---|---|
| committer | Valery Sizov <valery@gitlab.com> | 2015-06-24 12:16:55 +0000 |
| commit | aec639d33b404ed4e1e587ea181cd65af5e5314e (patch) | |
| tree | 07783104a5ea20425021679464155dbaa59fc39a | |
| parent | 9ae34fda713d0ef0b9c824ff2ef37bc2c5f5d817 (diff) | |
| parent | 6231b4c9f39e0302ec3501204986b54f258775e8 (diff) | |
| download | gitlab-ci-aec639d33b404ed4e1e587ea181cd65af5e5314e.tar.gz | |
Merge branch 'commit_not_found_error' into 'master'
Explicit error when commit not found
!!! SHOULD BE MERGED WITH https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/871
https://dev.gitlab.org/gitlab/gitlab-ci/issues/280
See merge request !159
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | app/controllers/commits_controller.rb | 7 | ||||
| -rw-r--r-- | spec/controllers/commits_controller_spec.rb | 27 |
3 files changed, 33 insertions, 2 deletions
@@ -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 |
