Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
improve commit routing
Browse files Browse the repository at this point in the history
  • Loading branch information
vsizov committed Mar 20, 2015
1 parent ff0b455 commit 3d7eb9d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/builds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show

if commit
# Redirect to commit page
redirect_to project_show_commit_path(@project, sha: @build.commit.sha, ref: @build.commit.ref)
redirect_to project_ref_commit_path(@project, @build.commit.ref, @build.commit.sha)
return
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/commits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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_and_ref!(params[:sha], params[:ref])
@builds = @commit.builds
end

def status
@commit = project.commits.find_by(sha: params[:id])
render json: @commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
end

Expand All @@ -18,4 +17,8 @@ def status
def project
@project ||= Project.find(params[:project_id])
end

def commit
@commit ||= Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id])
end
end
2 changes: 1 addition & 1 deletion app/helpers/commits_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def commit_status_alert_class(commit)
end

def commit_link(commit)
link_to(commit.short_sha, project_show_commit_path(commit.project, sha: commit.sha, ref: commit.ref))
link_to(commit.short_sha, project_ref_commit_path(commit.project, commit.ref, commit.sha))
end
end
2 changes: 1 addition & 1 deletion app/models/project_services/slack_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def attachments
def attachment_message
out = "<#{RoutesHelper.project_url(project)}|#{project_name}>: "
if commit.matrix?
out << "Commit <#{RoutesHelper.project_show_commit_url(project, sha: commit.sha, ref: commit.ref)}|\##{commit.id}> "
out << "Commit <#{RoutesHelper.project_ref_commit_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
else
build = commit.builds_without_retry.first
out << "Build <#{RoutesHelper.project_build_url(project, build)}|\##{build.id}> "
Expand Down
2 changes: 1 addition & 1 deletion app/views/builds/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Edit Job

%p
= link_to project_show_commit_path(@project, sha: @commit.sha, ref: @commit.ref) do
= link_to project_ref_commit_path(@project, @commit.ref, @commit.sha) do
&larr; Back to project commit
%hr
#up-build-trace
Expand Down
2 changes: 1 addition & 1 deletion app/views/commits/_commit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
= commit.status

%td.build-link
= link_to project_show_commit_path(commit.project, sha: commit.sha, ref: commit.ref) do
= link_to project_ref_commit_path(commit.project, commit.ref, commit.sha) do
%strong #{commit.short_sha}

%td.build-message
Expand Down
11 changes: 6 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
end

resource :charts, only: [:show]
resources :commits, only: [] do
member do
get :status

resources :refs, constraints: { ref_id: /.*/ }, only: [] do
resources :commits, only: [:show] do
member do
get :status
end
end
end

get '/commit/:sha/ref/*ref' => 'commits#show', as: :show_commit

resources :builds, only: [:show] do
member do
get :cancel
Expand Down
2 changes: 1 addition & 1 deletion spec/features/commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

describe "GET /:project/commits/:sha" do
before do
visit project_show_commit_path(@project, sha: @commit.sha, ref: @commit.ref)
visit project_ref_commit_path(@project, @commit.ref, @commit.sha)
end

it { page.should have_content @commit.sha[0..7] }
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@commit = FactoryGirl.create :commit, project: @project
end

describe "GET /:project/commits/:id/status.json" do
describe "GET /:project/refs/:ref_name/commits/:id/status.json" do
before do
get status_project_commit_path(@project, @commit), format: :json
get status_project_ref_commit_path(@project, @commit.ref, @commit.sha), format: :json
end

it { response.status.should == 200 }
Expand Down

0 comments on commit 3d7eb9d

Please sign in to comment.