summaryrefslogtreecommitdiff
path: root/app/controllers/ci/commits_controller.rb
blob: acf9189572cc83106a49363c71935e82400fdf5e (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
36
37
38
module Ci
  class CommitsController < Ci::ApplicationController
    before_action :authenticate_user!, except: [:status, :show]
    before_action :authenticate_public_page!, only: :show
    before_action :project
    before_action :authorize_access_project!, except: [:status, :show, :cancel]
    before_action :authorize_manage_builds!, only: [:cancel]
    before_action :commit, only: :show
    layout 'ci/commit'

    def show
      @builds = @commit.builds
    end

    def status
      commit = Ci::Project.find(params[:project_id]).commits.find_by_sha!(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 ci_project_commits_path(project, commit.sha)
    end

    private

    def project
      @project ||= Ci::Project.find(params[:project_id])
    end

    def commit
      @commit ||= Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id])
    end
  end
end