From ec9864980602c2488b8bc22d5bd635edb36dbe38 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Tue, 15 Aug 2023 14:16:35 +0300 Subject: [PATCH 1/2] Add server type query param for repos --- app/adapters/repo.js | 9 +++++++-- app/controllers/repo.js | 3 ++- app/models/repo.js | 9 ++++++--- app/router.js | 2 ++ app/routes/legacy-repo-url.js | 23 ++++++++++++++++++----- app/routes/repo.js | 4 ++-- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/adapters/repo.js b/app/adapters/repo.js index 3485918a88..72cc1498d1 100644 --- a/app/adapters/repo.js +++ b/app/adapters/repo.js @@ -19,16 +19,21 @@ export default V3Adapter.extend({ const prefix = this.urlPrefix(); if (query) { - const { provider, slug, custom } = query; + const { provider, slug, serverType, custom } = query; const providerPrefix = provider ? `${provider}/` : ''; delete query.provider; delete query.slug; delete query.custom; + delete query.serverType; // fetch repo by slug if (!id && slug) { - return `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}`; + if (serverType) { + return `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}?server_type=${serverType}`; + } else { + return `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}`; + } } if (custom && custom.type === 'byOwner') { diff --git a/app/controllers/repo.js b/app/controllers/repo.js index 16f85a16fd..ebc33cb8b4 100644 --- a/app/controllers/repo.js +++ b/app/controllers/repo.js @@ -16,7 +16,8 @@ export default Controller.extend({ features: service(), updateTimesService: service('updateTimes'), - queryParams: ['migrationStatus'], + queryParams: ['migrationStatus', 'serverType'], + serverType: null, migrationStatus: null, jobController: controller('job'), diff --git a/app/models/repo.js b/app/models/repo.js index 4233f9e01d..41bb6d98f2 100644 --- a/app/models/repo.js +++ b/app/models/repo.js @@ -426,12 +426,15 @@ Repo.reopenClass({ }); }, - fetchBySlug(store, slug, provider = defaultVcsConfig.urlPrefix) { - const loadedRepos = store.peekAll('repo').filterBy('provider', provider).filterBy('slug', slug); + fetchBySlug(store, slug, provider = defaultVcsConfig.urlPrefix, serverType = undefined) { + let loadedRepos = store.peekAll('repo').filterBy('provider', provider).filterBy('slug', slug); + if (serverType) { + loadedRepos = loadedRepos.filterBy('serverType', serverType); + } if (!isEmpty(loadedRepos)) { return EmberPromise.resolve(loadedRepos.firstObject); } - return store.queryRecord('repo', { slug, provider }); + return store.queryRecord('repo', { slug, provider, serverType }); }, }); diff --git a/app/router.js b/app/router.js index eed7e29f99..23a17a84f1 100644 --- a/app/router.js +++ b/app/router.js @@ -93,6 +93,8 @@ Router.map(function () { this.route('legacy-repo-url', { path: '/:owner/:repo/:method' }); this.route('legacy-repo-url', { path: '/:owner/:repo/:method/:id' }); this.route('legacy-repo-url', { path: '/:owner/:repo/:method/:id/:view' }); + this.route('legacy-repo-url', { path: '/:provider/:owner/:repo/:serverType/:method/:id' }); + this.route('legacy-repo-url', { path: '/:provider/:owner/:repo/:serverType/:method/:id/:view' }); this.route('error404', { path: '/404' }); this.route('page-not-found', { path: '/*wildcard' }); diff --git a/app/routes/legacy-repo-url.js b/app/routes/legacy-repo-url.js index 05f2897741..98e7ff6fa7 100644 --- a/app/routes/legacy-repo-url.js +++ b/app/routes/legacy-repo-url.js @@ -7,19 +7,32 @@ export default Route.extend({ beforeModel(transition) { const { params, queryParams } = transition.to; - let { owner, repo, method, id, view } = params; - let provider, routeName = 'provider', routeModels = []; + let { owner, repo, method, id, view, provider, serverType } = params; + let vcsConfig, routeName = 'provider', routeModels = []; - const vcsConfig = vcsConfigByUrlPrefix(owner); + if (provider) { + vcsConfig = vcsConfigByUrlPrefix(provider); + } else { + vcsConfig = vcsConfigByUrlPrefix(owner); + } const isLegacyUrl = isEmpty(vcsConfig); + const serverTypes = ['git', 'svn', 'perforce']; + const isServerTypeUrl = serverTypes.includes(serverType) || serverTypes.includes(id); + if (isLegacyUrl) { provider = defaultVcsConfig.urlPrefix; } else { // params include provider, so swap them accordingly - [provider, owner, repo, method, id] = [owner, repo, method, id, view]; + if (!isServerTypeUrl) { + [provider, owner, repo, method, id] = [owner, repo, method, id, view]; + } else if (serverTypes.includes(id)) { + [provider, owner, repo, serverType, method, id, view] = [owner, repo, method, id, view]; + } } + const newQueryParams = { serverType: serverType, ...queryParams }; + routeModels.push(provider); if (owner) { @@ -43,7 +56,7 @@ export default Route.extend({ if (this._router.hasRoute(routeName)) { transition.abort(); - this.transitionTo(routeName, ...routeModels, { queryParams }); + this.transitionTo(routeName, ...routeModels, { queryParams: newQueryParams }); } } }); diff --git a/app/routes/repo.js b/app/routes/repo.js index bbcc7443be..66166441ff 100644 --- a/app/routes/repo.js +++ b/app/routes/repo.js @@ -52,10 +52,10 @@ export default TravisRoute.extend(ScrollResetMixin, { return { provider, owner, name }; }, - model({ provider, owner, name }) { + model({ provider, owner, name, serverType }) { const slug = `${owner}/${name}`; this.set('slug', slug); - return Repo.fetchBySlug(this.store, slug, provider); + return Repo.fetchBySlug(this.store, slug, provider, serverType); }, beforeModel() { From e00024f6834590d3bfebdfe256386158c3b8fdb3 Mon Sep 17 00:00:00 2001 From: vitalie Date: Tue, 15 Aug 2023 16:06:01 +0300 Subject: [PATCH 2/2] refactoring --- app/adapters/repo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/adapters/repo.js b/app/adapters/repo.js index 72cc1498d1..61059c0902 100644 --- a/app/adapters/repo.js +++ b/app/adapters/repo.js @@ -29,11 +29,11 @@ export default V3Adapter.extend({ // fetch repo by slug if (!id && slug) { + let url = `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}`; if (serverType) { - return `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}?server_type=${serverType}`; - } else { - return `${prefix}/repo/${providerPrefix}${encodeURIComponent(slug)}`; + url = `${url}?server_type=${serverType}`; } + return url; } if (custom && custom.type === 'byOwner') {