2012-09-17 14:08:02 +00:00
|
|
|
# Controller for a specific Commit
|
|
|
|
#
|
|
|
|
# Not to be confused with CommitsController, plural.
|
2013-06-23 16:47:22 +00:00
|
|
|
class Projects::CommitController < Projects::ApplicationController
|
2012-09-17 14:08:02 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
2015-10-23 09:41:22 +00:00
|
|
|
before_action :authorize_download_code!, except: [:cancel_builds]
|
|
|
|
before_action :authorize_manage_builds!, only: [:cancel_builds]
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :commit
|
2015-11-03 10:44:07 +00:00
|
|
|
before_action :authorize_manage_builds!, only: [:cancel_builds, :retry_builds]
|
|
|
|
before_action :define_show_vars, only: [:show, :builds]
|
2012-09-17 14:08:02 +00:00
|
|
|
|
|
|
|
def show
|
2014-01-15 13:06:12 +00:00
|
|
|
return git_not_found! unless @commit
|
2012-09-17 14:08:02 +00:00
|
|
|
|
2015-04-21 13:15:49 +00:00
|
|
|
@line_notes = commit.notes.inline
|
2014-10-19 21:20:55 +00:00
|
|
|
@note = @project.build_commit_note(commit)
|
2015-04-21 13:15:49 +00:00
|
|
|
@notes = commit.notes.not_inline.fresh
|
2013-12-25 20:32:48 +00:00
|
|
|
@noteable = @commit
|
2012-10-29 14:55:37 +00:00
|
|
|
@comments_allowed = @reply_allowed = true
|
2014-01-15 13:06:12 +00:00
|
|
|
@comments_target = {
|
|
|
|
noteable_type: 'Commit',
|
|
|
|
commit_id: @commit.id
|
|
|
|
}
|
2012-09-25 22:46:19 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2014-07-15 15:28:21 +00:00
|
|
|
format.html
|
2012-11-22 19:49:44 +00:00
|
|
|
format.diff { render text: @commit.to_diff }
|
2012-11-22 11:45:39 +00:00
|
|
|
format.patch { render text: @commit.to_patch }
|
2012-09-17 14:08:02 +00:00
|
|
|
end
|
|
|
|
end
|
2014-01-15 13:06:12 +00:00
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
def builds
|
2015-10-06 11:12:21 +00:00
|
|
|
@ci_project = @project.gitlab_ci_project
|
|
|
|
end
|
|
|
|
|
2015-10-07 13:24:32 +00:00
|
|
|
def cancel_builds
|
2015-11-03 10:44:07 +00:00
|
|
|
ci_commit.builds.running_or_pending.each(&:cancel)
|
2015-10-07 13:24:32 +00:00
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
redirect_to builds_namespace_project_commit_path(project.namespace, project, commit.sha)
|
2015-10-07 13:24:32 +00:00
|
|
|
end
|
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
def retry_builds
|
|
|
|
ci_commit.builds.latest.failed.each do |build|
|
|
|
|
if build.retryable?
|
|
|
|
Ci::Build.retry(build)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to builds_namespace_project_commit_path(project.namespace, project, commit.sha)
|
|
|
|
end
|
2015-10-07 13:24:32 +00:00
|
|
|
|
2015-02-03 05:30:11 +00:00
|
|
|
def branches
|
|
|
|
@branches = @project.repository.branch_names_contains(commit.id)
|
|
|
|
@tags = @project.repository.tag_names_contains(commit.id)
|
|
|
|
render layout: false
|
|
|
|
end
|
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
private
|
|
|
|
|
2014-01-15 13:06:12 +00:00
|
|
|
def commit
|
2015-04-21 13:13:40 +00:00
|
|
|
@commit ||= @project.commit(params[:id])
|
2014-01-15 13:06:12 +00:00
|
|
|
end
|
2015-10-23 09:41:22 +00:00
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
def ci_commit
|
|
|
|
@ci_commit ||= project.ci_commit(commit.sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
def define_show_vars
|
2015-11-30 09:30:44 +00:00
|
|
|
if params[:w].to_i == 1
|
|
|
|
@diffs = commit.diffs({ ignore_whitespace_change: true })
|
|
|
|
else
|
|
|
|
@diffs = commit.diffs
|
|
|
|
end
|
|
|
|
|
2015-11-03 10:44:07 +00:00
|
|
|
@notes_count = commit.notes.count
|
|
|
|
|
|
|
|
@builds = ci_commit.builds if ci_commit
|
|
|
|
end
|
2015-10-23 09:41:22 +00:00
|
|
|
|
|
|
|
def authorize_manage_builds!
|
|
|
|
unless can?(current_user, :manage_builds, project)
|
|
|
|
return page_404
|
|
|
|
end
|
|
|
|
end
|
2012-09-17 14:08:02 +00:00
|
|
|
end
|