Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-08-04 15:21:02 +0300
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-08-04 15:21:02 +0300
commitbbf2ef06eb25213a906159e28ec902c7ed9d6783 (patch)
treeafb6def1d410311316bdd93dc3e33f92897df793 /app/controllers
parent4c45f8ba4b3fcf0d258c005abc1224c77f880095 (diff)
Fix ABC size of BlobController#show
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/projects/blob_controller.rb56
1 files changed, 32 insertions, 24 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index 1716c8a7f61..a2e8c10857d 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -37,33 +37,11 @@ class Projects::BlobController < Projects::ApplicationController
respond_to do |format|
format.html do
- environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
- @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last
- @last_commit = @repository.last_commit_for_path(@commit.id, @blob.path)
-
- render 'show'
+ show_html
end
format.json do
- json = blob_json(@blob)
- return render_404 unless json
-
- render json: json.merge(
- path: blob.path,
- name: blob.name,
- extension: blob.extension,
- size: blob.raw_size,
- mime_type: blob.mime_type,
- binary: blob.raw_binary?,
- simple_viewer: blob.simple_viewer&.class&.partial_name,
- rich_viewer: blob.rich_viewer&.class&.partial_name,
- show_viewer_switcher: !!blob.show_viewer_switcher?,
- render_error: blob.simple_viewer&.render_error || blob.rich_viewer&.render_error,
- raw_path: project_raw_path(project, @id),
- blame_path: project_blame_path(project, @id),
- commits_path: project_commits_path(project, @id),
- permalink: project_blob_path(project, File.join(@commit.id, @path))
- )
+ show_json
end
end
end
@@ -207,4 +185,34 @@ class Projects::BlobController < Projects::ApplicationController
@last_commit_sha = Gitlab::Git::Commit
.last_for_path(@repository, @ref, @path).sha
end
+
+ def show_html
+ environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
+ @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last
+ @last_commit = @repository.last_commit_for_path(@commit.id, @blob.path)
+
+ render 'show'
+ end
+
+ def show_json
+ json = blob_json(@blob)
+ return render_404 unless json
+
+ render json: json.merge(
+ path: blob.path,
+ name: blob.name,
+ extension: blob.extension,
+ size: blob.raw_size,
+ mime_type: blob.mime_type,
+ binary: blob.raw_binary?,
+ simple_viewer: blob.simple_viewer&.class&.partial_name,
+ rich_viewer: blob.rich_viewer&.class&.partial_name,
+ show_viewer_switcher: !!blob.show_viewer_switcher?,
+ render_error: blob.simple_viewer&.render_error || blob.rich_viewer&.render_error,
+ raw_path: project_raw_path(project, @id),
+ blame_path: project_blame_path(project, @id),
+ commits_path: project_commits_path(project, @id),
+ permalink: project_blob_path(project, File.join(@commit.id, @path))
+ )
+ end
end