diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 18:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 18:09:43 +0300 |
commit | 7a33080fff9a735cbe77968d67b13ffa92c0ffae (patch) | |
tree | 71a880649c8d3e551ec6bd94e93d08a9a9b5bde7 /app/presenters | |
parent | 9223573b85bcfdd21953f52e0d2c5cb587e366a1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/blob_presenter.rb | 29 | ||||
-rw-r--r-- | app/presenters/tree_entry_presenter.rb | 17 |
2 files changed, 38 insertions, 8 deletions
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index f25436c54be..cd473152b41 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -56,23 +56,23 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated end def web_url - url_helpers.project_blob_url(project, ref_qualified_path) + url_helpers.project_blob_url(*path_params) end def web_path - url_helpers.project_blob_path(project, ref_qualified_path) + url_helpers.project_blob_path(*path_params) end def edit_blob_path - url_helpers.project_edit_blob_path(project, ref_qualified_path) + url_helpers.project_edit_blob_path(*path_params) end def raw_path - url_helpers.project_raw_path(project, ref_qualified_path) + url_helpers.project_raw_path(*path_params) end def replace_path - url_helpers.project_update_blob_path(project, ref_qualified_path) + url_helpers.project_update_blob_path(*path_params) end def pipeline_editor_path @@ -164,6 +164,18 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated private + def path_params + if ref_type.present? + [project, ref_qualified_path, { ref_type: ref_type }] + else + [project, ref_qualified_path] + end + end + + def ref_type + blob.ref_type + end + def url_helpers Gitlab::Routing.url_helpers end @@ -179,7 +191,12 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated end def ref_qualified_path - File.join(blob.commit_id, blob.path) + # If `ref_type` is present the commit_id will include the ref qualifier e.g. `refs/heads/`. + # We only accept/return unqualified refs so we need to remove the qualifier from the `commit_id`. + + commit_id = ExtractsRef.unqualify_ref(blob.commit_id, ref_type) + + File.join(commit_id, blob.path) end def load_all_blob_data diff --git a/app/presenters/tree_entry_presenter.rb b/app/presenters/tree_entry_presenter.rb index 0b313d81360..3f4a9f13c36 100644 --- a/app/presenters/tree_entry_presenter.rb +++ b/app/presenters/tree_entry_presenter.rb @@ -4,10 +4,23 @@ class TreeEntryPresenter < Gitlab::View::Presenter::Delegated presents nil, as: :tree def web_url - Gitlab::Routing.url_helpers.project_tree_url(tree.repository.project, File.join(tree.commit_id, tree.path)) + Gitlab::Routing.url_helpers.project_tree_url(tree.repository.project, ref_qualified_path, + ref_type: tree.ref_type) end def web_path - Gitlab::Routing.url_helpers.project_tree_path(tree.repository.project, File.join(tree.commit_id, tree.path)) + Gitlab::Routing.url_helpers.project_tree_path(tree.repository.project, ref_qualified_path, + ref_type: tree.ref_type) + end + + private + + def ref_qualified_path + # If `ref_type` is present the commit_id will include the ref qualifier e.g. `refs/heads/`. + # We only accept/return unqualified refs so we need to remove the qualifier from the `commit_id`. + + commit_id = ExtractsRef.unqualify_ref(tree.commit_id, ref_type) + + File.join(commit_id, tree.path) end end |