diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index 85740117c00cb06454c96e12bb65ea68b115fd10..2d24a467598ba0fd13526c7b4e31dd4fcdd302b3 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -713,3 +713,16 @@ export function visitUrl(url, external = false) {
export function refreshCurrentPage() {
visitUrl(window.location.href);
}
+
+// Adds a ref_type param to the path if refType is available
+export function buildURLwithRefType({ base = window.location.origin, path, refType = null }) {
+ const url = new URL('', base);
+ url.pathname = path; // This assignment does proper _escapes_
+
+ if (refType) {
+ url.searchParams.set('ref_type', refType.toLowerCase());
+ } else {
+ url.searchParams.delete('ref_type');
+ }
+ return url.pathname + url.search;
+}
diff --git a/app/assets/javascripts/pages/projects/blob/show/index.js b/app/assets/javascripts/pages/projects/blob/show/index.js
index f5e09d972a91b723d384136a4a96005878023707..daf06868298c3b1f3daeef06a97bda987e71f186 100644
--- a/app/assets/javascripts/pages/projects/blob/show/index.js
+++ b/app/assets/javascripts/pages/projects/blob/show/index.js
@@ -71,6 +71,7 @@ if (viewBlobEl) {
resourceId,
userId,
explainCodeAvailable,
+ refType,
...dataset
} = viewBlobEl.dataset;
@@ -94,6 +95,7 @@ if (viewBlobEl) {
props: {
path: blobPath,
projectPath,
+ refType,
},
});
},
diff --git a/app/assets/javascripts/repository/commits_service.js b/app/assets/javascripts/repository/commits_service.js
index e26036b56208cd4745f05f51217866ee2924beb7..1e0de045d3916bf2e01799e3cb9935371f12efc1 100644
--- a/app/assets/javascripts/repository/commits_service.js
+++ b/app/assets/javascripts/repository/commits_service.js
@@ -24,7 +24,7 @@ const addRequestedOffset = (offset) => {
const removeLeadingSlash = (path) => path.replace(/^\//, '');
-const fetchData = (projectPath, path, ref, offset) => {
+const fetchData = (projectPath, path, ref, offset, refType) => {
if (fetchedBatches.includes(offset) || offset < 0) {
return [];
}
@@ -41,12 +41,12 @@ const fetchData = (projectPath, path, ref, offset) => {
);
return axios
- .get(url, { params: { format: 'json', offset } })
+ .get(url, { params: { format: 'json', offset, ref_type: refType } })
.then(({ data }) => normalizeData(data, path))
.catch(() => createAlert({ message: I18N_COMMIT_DATA_FETCH_ERROR }));
};
-export const loadCommits = async (projectPath, path, ref, offset) => {
+export const loadCommits = async (projectPath, path, ref, offset, refType) => {
if (isRequested(offset)) {
return [];
}
@@ -54,7 +54,7 @@ export const loadCommits = async (projectPath, path, ref, offset) => {
// We fetch in batches of 25, so this ensures we don't refetch
Array.from(Array(COMMIT_BATCH_SIZE)).forEach((_, i) => addRequestedOffset(offset + i));
- const commits = await fetchData(projectPath, path, ref, offset);
+ const commits = await fetchData(projectPath, path, ref, offset, refType);
return commits;
};
diff --git a/app/assets/javascripts/repository/components/blob_content_viewer.vue b/app/assets/javascripts/repository/components/blob_content_viewer.vue
index 969036f84b729d317a0dd6e860ca37b34e5be956..87b3aa91c4a261e9cc9e805c4a0f8893c3574626 100644
--- a/app/assets/javascripts/repository/components/blob_content_viewer.vue
+++ b/app/assets/javascripts/repository/components/blob_content_viewer.vue
@@ -76,12 +76,15 @@ export default {
project: {
query: blobInfoQuery,
variables() {
- return {
+ const queryVariables = {
projectPath: this.projectPath,
filePath: this.path,
ref: this.originalBranch || this.ref,
shouldFetchRawText: Boolean(this.glFeatures.highlightJs),
+ refType: this.refType?.toUpperCase() || null,
};
+
+ return queryVariables;
},
result({ data }) {
const blob = data.project?.repository?.blobs?.nodes[0] || {};
@@ -130,6 +133,11 @@ export default {
type: String,
required: true,
},
+ refType: {
+ type: String,
+ required: false,
+ default: null,
+ },
},
data() {
return {
@@ -259,8 +267,12 @@ export default {
const type = this.activeViewerType;
this.isLoadingLegacyViewer = true;
+
+ const newUrl = new URL(this.blobInfo.webPath, window.location.origin);
+ newUrl.searchParams.set('format', 'json');
+ newUrl.searchParams.set('viewer', type);
axios
- .get(`${this.blobInfo.webPath}?format=json&viewer=${type}`)
+ .get(newUrl.pathname + newUrl.search)
.then(async ({ data: { html, binary } }) => {
this.isRenderingLegacyTextViewer = true;
diff --git a/app/assets/javascripts/repository/components/breadcrumbs.vue b/app/assets/javascripts/repository/components/breadcrumbs.vue
index d498be0b2bb63207047e14b1b6838609cf4f398d..5357644cfdf6c07e44f64871e6a446313a60b68f 100644
--- a/app/assets/javascripts/repository/components/breadcrumbs.vue
+++ b/app/assets/javascripts/repository/components/breadcrumbs.vue
@@ -1,7 +1,7 @@
-
-
+
diff --git a/app/assets/javascripts/repository/pages/index.vue b/app/assets/javascripts/repository/pages/index.vue
index 0e53235779c85dd0ebe6c3068230f74264d9276e..7b3cbdf21484659d3eb429d2b87889b4d50bb264 100644
--- a/app/assets/javascripts/repository/pages/index.vue
+++ b/app/assets/javascripts/repository/pages/index.vue
@@ -6,6 +6,13 @@ export default {
components: {
TreePage,
},
+ props: {
+ refType: {
+ type: String,
+ required: false,
+ default: null,
+ },
+ },
mounted() {
this.updateProjectElements(true);
},
@@ -21,5 +28,5 @@ export default {
-
+
diff --git a/app/assets/javascripts/repository/pages/tree.vue b/app/assets/javascripts/repository/pages/tree.vue
index 6bf674eb3f1191143289306a3f047bc6a0df185b..674d7bad4e4d212e7a969ca221eb5a4348099933 100644
--- a/app/assets/javascripts/repository/pages/tree.vue
+++ b/app/assets/javascripts/repository/pages/tree.vue
@@ -8,12 +8,22 @@ export default {
TreeContent,
},
mixins: [preloadMixin],
+ provide() {
+ return {
+ refType: this.refType,
+ };
+ },
props: {
path: {
type: String,
required: false,
default: '/',
},
+ refType: {
+ type: String,
+ required: false,
+ default: '',
+ },
},
computed: {
isRoot() {
diff --git a/app/assets/javascripts/repository/router.js b/app/assets/javascripts/repository/router.js
index 0a675e14eb5617a5a222754b70667028635b827f..5f73912ed2b8cdc2b86f6984f3d0868b2facc32e 100644
--- a/app/assets/javascripts/repository/router.js
+++ b/app/assets/javascripts/repository/router.js
@@ -13,15 +13,19 @@ export default function createRouter(base, baseRef) {
component: TreePage,
props: (route) => ({
path: route.params.path?.replace(/^\//, '') || '/',
+ refType: route.query.ref_type || null,
}),
};
const blobPathRoute = {
component: BlobPage,
- props: (route) => ({
- path: route.params.path,
- projectPath: base,
- }),
+ props: (route) => {
+ return {
+ path: route.params.path,
+ projectPath: base,
+ refType: route.query.ref_type || null,
+ };
+ },
};
const router = new VueRouter({
@@ -56,6 +60,9 @@ export default function createRouter(base, baseRef) {
path: '/',
name: 'projectRoot',
component: IndexPage,
+ props: {
+ refType: 'HEADS',
+ },
},
],
});
diff --git a/app/assets/javascripts/repository/utils/ref_switcher_utils.js b/app/assets/javascripts/repository/utils/ref_switcher_utils.js
index bcad4a2c822fedb109fa0a862beb6e63f841fabb..f3d21971771d5288466acaf663c9c8447e108c08 100644
--- a/app/assets/javascripts/repository/utils/ref_switcher_utils.js
+++ b/app/assets/javascripts/repository/utils/ref_switcher_utils.js
@@ -28,7 +28,7 @@ export function generateRefDestinationPath(projectRootPath, ref, selectedRef) {
[, refType, actualRef] = matches;
}
if (refType) {
- url.searchParams.set('ref_type', refType);
+ url.searchParams.set('ref_type', refType.toLowerCase());
} else {
url.searchParams.delete('ref_type');
}
diff --git a/app/graphql/queries/repository/blob_info.query.graphql b/app/graphql/queries/repository/blob_info.query.graphql
index fd463436ed4a5ef299daadf4b64eac34248d1762..7419961a564e003f589b1f239527f912426a9126 100644
--- a/app/graphql/queries/repository/blob_info.query.graphql
+++ b/app/graphql/queries/repository/blob_info.query.graphql
@@ -2,6 +2,7 @@ query getBlobInfo(
$projectPath: ID!
$filePath: String!
$ref: String!
+ $refType: RefType
$shouldFetchRawText: Boolean!
) {
project(fullPath: $projectPath) {
@@ -10,7 +11,7 @@ query getBlobInfo(
repository {
__typename
empty
- blobs(paths: [$filePath], ref: $ref) {
+ blobs(paths: [$filePath], ref: $ref, refType: $refType) {
__typename
nodes {
__typename
diff --git a/app/graphql/queries/repository/files.query.graphql b/app/graphql/queries/repository/files.query.graphql
index a83880ce69624a563b81671e5a0ed6e013a77ca2..bd7bb8ba78776c381abb1b91441b27b38cadfa0b 100644
--- a/app/graphql/queries/repository/files.query.graphql
+++ b/app/graphql/queries/repository/files.query.graphql
@@ -19,6 +19,7 @@ query getFiles(
$projectPath: ID!
$path: String
$ref: String!
+ $refType: RefType
$pageSize: Int!
$nextPageCursor: String
) {
@@ -27,7 +28,7 @@ query getFiles(
__typename
repository {
__typename
- tree(path: $path, ref: $ref) {
+ tree(path: $path, ref: $ref, refType: $refType) {
__typename
trees(first: $pageSize, after: $nextPageCursor) {
__typename
diff --git a/app/graphql/queries/repository/paginated_tree.query.graphql b/app/graphql/queries/repository/paginated_tree.query.graphql
index e82bc6d07349c443ed6d6154a32f08ab02272934..68aa90046b939d295f072436044a99dc80f58299 100644
--- a/app/graphql/queries/repository/paginated_tree.query.graphql
+++ b/app/graphql/queries/repository/paginated_tree.query.graphql
@@ -7,13 +7,19 @@ fragment TreeEntry on Entry {
type
}
-query getPaginatedTree($projectPath: ID!, $path: String, $ref: String!, $nextPageCursor: String) {
+query getPaginatedTree(
+ $projectPath: ID!
+ $path: String
+ $ref: String!
+ $nextPageCursor: String
+ $refType: RefType
+) {
project(fullPath: $projectPath) {
id
__typename
repository {
__typename
- paginatedTree(path: $path, ref: $ref, after: $nextPageCursor) {
+ paginatedTree(path: $path, ref: $ref, refType: $refType, after: $nextPageCursor) {
__typename
pageInfo {
__typename
diff --git a/app/graphql/queries/repository/path_last_commit.query.graphql b/app/graphql/queries/repository/path_last_commit.query.graphql
index facbf1555fc2fb9a160d6e0c917eefd13c270e64..738fdf534cb1a5caa2cbc9600a52b87370b4701d 100644
--- a/app/graphql/queries/repository/path_last_commit.query.graphql
+++ b/app/graphql/queries/repository/path_last_commit.query.graphql
@@ -1,10 +1,10 @@
-query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) {
+query pathLastCommit($projectPath: ID!, $path: String, $ref: String!, $refType: RefType) {
project(fullPath: $projectPath) {
__typename
id
repository {
__typename
- paginatedTree(path: $path, ref: $ref) {
+ paginatedTree(path: $path, ref: $ref, refType: $refType) {
__typename
nodes {
__typename
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index 84512453b7cc71864a878bda1881b21036dc145c..880fb8aa9d8256b31c130bba12b8f10b3e1c1e3a 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -153,7 +153,8 @@ def vue_file_list_data(project, ref)
project_short_path: project.path,
ref: ref,
escaped_ref: ActionDispatch::Journey::Router::Utils.escape_path(ref),
- full_name: project.name_with_namespace
+ full_name: project.name_with_namespace,
+ ref_type: @ref_type
}
end
diff --git a/app/views/projects/_files.html.haml b/app/views/projects/_files.html.haml
index b5bbb57d58f03b819b5484a6433b58d27a326c54..ba6cf689bdcfd7e7277d3930dccc54a5930e5b68 100644
--- a/app/views/projects/_files.html.haml
+++ b/app/views/projects/_files.html.haml
@@ -3,13 +3,13 @@
- ref = local_assigns.fetch(:ref) { current_ref }
- project = local_assigns.fetch(:project) { @project }
- has_project_shortcut_buttons = !current_user || current_user.project_shortcut_buttons
-- add_page_startup_api_call logs_file_project_ref_path(@project, ref, @path, format: "json", offset: 0)
+- add_page_startup_api_call logs_file_project_ref_path(@project, ref, @path, format: "json", offset: 0, ref_type: @ref_type)
- if readme_path = @project.repository.readme_path
- add_page_startup_api_call project_blob_path(@project, tree_join(@ref, readme_path), viewer: "rich", format: "json")
#tree-holder.tree-holder.clearfix.js-per-page{ data: { blame_per_page: Gitlab::Git::BlamePagination::PAGINATION_PER_PAGE } }
.info-well.gl-display-none.gl-sm-display-flex.project-last-commit.gl-flex-direction-column.gl-mt-5
- #js-last-commit.gl-m-auto
+ #js-last-commit.gl-m-auto{ data: {ref_type: @ref_type.to_s} }
= gl_loading_icon(size: 'md')
- if project.licensed_feature_available?(:code_owners)
#js-code-owners{ data: { branch: @ref, can_view_branch_rules: can_view_branch_rules?, branch_rules_path: branch_rules_path } }
diff --git a/app/views/projects/blob/_blob.html.haml b/app/views/projects/blob/_blob.html.haml
index e55668823711b0f682e8f4e41e475b1411f2d4c0..543bdaf46dfba9927802f0441df5231161a18ab0 100644
--- a/app/views/projects/blob/_blob.html.haml
+++ b/app/views/projects/blob/_blob.html.haml
@@ -24,7 +24,7 @@
- if !expanded
-# Data info will be removed once we migrate this to use GraphQL
-# Follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/330406
- #js-view-blob-app{ data: vue_blob_app_data(project, blob, ref) }
+ #js-view-blob-app{ data: vue_blob_app_data(project, blob, ref).merge(ref_type: @ref_type.to_s) }
= gl_loading_icon(size: 'md')
- else
%article.file-holder
diff --git a/app/views/projects/blob/_breadcrumb.html.haml b/app/views/projects/blob/_breadcrumb.html.haml
index 3178426ee8bd5923ee87955095648e67a81ec88c..539453bf6af6ee0c44b137b69265271ded944222 100644
--- a/app/views/projects/blob/_breadcrumb.html.haml
+++ b/app/views/projects/blob/_breadcrumb.html.haml
@@ -6,16 +6,16 @@
%ul.breadcrumb.repo-breadcrumb
%li.breadcrumb-item
- = link_to project_tree_path(@project, @ref) do
+ = link_to project_tree_path(@project, @ref, ref_type: @ref_type) do
= @project.path
- path_breadcrumbs do |title, path|
- title = truncate(title, length: 40)
%li.breadcrumb-item
- if path == @path
- = link_to project_blob_path(@project, tree_join(@ref, path)) do
+ = link_to project_blob_path(@project, tree_join(@ref, path), ref_type: @ref_type) do
%strong= title
- else
- = link_to title, project_tree_path(@project, tree_join(@ref, path))
+ = link_to title, project_tree_path(@project, tree_join(@ref, path), ref_type: @ref_type)
.tree-controls.gl-children-ml-sm-3<
= render 'projects/find_file_link'
diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml
index 1ffcb11247b39e751681919bc9276f58a127b2bd..9ec824f64d4664549a22606d46b3f35a0f1880b5 100644
--- a/app/views/projects/blob/show.html.haml
+++ b/app/views/projects/blob/show.html.haml
@@ -4,7 +4,7 @@
- signatures_path = namespace_project_signatures_path(namespace_id: @project.namespace.full_path, project_id: @project.path, id: @last_commit, limit: 1)
- content_for :prefetch_asset_tags do
- webpack_preload_asset_tag('monaco', prefetch: true)
-- add_page_startup_graphql_call('repository/blob_info', { projectPath: @project.full_path, ref: current_ref, filePath: @blob.path, shouldFetchRawText: @blob.rendered_as_text? && !@blob.rich_viewer })
+- add_page_startup_graphql_call('repository/blob_info', { projectPath: @project.full_path, ref: current_ref, refType: @ref_type.to_s, filePath: @blob.path, shouldFetchRawText: @blob.rendered_as_text? && !@blob.rich_viewer })
.js-signature-container{ data: { 'signatures-path': signatures_path } }
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index ae8d230f3564ce2db5505dd69cf9fc660949df54..51841c498188287e585f54bac8a9ecd258c5c274 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -7,7 +7,7 @@
%li{ class: "branch-item gl-display-flex! gl-align-items-center! js-branch-item js-branch-#{branch.name} gl-pl-3!", data: { name: branch.name, qa_selector: 'branch_container', qa_name: branch.name } }
.branch-info
.gl-display-flex.gl-align-items-center
- = link_to project_tree_path(@project, branch.name), class: 'item-title str-truncated-100 ref-name', data: { qa_selector: 'branch_link' } do
+ = link_to project_tree_path(@project, branch.name, ref_type: 'heads'), class: 'item-title str-truncated-100 ref-name', data: { qa_selector: 'branch_link' } do
= branch.name
= clipboard_button(text: branch.name, title: _("Copy branch name"))
- if is_default_branch
diff --git a/app/views/projects/tree/show.html.haml b/app/views/projects/tree/show.html.haml
index fbbf1c0461312f49f78f2ff9217a72dee840d01f..3c3f9eb7390fccb4aedef666fa767ddd57da8839 100644
--- a/app/views/projects/tree/show.html.haml
+++ b/app/views/projects/tree/show.html.haml
@@ -1,8 +1,9 @@
+- ref_type_enum_value = @ref_type&.upcase
- add_page_specific_style 'page_bundles/tree'
- current_route_path = request.fullpath.match(%r{-/tree/[^/]+/(.+$)}).to_a[1]
-- add_page_startup_graphql_call('repository/path_last_commit', { projectPath: @project.full_path, ref: current_ref, path: current_route_path || "" })
+- add_page_startup_graphql_call('repository/path_last_commit', { projectPath: @project.full_path, ref: current_ref, path: current_route_path || "", refType: ref_type_enum_value})
- add_page_startup_graphql_call('repository/permissions', { projectPath: @project.full_path })
-- add_page_startup_graphql_call('repository/files', { nextPageCursor: "", pageSize: 100, projectPath: @project.full_path, ref: current_ref, path: current_route_path || "/"})
+- add_page_startup_graphql_call('repository/files', { nextPageCursor: "", pageSize: 100, projectPath: @project.full_path, ref: current_ref, path: current_route_path || "/", refType: ref_type_enum_value})
- breadcrumb_title _("Repository")
- page_title @path.presence || _("Files"), @ref
diff --git a/spec/features/projects/files/user_browses_files_spec.rb b/spec/features/projects/files/user_browses_files_spec.rb
index 3b30a620257dea00678f168f2d0a9d536d058498..e93c9427c91fdbba24f49bd2d92e13dc2e2df1ba 100644
--- a/spec/features/projects/files/user_browses_files_spec.rb
+++ b/spec/features/projects/files/user_browses_files_spec.rb
@@ -155,7 +155,7 @@
click_link("d")
end
- expect(page).to have_link("..", href: project_tree_path(project, "markdown/"))
+ expect(page).to have_link("..", href: project_tree_path(project, "markdown"))
page.within(".tree-table") do
click_link("README.md")
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index 0f32eaa4ca6a23a8189366c3f9127256279e9dba..e54ad674a360841a1efa6ceb2b667a99baadcec5 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -1136,4 +1136,18 @@ describe('URL utility', () => {
expect(urlUtils.removeLastSlashInUrlPath(input)).toBe(output);
});
});
+
+ describe('buildURLwithRefType', () => {
+ const base = 'http://gitlab.com/';
+
+ it.each`
+ path | refType | output
+ ${'foo/bar'} | ${'heads'} | ${'/foo/bar?ref_type=heads'}
+ ${'/foo/bar/'} | ${'HEADS'} | ${'/foo/bar/?ref_type=heads'}
+ ${'/foo/bar/'} | ${''} | ${'/foo/bar/'}
+ ${'/'} | ${''} | ${'/'}
+ `('path $path with ref $refType becomes $output', ({ path, refType, output }) => {
+ expect(urlUtils.buildURLwithRefType({ base, path, refType })).toBe(output);
+ });
+ });
});
diff --git a/spec/frontend/repository/commits_service_spec.js b/spec/frontend/repository/commits_service_spec.js
index 22ef552c2f94862ed1322cf7530b4c0d534a4da8..5fb683bd37058bc04800654c020193ee7433c474 100644
--- a/spec/frontend/repository/commits_service_spec.js
+++ b/spec/frontend/repository/commits_service_spec.js
@@ -25,8 +25,13 @@ describe('commits service', () => {
resetRequestedCommits();
});
- const requestCommits = (offset, project = 'my-project', path = '', ref = 'main') =>
- loadCommits(project, path, ref, offset);
+ const requestCommits = (
+ offset,
+ project = 'my-project',
+ path = '',
+ ref = 'main',
+ refType = 'heads',
+ ) => loadCommits(project, path, ref, offset, refType);
it('calls axios get', async () => {
const offset = 10;
@@ -37,7 +42,9 @@ describe('commits service', () => {
await requestCommits(offset, project, path, ref);
- expect(axios.get).toHaveBeenCalledWith(testUrl, { params: { format: 'json', offset } });
+ expect(axios.get).toHaveBeenCalledWith(testUrl, {
+ params: { format: 'json', offset, ref_type: 'heads' },
+ });
});
it('encodes the path and ref', async () => {
diff --git a/spec/frontend/repository/components/blob_content_viewer_spec.js b/spec/frontend/repository/components/blob_content_viewer_spec.js
index e2bb7cdb2d79a6436f5a2a150bfbd161090c5077..50727756906fecaa77c4792bd4f8da8c11dd2a16 100644
--- a/spec/frontend/repository/components/blob_content_viewer_spec.js
+++ b/spec/frontend/repository/components/blob_content_viewer_spec.js
@@ -64,7 +64,7 @@ const mockRouter = {
push: mockRouterPush,
};
-const legacyViewerUrl = 'some_file.js?format=json&viewer=simple';
+const legacyViewerUrl = '/some_file.js?format=json&viewer=simple';
const createComponent = async (mockData = {}, mountFn = shallowMount, mockRoute = {}) => {
Vue.use(VueApollo);
@@ -255,7 +255,7 @@ describe('Blob content viewer component', () => {
'loads the legacy viewer when a file type is identified as legacy',
async (type) => {
await createComponent({ blob: { ...simpleViewerMock, fileType: type, webPath: type } });
- expect(mockAxios.history.get[0].url).toBe(`${type}?format=json&viewer=simple`);
+ expect(mockAxios.history.get[0].url).toBe(`/${type}?format=json&viewer=simple`);
},
);
@@ -348,7 +348,7 @@ describe('Blob content viewer component', () => {
await createComponent({ blob: { ...richViewerMock, fileType: 'unknown' } });
expect(mockAxios.history.get).toHaveLength(1);
- expect(mockAxios.history.get[0].url).toEqual('some_file.js?format=json&viewer=rich');
+ expect(mockAxios.history.get[0].url).toEqual('/some_file.js?format=json&viewer=rich');
});
});
@@ -371,7 +371,7 @@ describe('Blob content viewer component', () => {
});
it('does not load a CodeIntelligence component when no viewers are loaded', async () => {
- const url = 'some_file.js?format=json&viewer=rich';
+ const url = '/some_file.js?format=json&viewer=rich';
mockAxios.onGet(url).replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
await createComponent({ blob: { ...richViewerMock, fileType: 'unknown' } });
diff --git a/spec/frontend/repository/components/table/parent_row_spec.js b/spec/frontend/repository/components/table/parent_row_spec.js
index 77822a148b72c076fc4d18b4b6e4c8be846e20e1..daba5a5f63fcd2134d8be95a03e751225cc3a900 100644
--- a/spec/frontend/repository/components/table/parent_row_spec.js
+++ b/spec/frontend/repository/components/table/parent_row_spec.js
@@ -16,6 +16,9 @@ function factory(path, loadingPath) {
path,
loadingPath,
},
+ provide: {
+ refType: 'heads',
+ },
stubs: {
RouterLink: RouterLinkStub,
},
@@ -28,16 +31,14 @@ function factory(path, loadingPath) {
describe('Repository parent row component', () => {
it.each`
path | to
- ${'app'} | ${'/-/tree/main/'}
+ ${'app'} | ${'/-/tree/main'}
${'app/assets'} | ${'/-/tree/main/app'}
${'app/assets#/test'} | ${'/-/tree/main/app/assets%23'}
${'app/assets#/test/world'} | ${'/-/tree/main/app/assets%23/test'}
`('renders link in $path to $to', ({ path, to }) => {
factory(path);
- expect(vm.findComponent(RouterLinkStub).props().to).toEqual({
- path: to,
- });
+ expect(vm.findComponent(RouterLinkStub).props().to).toBe(`${to}?ref_type=heads`);
});
it('pushes new router when clicking row', () => {
@@ -45,9 +46,7 @@ describe('Repository parent row component', () => {
vm.find('td').trigger('click');
- expect($router.push).toHaveBeenCalledWith({
- path: '/-/tree/main/app',
- });
+ expect($router.push).toHaveBeenCalledWith('/-/tree/main/app?ref_type=heads');
});
// We test that it does not get called when clicking any internal
@@ -57,9 +56,7 @@ describe('Repository parent row component', () => {
vm.find('a').trigger('click');
- expect($router.push).not.toHaveBeenCalledWith({
- path: '/-/tree/main/app',
- });
+ expect($router.push).not.toHaveBeenCalled();
});
it('renders loading icon when loading parent', () => {
diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js
index 02b505c828cd52c2fe1424a0471486fd38bdd1e9..80471d8734bb7057e531584636c943d9b0a4b55a 100644
--- a/spec/frontend/repository/components/table/row_spec.js
+++ b/spec/frontend/repository/components/table/row_spec.js
@@ -44,6 +44,9 @@ function factory({ mockData = { ref: 'main', escapedRef: 'main' }, propsData = {
type: 'tree',
...propsData,
},
+ provide: {
+ refType: 'heads',
+ },
directives: {
GlHoverLoad: createMockDirective('gl-hover-load'),
},
@@ -157,9 +160,9 @@ describe('Repository table row component', () => {
},
});
- expect(wrapper.findComponent({ ref: 'link' }).props('to')).toEqual({
- path: `/-/tree/main/${encodeURIComponent(path)}`,
- });
+ expect(wrapper.findComponent({ ref: 'link' }).props('to')).toBe(
+ `/-/tree/main/${encodeURIComponent(path)}?ref_type=heads`,
+ );
});
it('renders link for directory with hash', () => {
@@ -173,7 +176,7 @@ describe('Repository table row component', () => {
},
});
- expect(wrapper.find('.tree-item-link').props('to')).toEqual({ path: '/-/tree/main/test%23' });
+ expect(wrapper.find('.tree-item-link').props('to')).toBe(`/-/tree/main/test%23?ref_type=heads`);
});
it('renders commit ID for submodule', () => {
diff --git a/spec/frontend/repository/components/tree_content_spec.js b/spec/frontend/repository/components/tree_content_spec.js
index 8d45e24e9e6f1e22a51b84529d0507c20048235a..c0eb65b28fe6b8b420af55cce3300af3816b8e51 100644
--- a/spec/frontend/repository/components/tree_content_spec.js
+++ b/spec/frontend/repository/components/tree_content_spec.js
@@ -51,6 +51,7 @@ describe('Repository table component', () => {
propsData: {
path,
},
+ provide: { refType: 'heads' },
});
};
@@ -170,8 +171,8 @@ describe('Repository table component', () => {
expect(isRequested).toHaveBeenCalledWith(rowNumber);
expect(loadCommits.mock.calls).toEqual([
- ['', path, '', rowNumber],
- ['', path, '', rowNumber - 25],
+ ['', path, '', rowNumber, 'heads'],
+ ['', path, '', rowNumber - 25, 'heads'],
]);
});
@@ -179,7 +180,7 @@ describe('Repository table component', () => {
createComponent({ path });
findFileTable().vm.$emit('row-appear', 0);
- expect(loadCommits.mock.calls).toEqual([['', path, '', 0]]);
+ expect(loadCommits.mock.calls).toEqual([['', path, '', 0, 'heads']]);
});
});
diff --git a/spec/frontend/repository/pages/index_spec.js b/spec/frontend/repository/pages/index_spec.js
index e50557e7d6165f0522b6c386ddaafa632d6fee58..a67a472b936d5663eccbc39c6f1193ee7693517a 100644
--- a/spec/frontend/repository/pages/index_spec.js
+++ b/spec/frontend/repository/pages/index_spec.js
@@ -9,7 +9,9 @@ describe('Repository index page component', () => {
let wrapper;
function factory() {
- wrapper = shallowMount(IndexPage);
+ wrapper = shallowMount(IndexPage, {
+ propsData: { refType: 'heads' },
+ });
}
afterEach(() => {
@@ -35,6 +37,6 @@ describe('Repository index page component', () => {
const child = wrapper.findComponent(TreePage);
expect(child.exists()).toBe(true);
- expect(child.props()).toEqual({ path: '/' });
+ expect(child.props()).toEqual({ path: '/', refType: 'heads' });
});
});
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index 1ca5b8eb954d7923444b265426e06d8cc35ad1ed..c94844eebbc27ee14070b5a9803c83eb2f817809 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -21,12 +21,14 @@
describe '#vue_file_list_data' do
it 'returns a list of attributes related to the project' do
+ helper.instance_variable_set(:@ref_type, 'heads')
expect(helper.vue_file_list_data(project, sha)).to include(
project_path: project.full_path,
project_short_path: project.path,
ref: sha,
escaped_ref: sha,
- full_name: project.name_with_namespace
+ full_name: project.name_with_namespace,
+ ref_type: 'heads'
)
end
end