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.
This commit is contained in:
Simone Gotti 2019-05-15 11:21:18 +02:00
parent dfd16f99b8
commit 74cd268431
1 changed files with 25 additions and 2 deletions

View File

@ -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()
})