2018-12-09 13:21:20 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2019-05-23 21:37:52 +00:00
|
|
|
<div
|
|
|
|
|
v-if="fetchRunsError"
|
|
|
|
|
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
|
|
|
|
|
role="alert"
|
|
|
|
|
>
|
|
|
|
|
<div>{{ fetchRunsError }}</div>
|
|
|
|
|
</div>
|
2019-05-14 12:04:36 +00:00
|
|
|
<div v-if="runs.length > 0">
|
2019-05-21 10:13:21 +00:00
|
|
|
<ul>
|
|
|
|
|
<li
|
|
|
|
|
class="mb-2 border-l-5 rounded-l"
|
|
|
|
|
v-for="run in runs"
|
|
|
|
|
v-bind:key="run.id"
|
|
|
|
|
:class="runResultClass(run)"
|
|
|
|
|
>
|
|
|
|
|
<div class="pl-4 flex items-center border border-l-0 rounded-r">
|
2019-04-29 14:34:04 +00:00
|
|
|
<router-link
|
2019-05-17 15:28:11 +00:00
|
|
|
v-if="projectref"
|
2019-05-21 10:13:21 +00:00
|
|
|
class="w-1/3 font-bold"
|
2019-05-17 15:28:11 +00:00
|
|
|
:to="projectRunLink(ownertype, ownername, projectref, run.id)"
|
2018-12-09 13:21:20 +00:00
|
|
|
>
|
2019-05-21 10:13:21 +00:00
|
|
|
<span class>{{run.name}}</span>
|
2019-04-29 14:34:04 +00:00
|
|
|
</router-link>
|
2019-06-11 10:06:06 +00:00
|
|
|
<router-link v-else class="w-1/3 font-bold" :to="userDirectRunLink(ownername, run.id)">
|
2019-04-29 14:34:04 +00:00
|
|
|
<span>{{run.name}}</span>
|
|
|
|
|
</router-link>
|
2019-05-21 10:13:21 +00:00
|
|
|
<div class="w-1/3">{{run.annotations.message}}</div>
|
|
|
|
|
<span
|
|
|
|
|
v-if="waitingApproval(run)"
|
|
|
|
|
class="w-1/5 inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold mr-2"
|
|
|
|
|
>Waiting Approval</span>
|
|
|
|
|
<span v-if="!waitingApproval(run)" class="w-1/5"></span>
|
|
|
|
|
<span
|
|
|
|
|
v-if="stillRunning(run)"
|
|
|
|
|
class="w-1/5 inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold mr-2"
|
|
|
|
|
>Still running</span>
|
|
|
|
|
<span v-if="!stillRunning(run)" class="w-1/5"></span>
|
|
|
|
|
<div class="w-32">
|
|
|
|
|
<a :href="run.annotations.commit_link" class="block" target="_blank">
|
2019-04-29 14:34:04 +00:00
|
|
|
<i class="mdi mdi-source-commit mdi-rotate-90"></i>
|
|
|
|
|
<span>{{run.annotations.commit_sha.substring(0,8)}}</span>
|
|
|
|
|
</a>
|
|
|
|
|
<a
|
2019-06-10 15:48:58 +00:00
|
|
|
v-if="run.annotations.ref_type == 'branch'"
|
2019-04-29 14:34:04 +00:00
|
|
|
:href="run.annotations.branch_link"
|
2019-05-21 10:13:21 +00:00
|
|
|
class="block whitespace-no-wrap overflow-x-hidden"
|
2019-04-29 14:34:04 +00:00
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
<i class="mdi mdi-source-branch"></i>
|
|
|
|
|
<span>{{run.annotations.branch}}</span>
|
|
|
|
|
</a>
|
|
|
|
|
<a
|
2019-06-10 15:48:58 +00:00
|
|
|
v-else-if="run.annotations.ref_type == 'tag'"
|
2019-04-29 14:34:04 +00:00
|
|
|
:href="run.annotations.tag_link"
|
2019-05-21 10:13:21 +00:00
|
|
|
class="block"
|
2019-04-29 14:34:04 +00:00
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
<i class="mdi mdi-tag"></i>
|
|
|
|
|
<span>{{run.annotations.tag}}</span>
|
|
|
|
|
</a>
|
|
|
|
|
<a
|
2019-06-10 15:48:58 +00:00
|
|
|
v-else-if="run.annotations.ref_type == 'pull_request'"
|
2019-04-29 14:34:04 +00:00
|
|
|
:href="run.annotations.pull_request_link"
|
2019-05-21 10:13:21 +00:00
|
|
|
class="block"
|
2019-04-29 14:34:04 +00:00
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
<i class="mdi mdi-source-pull"></i>
|
|
|
|
|
<span>PR #{{run.annotations.pull_request_id}}</span>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2018-12-09 13:21:20 +00:00
|
|
|
</div>
|
2019-05-21 10:13:21 +00:00
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="flex justify-center my-3">
|
2019-05-14 12:04:36 +00:00
|
|
|
<button
|
|
|
|
|
v-if="hasMoreRuns"
|
2019-05-21 10:13:21 +00:00
|
|
|
class="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded"
|
2019-05-14 12:04:36 +00:00
|
|
|
@click="loadMoreRuns()"
|
|
|
|
|
>Load more...</button>
|
|
|
|
|
</div>
|
2018-12-09 13:21:20 +00:00
|
|
|
</div>
|
2019-05-21 10:13:21 +00:00
|
|
|
<div v-else class>No runs</div>
|
2018-12-09 13:21:20 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2019-05-13 14:29:47 +00:00
|
|
|
import { fetchUser, fetchProject, fetchRuns } from "@/util/data.js";
|
2019-06-11 10:06:06 +00:00
|
|
|
import { userDirectRunLink, projectRunLink } from "@/util/link.js";
|
2019-05-21 16:05:34 +00:00
|
|
|
import { runResultClass } from "@/util/run.js";
|
2018-12-09 13:21:20 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {},
|
|
|
|
|
name: "runs",
|
|
|
|
|
props: {
|
|
|
|
|
ownertype: String,
|
|
|
|
|
ownername: String,
|
2019-04-02 16:08:03 +00:00
|
|
|
projectref: Array,
|
2019-03-27 14:41:29 +00:00
|
|
|
query: String
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-05-23 21:37:52 +00:00
|
|
|
fetchRunsError: null,
|
2018-12-09 13:21:20 +00:00
|
|
|
runs: [],
|
2019-05-14 12:04:36 +00:00
|
|
|
wantedRunsNumber: 25,
|
|
|
|
|
hasMoreRuns: false,
|
2018-12-09 13:21:20 +00:00
|
|
|
polling: null,
|
|
|
|
|
project: null,
|
|
|
|
|
user: null
|
|
|
|
|
};
|
|
|
|
|
},
|
2019-03-27 14:41:29 +00:00
|
|
|
watch: {
|
2019-04-02 16:08:03 +00:00
|
|
|
$route: function() {
|
2019-03-27 14:41:29 +00:00
|
|
|
this.update();
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-12-09 13:21:20 +00:00
|
|
|
methods: {
|
|
|
|
|
projectRunLink: projectRunLink,
|
2019-06-11 10:06:06 +00:00
|
|
|
userDirectRunLink: userDirectRunLink,
|
2019-05-21 16:05:34 +00:00
|
|
|
runResultClass: runResultClass,
|
2018-12-09 13:21:20 +00:00
|
|
|
stillRunning(run) {
|
|
|
|
|
return run.result != "unknown" && run.phase == "running";
|
|
|
|
|
},
|
2019-04-08 15:43:34 +00:00
|
|
|
waitingApproval(run) {
|
|
|
|
|
return run.tasks_waiting_approval.length > 0;
|
|
|
|
|
},
|
2019-03-27 14:41:29 +00:00
|
|
|
update() {
|
|
|
|
|
clearInterval(this.polling);
|
2019-04-02 16:08:03 +00:00
|
|
|
if (this.projectref !== undefined) {
|
2019-03-27 14:41:29 +00:00
|
|
|
this.fetchProject();
|
|
|
|
|
} else {
|
2019-05-17 15:28:11 +00:00
|
|
|
this.fetchUser();
|
2019-03-27 14:41:29 +00:00
|
|
|
}
|
|
|
|
|
this.pollData();
|
|
|
|
|
},
|
2019-03-29 17:19:07 +00:00
|
|
|
async fetchProject() {
|
2019-05-13 14:29:47 +00:00
|
|
|
let projectref = [
|
|
|
|
|
this.ownertype,
|
|
|
|
|
this.ownername,
|
|
|
|
|
...this.projectref
|
|
|
|
|
].join("/");
|
|
|
|
|
|
|
|
|
|
let { data, error } = await fetchProject(projectref);
|
|
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.project = data;
|
2018-12-09 13:21:20 +00:00
|
|
|
|
2019-03-29 17:19:07 +00:00
|
|
|
this.fetchRuns();
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
2019-03-29 17:19:07 +00:00
|
|
|
async fetchUser() {
|
2019-05-17 15:28:11 +00:00
|
|
|
let { data, error } = await fetchUser(this.ownername);
|
2019-05-13 14:29:47 +00:00
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.user = data;
|
2018-12-09 13:21:20 +00:00
|
|
|
|
2019-03-29 17:19:07 +00:00
|
|
|
this.fetchRuns();
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
2019-05-14 12:04:36 +00:00
|
|
|
loadMoreRuns() {
|
|
|
|
|
this.wantedRunsNumber += 25;
|
|
|
|
|
this.fetchRuns();
|
|
|
|
|
},
|
|
|
|
|
// TODO(sgotti) use run events instead of refetching all runs everytime
|
2019-03-27 14:41:29 +00:00
|
|
|
async fetchRuns() {
|
|
|
|
|
let group;
|
|
|
|
|
let lastrun = false;
|
2018-12-09 13:21:20 +00:00
|
|
|
if (this.project !== null) {
|
2019-03-27 14:41:29 +00:00
|
|
|
if (this.query == "branches") {
|
2019-03-29 08:28:31 +00:00
|
|
|
group = "/project/" + this.project.id + "/branch";
|
2019-03-27 14:41:29 +00:00
|
|
|
} else if (this.query == "tags") {
|
2019-03-29 08:28:31 +00:00
|
|
|
group = "/project/" + this.project.id + "/tag";
|
2019-03-27 14:41:29 +00:00
|
|
|
} else if (this.query == "pullrequests") {
|
2019-03-29 08:28:31 +00:00
|
|
|
group = "/project/" + this.project.id + "/pr";
|
2019-03-27 14:41:29 +00:00
|
|
|
} else {
|
2019-03-29 08:28:31 +00:00
|
|
|
group = "/project/" + this.project.id;
|
2019-03-27 14:41:29 +00:00
|
|
|
}
|
2018-12-09 13:21:20 +00:00
|
|
|
} else if (this.user !== null) {
|
2019-03-29 08:28:31 +00:00
|
|
|
group = "/user/" + this.user.id;
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-14 12:04:36 +00:00
|
|
|
let newRuns = [];
|
|
|
|
|
let hasMoreRuns = false;
|
|
|
|
|
let stopFetch = false;
|
|
|
|
|
let runCount = 0;
|
|
|
|
|
let startRunID = null;
|
|
|
|
|
while (!stopFetch) {
|
|
|
|
|
let { data, error } = await fetchRuns(group, startRunID, lastrun);
|
|
|
|
|
if (error) {
|
2019-05-23 21:37:52 +00:00
|
|
|
this.fetchRunsError = error;
|
2019-05-14 12:04:36 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-05-23 21:37:52 +00:00
|
|
|
this.fetchRunsError = null;
|
2019-05-14 12:04:36 +00:00
|
|
|
runCount += data.length;
|
|
|
|
|
if (runCount >= this.wantedRunsNumber || data.length == 0) {
|
|
|
|
|
hasMoreRuns = data.length != 0;
|
|
|
|
|
stopFetch = true;
|
|
|
|
|
}
|
|
|
|
|
newRuns = newRuns.concat(data);
|
|
|
|
|
if (newRuns.length) {
|
|
|
|
|
startRunID = newRuns[newRuns.length - 1].id;
|
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
}
|
2019-05-14 12:04:36 +00:00
|
|
|
this.runs = newRuns;
|
|
|
|
|
this.hasMoreRuns = hasMoreRuns;
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
|
|
|
|
pollData() {
|
2019-03-27 14:41:29 +00:00
|
|
|
clearInterval(this.polling);
|
2018-12-09 13:21:20 +00:00
|
|
|
this.polling = setInterval(() => {
|
|
|
|
|
this.fetchRuns();
|
|
|
|
|
}, 2000);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function() {
|
2019-03-27 14:41:29 +00:00
|
|
|
this.update();
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
clearInterval(this.polling);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
</style>
|