project: show last branches, tags, PRs runs

This commit is contained in:
Simone Gotti 2019-03-27 15:41:29 +01:00
parent 395f8454a0
commit 6f7b0a0e16
5 changed files with 150 additions and 33 deletions

View File

@ -63,6 +63,7 @@
<script> <script>
import { apiurl, fetch } from "@/util/auth"; import { apiurl, fetch } from "@/util/auth";
import { fetchRuns } from "@/util/data.js";
import { userLocalRunLink, projectRunLink } from "@/util/link.js"; import { userLocalRunLink, projectRunLink } from "@/util/link.js";
export default { export default {
@ -72,7 +73,8 @@ export default {
ownertype: String, ownertype: String,
ownername: String, ownername: String,
username: String, username: String,
projectname: String projectname: String,
query: String
}, },
data() { data() {
return { return {
@ -82,6 +84,11 @@ export default {
user: null user: null
}; };
}, },
watch: {
$route: function(route) {
this.update();
}
},
methods: { methods: {
projectRunLink: projectRunLink, projectRunLink: projectRunLink,
userLocalRunLink: userLocalRunLink, userLocalRunLink: userLocalRunLink,
@ -99,7 +106,20 @@ export default {
if (run.result == "stopped") return "failed"; if (run.result == "stopped") return "failed";
return "unknown"; return "unknown";
}, },
fetchProjectRuns() { update() {
clearInterval(this.polling);
console.log("username", this.username);
console.log("projectname", this.projectname);
if (this.projectname !== undefined) {
this.fetchProject();
} else if (this.username !== undefined) {
this.fetchUser();
} else {
this.fetchRuns();
}
this.pollData();
},
fetchProject() {
let path = let path =
"/projects/" + "/projects/" +
encodeURIComponent( encodeURIComponent(
@ -115,7 +135,7 @@ export default {
this.fetchRuns(); this.fetchRuns();
}); });
}, },
fetchUserRuns() { fetchUser() {
fetch(apiurl("/users/" + this.username)) fetch(apiurl("/users/" + this.username))
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
@ -126,44 +146,37 @@ export default {
this.fetchRuns(); this.fetchRuns();
}); });
}, },
fetchRuns() { async fetchRuns() {
let u = apiurl("/runs"); let group;
//console.log("this.project.id", this.project.id); let lastrun = false;
console.log("u", u);
if (this.project !== null) { if (this.project !== null) {
u.searchParams.append("group", this.project.id); if (this.query == "branches") {
group = "project/" + this.project.id + "/branch";
lastrun = true;
} else if (this.query == "tags") {
group = "project/" + this.project.id + "/tag";
lastrun = true;
} else if (this.query == "pullrequests") {
group = "project/" + this.project.id + "/pr";
lastrun = true;
} else {
group = "project/" + this.project.id;
}
} else if (this.user !== null) { } else if (this.user !== null) {
u.searchParams.append("group", this.user.id); group = "user/" + this.user.id;
} }
fetch(u) this.runs = await fetchRuns(group, lastrun);
.then(res => res.json())
.then(res => {
console.log(res);
let runs = res.map(function(run) {
return run;
});
this.runs = runs;
console.log("runs", this.runs);
});
}, },
pollData() { pollData() {
clearInterval(this.polling);
this.polling = setInterval(() => { this.polling = setInterval(() => {
this.fetchRuns(); this.fetchRuns();
}, 2000); }, 2000);
} }
}, },
created: function() { created: function() {
console.log("username", this.username); this.update();
console.log("projectname", this.projectname);
if (this.projectname !== undefined) {
this.fetchProjectRuns();
} else if (this.username !== undefined) {
this.fetchUserRuns();
} else {
this.fetchRuns();
}
this.pollData();
}, },
beforeDestroy() { beforeDestroy() {
clearInterval(this.polling); clearInterval(this.polling);

View File

@ -93,6 +93,24 @@ export default new VueRouter({
component: runs, component: runs,
props: (route) => ({ ownertype: "user", ownername: route.params.username, projectname: route.params.projectname }) props: (route) => ({ ownertype: "user", ownername: route.params.username, projectname: route.params.projectname })
}, },
{
path: "branches",
name: "user project branches runs",
component: runs,
props: (route) => ({ ownertype: "user", ownername: route.params.username, projectname: route.params.projectname, query: "branches" })
},
{
path: "tags",
name: "user project tags runs",
component: runs,
props: (route) => ({ ownertype: "user", ownername: route.params.username, projectname: route.params.projectname, query: "tags" })
},
{
path: "pullrequests",
name: "user project pull requests runs",
component: runs,
props: (route) => ({ ownertype: "user", ownername: route.params.username, projectname: route.params.projectname, query: "pullrequests" })
},
{ {
path: "runs/:runid", path: "runs/:runid",
name: "user project run", name: "user project run",
@ -137,6 +155,24 @@ export default new VueRouter({
component: runs, component: runs,
props: (route) => ({ ownertype: "org", ownername: route.params.orgname, projectname: route.params.projectname }) props: (route) => ({ ownertype: "org", ownername: route.params.orgname, projectname: route.params.projectname })
}, },
{
path: "branches",
name: "org project branches runs",
component: runs,
props: (route) => ({ ownertype: "org", ownername: route.params.orgname, projectname: route.params.projectname, query: "branches" })
},
{
path: "tags",
name: "org project tags runs",
component: runs,
props: (route) => ({ ownertype: "org", ownername: route.params.orgname, projectname: route.params.projectname, query: "tags" })
},
{
path: "pullrequests",
name: "org project pull requests runs",
component: runs,
props: (route) => ({ ownertype: "org", ownername: route.params.orgname, projectname: route.params.projectname, query: "pullrequests" })
},
{ {
path: "runs/:runid", path: "runs/:runid",
name: "org project run", name: "org project run",

View File

@ -1,5 +1,17 @@
import { apiurl, fetch } from "@/util/auth"; import { apiurl, fetch } from "@/util/auth";
export async function fetchRuns(group, lastrun) {
let u = apiurl("/runs");
if (group) {
u.searchParams.append("group", group)
}
if (lastrun) {
u.searchParams.append("lastrun", true)
}
let res = await fetch(u)
return res.json();
}
export async function fetchRun(runid) { export async function fetchRun(runid) {
let res = await fetch(apiurl("/run/" + runid)); let res = await fetch(apiurl("/run/" + runid));
return res.json(); return res.json();

View File

@ -31,6 +31,18 @@ export function projectRunsLink(ownertype, ownername, projectname) {
return { name: ownertype + " project runs", params: { orgname: ownername, projectname: projectname } } return { name: ownertype + " project runs", params: { orgname: ownername, projectname: projectname } }
} }
export function projectBranchesRunsLink(ownertype, ownername, projectname) {
return { name: ownertype + " project branches runs", params: { orgname: ownername, projectname: projectname } }
}
export function projectTagsRunsLink(ownertype, ownername, projectname) {
return { name: ownertype + " project tags runs", params: { orgname: ownername, projectname: projectname } }
}
export function projectPRsRunsLink(ownertype, ownername, projectname) {
return { name: ownertype + " project pull requests runs", params: { orgname: ownername, projectname: projectname } }
}
export function projectRunLink(ownertype, ownername, projectname, runid) { export function projectRunLink(ownertype, ownername, projectname, runid) {
return { name: ownertype + " project run", params: { orgname: ownername, projectname: projectname, runid: runid } } return { name: ownertype + " project run", params: { orgname: ownername, projectname: projectname, runid: runid } }
} }

View File

@ -4,9 +4,18 @@
<div class="tabs"> <div class="tabs">
<ul> <ul>
<li <li
:class="[{ 'is-active': $route.name.endsWith('project runs') || $route.name.endsWith('project') }]" :class="[{ 'is-active': $route.name.match('project runs') || $route.name.endsWith('project') }]"
> >
<router-link :to="projectRunsLink(ownertype, ownername, projectname)">Runs</router-link> <router-link :to="projectRunsLink(ownertype, ownername, projectname)">Runs History</router-link>
</li>
<li :class="[{ 'is-active': $route.name.match('project branches runs') }]">
<router-link :to="projectBranchesRunsLink(ownertype, ownername, projectname)">Branches</router-link>
</li>
<li :class="[{ 'is-active': $route.name.match('project tags runs') }]">
<router-link :to="projectTagsRunsLink(ownertype, ownername, projectname)">Tags</router-link>
</li>
<li :class="[{ 'is-active': $route.name.match('project pull requests runs') }]">
<router-link :to="projectPRsRunsLink(ownertype, ownername, projectname)">Pull Requests</router-link>
</li> </li>
<li <li
v-if="$route.name.endsWith('project run') || $route.name.endsWith('project run task')" v-if="$route.name.endsWith('project run') || $route.name.endsWith('project run task')"
@ -20,7 +29,12 @@
> >
<router-link <router-link
:to="projectRunLink(ownertype, ownername, $route.params.projectname, $route.params.runid)" :to="projectRunLink(ownertype, ownername, $route.params.projectname, $route.params.runid)"
>Run {{$route.params.runid}}</router-link> >
<p v-if="run">
Run
<strong>#{{run.counter}}</strong>
</p>
</router-link>
</li> </li>
<li <li
v-if="$route.name.endsWith('project run task')" v-if="$route.name.endsWith('project run task')"
@ -31,7 +45,12 @@
<li v-if="$route.name.endsWith('project run task')" class="is-active"> <li v-if="$route.name.endsWith('project run task')" class="is-active">
<router-link <router-link
:to="projectRunTaskLink(ownertype, ownername, $route.params.projectname, $route.params.runid, $route.params.taskid)" :to="projectRunTaskLink(ownertype, ownername, $route.params.projectname, $route.params.runid, $route.params.taskid)"
>Task {{$route.params.taskid}}</router-link> >
<p v-if="run">
Task
<strong>{{run.tasks[$route.params.taskid].name}}</strong>
</p>
</router-link>
</li> </li>
</ul> </ul>
<ul class="is-right"> <ul class="is-right">
@ -49,11 +68,16 @@
import { import {
projectLink, projectLink,
projectRunsLink, projectRunsLink,
projectBranchesRunsLink,
projectTagsRunsLink,
projectPRsRunsLink,
projectRunLink, projectRunLink,
projectRunTaskLink, projectRunTaskLink,
projectSettingsLink projectSettingsLink
} from "@/util/link.js"; } from "@/util/link.js";
import { fetchRun } from "@/util/data.js";
import projbreadcrumbs from "@/components/projbreadcrumbs.vue"; import projbreadcrumbs from "@/components/projbreadcrumbs.vue";
import runs from "@/components/runs.vue"; import runs from "@/components/runs.vue";
import tabarrow from "@/components/tabarrow.vue"; import tabarrow from "@/components/tabarrow.vue";
@ -66,12 +90,32 @@ export default {
ownername: String, ownername: String,
projectname: String projectname: String
}, },
data() {
return {
run: null
};
},
watch: {
$route: async function(route) {
if (route.params.runid) {
this.run = await fetchRun(route.params.runid);
}
}
},
methods: { methods: {
projectLink: projectLink, projectLink: projectLink,
projectRunsLink: projectRunsLink, projectRunsLink: projectRunsLink,
projectBranchesRunsLink: projectBranchesRunsLink,
projectTagsRunsLink: projectTagsRunsLink,
projectPRsRunsLink: projectPRsRunsLink,
projectRunLink: projectRunLink, projectRunLink: projectRunLink,
projectRunTaskLink: projectRunTaskLink, projectRunTaskLink: projectRunTaskLink,
projectSettingsLink: projectSettingsLink projectSettingsLink: projectSettingsLink
},
created: async function() {
if (this.$route.params.runid) {
this.run = await fetchRun(this.$route.params.runid);
}
} }
}; };
</script> </script>