From 74cd268431bc349cf5dd2e6918c544b4849fdca5 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 15 May 2019 11:21:18 +0200 Subject: [PATCH] router: handle /run path /run will accept two query parameters: projectref and runid and generate the final run path. This is useful for calls from commit statuses target_url so we don't have to provide a web api path the could change in the future. --- src/router.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/router.js b/src/router.js index 3f9c449..cc5f05a 100644 --- a/src/router.js +++ b/src/router.js @@ -21,7 +21,8 @@ import Register from "./views/Register.vue"; import Login from "./views/Login.vue"; import Logout from "./views/Logout.vue"; -import { parseRef } from "@/util/link.js"; +import { parseRef, projectRunLink } from "@/util/link.js"; +import { fetchProject } from "@/util/data.js"; import store from "./store"; @@ -348,8 +349,30 @@ const router = new VueRouter({ ] }); -router.beforeEach((to, from, next) => { +router.beforeEach(async (to, from, next) => { store.dispatch("setError", null); + + const { path, query } = to + + if (path == "/run") { + // generic run handler by projectref and runid + let projectref = query.projectref + let runid = query.runid + + let { data, error } = await fetchProject(projectref); + if (error) { + this.$store.dispatch("setError", error); + return; + } + + let project = data; + + let parts = project.path.split("/") + let nextPath = projectRunLink(parts[0], parts[1], parts.slice(2), runid) + + next({ path: nextPath.path, replace: true }) + } + next() })