2021-11-03 16:40:31 +00:00
|
|
|
import { Component } from 'vue';
|
|
|
|
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
|
|
|
|
2022-05-14 15:45:01 +00:00
|
|
|
import useAuthentication from '~/compositions/useAuthentication';
|
2023-08-07 14:05:18 +00:00
|
|
|
import useConfig from '~/compositions/useConfig';
|
2022-05-14 15:45:01 +00:00
|
|
|
import useUserConfig from '~/compositions/useUserConfig';
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2023-08-07 14:05:18 +00:00
|
|
|
const { rootPath } = useConfig();
|
2021-11-03 16:40:31 +00:00
|
|
|
const routes: RouteRecordRaw[] = [
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/`,
|
2021-11-03 16:40:31 +00:00
|
|
|
name: 'home',
|
2023-08-07 14:05:18 +00:00
|
|
|
redirect: `${rootPath}/repos`,
|
2021-11-03 16:40:31 +00:00
|
|
|
},
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/repos`,
|
2023-06-12 23:07:52 +00:00
|
|
|
component: (): Component => import('~/views/RouterView.vue'),
|
2022-08-14 11:48:53 +00:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '',
|
2023-06-12 23:07:52 +00:00
|
|
|
name: 'repos',
|
|
|
|
component: (): Component => import('~/views/Repos.vue'),
|
2022-08-14 11:48:53 +00:00
|
|
|
meta: { authentication: 'required' },
|
|
|
|
},
|
2021-11-03 16:40:31 +00:00
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'add',
|
|
|
|
name: 'repo-add',
|
|
|
|
component: (): Component => import('~/views/RepoAdd.vue'),
|
|
|
|
meta: { authentication: 'required' },
|
2023-03-19 09:43:57 +00:00
|
|
|
},
|
2021-11-03 16:40:31 +00:00
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: ':repoId',
|
|
|
|
name: 'repo-wrapper',
|
|
|
|
component: (): Component => import('~/views/repo/RepoWrapper.vue'),
|
2021-11-03 16:40:31 +00:00
|
|
|
props: true,
|
2022-01-09 01:21:30 +00:00
|
|
|
children: [
|
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: '',
|
|
|
|
name: 'repo',
|
|
|
|
component: (): Component => import('~/views/repo/RepoPipelines.vue'),
|
|
|
|
meta: { repoHeader: true },
|
2022-01-09 01:21:30 +00:00
|
|
|
},
|
2022-01-09 18:28:02 +00:00
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'branches',
|
|
|
|
name: 'repo-branches',
|
|
|
|
component: (): Component => import('~/views/repo/RepoBranches.vue'),
|
|
|
|
meta: { repoHeader: true },
|
2022-01-09 18:28:02 +00:00
|
|
|
},
|
2022-01-09 02:59:45 +00:00
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'branches/:branch',
|
|
|
|
name: 'repo-branch',
|
|
|
|
component: (): Component => import('~/views/repo/RepoBranch.vue'),
|
|
|
|
meta: { repoHeader: true },
|
|
|
|
props: (route) => ({ branch: route.params.branch }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'pull-requests',
|
|
|
|
name: 'repo-pull-requests',
|
|
|
|
component: (): Component => import('~/views/repo/RepoPullRequests.vue'),
|
|
|
|
meta: { repoHeader: true },
|
2022-01-09 02:59:45 +00:00
|
|
|
},
|
2022-10-31 16:06:21 +00:00
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'pull-requests/:pullRequest',
|
|
|
|
name: 'repo-pull-request',
|
|
|
|
component: (): Component => import('~/views/repo/RepoPullRequest.vue'),
|
|
|
|
meta: { repoHeader: true },
|
|
|
|
props: (route) => ({ pullRequest: route.params.pullRequest }),
|
2022-10-31 16:06:21 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'pipeline/:pipelineId',
|
|
|
|
component: (): Component => import('~/views/repo/pipeline/PipelineWrapper.vue'),
|
|
|
|
props: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: ':stepId?',
|
|
|
|
name: 'repo-pipeline',
|
|
|
|
component: (): Component => import('~/views/repo/pipeline/Pipeline.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'changed-files',
|
|
|
|
name: 'repo-pipeline-changed-files',
|
|
|
|
component: (): Component => import('~/views/repo/pipeline/PipelineChangedFiles.vue'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'config',
|
|
|
|
name: 'repo-pipeline-config',
|
|
|
|
component: (): Component => import('~/views/repo/pipeline/PipelineConfig.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
2023-11-03 10:44:03 +00:00
|
|
|
{
|
|
|
|
path: 'errors',
|
|
|
|
name: 'repo-pipeline-errors',
|
|
|
|
component: (): Component => import('~/views/repo/pipeline/PipelineErrors.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
2023-06-12 23:07:52 +00:00
|
|
|
],
|
2022-10-31 16:06:21 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-12 23:07:52 +00:00
|
|
|
path: 'settings',
|
|
|
|
name: 'repo-settings',
|
|
|
|
component: (): Component => import('~/views/repo/RepoSettings.vue'),
|
|
|
|
meta: { authentication: 'required' },
|
|
|
|
props: true,
|
2022-10-31 16:06:21 +00:00
|
|
|
},
|
|
|
|
],
|
2021-11-03 16:40:31 +00:00
|
|
|
},
|
2023-06-12 23:07:52 +00:00
|
|
|
{
|
|
|
|
path: ':repoOwner/:repoName/:pathMatch(.*)*',
|
|
|
|
component: () => import('~/views/repo/RepoDeprecatedRedirect.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
2021-11-03 16:40:31 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/orgs/:orgId`,
|
2023-06-12 23:07:52 +00:00
|
|
|
component: (): Component => import('~/views/org/OrgWrapper.vue'),
|
2021-11-03 16:40:31 +00:00
|
|
|
props: true,
|
2023-06-12 23:07:52 +00:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '',
|
|
|
|
name: 'org',
|
|
|
|
component: (): Component => import('~/views/org/OrgRepos.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'settings',
|
|
|
|
name: 'org-settings',
|
|
|
|
component: (): Component => import('~/views/org/OrgSettings.vue'),
|
|
|
|
meta: { authentication: 'required' },
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
],
|
2021-11-03 16:40:31 +00:00
|
|
|
},
|
2023-07-21 17:45:32 +00:00
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/org/:orgName/:pathMatch(.*)*`,
|
2023-07-21 17:45:32 +00:00
|
|
|
component: (): Component => import('~/views/org/OrgDeprecatedRedirect.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
2022-08-14 11:48:53 +00:00
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/admin`,
|
2023-08-03 09:35:12 +00:00
|
|
|
name: 'admin-settings',
|
|
|
|
component: (): Component => import('~/views/admin/AdminSettings.vue'),
|
|
|
|
props: true,
|
2022-08-14 11:48:53 +00:00
|
|
|
meta: { authentication: 'required' },
|
|
|
|
},
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2021-11-03 16:40:31 +00:00
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/user`,
|
2021-11-03 16:40:31 +00:00
|
|
|
name: 'user',
|
|
|
|
component: (): Component => import('~/views/User.vue'),
|
|
|
|
meta: { authentication: 'required' },
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/login/error`,
|
2021-11-03 16:40:31 +00:00
|
|
|
name: 'login-error',
|
|
|
|
component: (): Component => import('~/views/Login.vue'),
|
|
|
|
meta: { blank: true },
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/do-login`,
|
2021-11-03 16:40:31 +00:00
|
|
|
name: 'login',
|
|
|
|
component: (): Component => import('~/views/Login.vue'),
|
|
|
|
meta: { blank: true },
|
|
|
|
props: true,
|
|
|
|
},
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
// TODO: deprecated routes => remove after some time
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/:ownerOrOrgId`,
|
2023-06-12 23:07:52 +00:00
|
|
|
redirect: (route) => ({ name: 'org', params: route.params }),
|
|
|
|
},
|
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/:repoOwner/:repoName/:pathMatch(.*)*`,
|
2023-06-12 23:07:52 +00:00
|
|
|
component: () => import('~/views/repo/RepoDeprecatedRedirect.vue'),
|
|
|
|
props: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// not found handler
|
2021-11-03 16:40:31 +00:00
|
|
|
{
|
2023-08-07 14:05:18 +00:00
|
|
|
path: `${rootPath}/:pathMatch(.*)*`,
|
2021-11-03 16:40:31 +00:00
|
|
|
name: 'not-found',
|
|
|
|
component: (): Component => import('~/views/NotFound.vue'),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHistory(),
|
|
|
|
routes,
|
|
|
|
});
|
|
|
|
|
|
|
|
router.beforeEach(async (to, _, next) => {
|
2022-05-14 15:45:01 +00:00
|
|
|
const config = useUserConfig();
|
|
|
|
const { redirectUrl } = config.userConfig.value;
|
|
|
|
if (redirectUrl !== '') {
|
|
|
|
config.setUserConfig('redirectUrl', '');
|
|
|
|
next(redirectUrl);
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:40:31 +00:00
|
|
|
const authentication = useAuthentication();
|
2023-06-12 23:07:52 +00:00
|
|
|
const authenticationRequired = to.matched.some((record) => record.meta.authentication === 'required');
|
|
|
|
if (authenticationRequired && !authentication.isAuthenticated) {
|
2021-11-03 16:40:31 +00:00
|
|
|
next({ name: 'login', query: { url: to.fullPath } });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|