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