summaryrefslogtreecommitdiff
path: root/app/controllers/commits_controller.rb
blob: 45b2c5705b4c5d12b262259252f80507a06f7aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class CommitsController < ApplicationController
  before_filter :authenticate_user!, except: [:status, :show]
  before_filter :authenticate_public_page!, only: :show
  before_filter :project
  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
    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
    commit.builds.running_or_pending.each(&:cancel)

    redirect_to project_ref_commit_path(project, commit.ref, commit.sha)
  end

  private

  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