Class: Projects::BranchesController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/controllers/projects/branches_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#createObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/projects/branches_controller.rb', line 23

def create
  branch_name = sanitize(strip_tags(params[:branch_name]))
  branch_name = Addressable::URI.unescape(branch_name)

  result = CreateBranchService.new(project, current_user).
      execute(branch_name, ref)

  if params[:issue_iid]
    issue = @project.issues.find_by(iid: params[:issue_iid])
    SystemNoteService.new_issue_branch(issue, @project, current_user, branch_name) if issue
  end

  if result[:status] == :success
    @branch = result[:branch]
    redirect_to namespace_project_tree_path(@project.namespace, @project,
                                            @branch.name)
  else
    @error = result[:message]
    render action: 'new'
  end
end

#destroyObject


45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/projects/branches_controller.rb', line 45

def destroy
  @branch_name = Addressable::URI.unescape(params[:id])
  status = DeleteBranchService.new(project, current_user).execute(@branch_name)
  respond_to do |format|
    format.html do
      redirect_to namespace_project_branches_path(@project.namespace,
                                                  @project), status: 303
    end
    format.js { render status: status[:return_code] }
  end
end

#indexObject


8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/projects/branches_controller.rb', line 8

def index
  @sort = params[:sort] || 'name'
  @branches = @repository.branches_sorted_by(@sort)
  @branches = Kaminari.paginate_array(@branches).page(params[:page])

  @max_commits = @branches.reduce(0) do |memo, branch|
    diverging_commit_counts = repository.diverging_commit_counts(branch)
    [memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max
  end
end

#recentObject


19
20
21
# File 'app/controllers/projects/branches_controller.rb', line 19

def recent
  @branches = @repository.recent_branches
end