This repository was archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
145 lines (133 loc) · 4.88 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Camptocamp.org developement builds</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<style>
</style>
</head>
<body>
<section id="app" class="section">
<div class="container">
<div class="columns is-mobile">
<div class="column is-6">
</div>
<div class="column is-6">
</div>
</div>
<h1 class="title">
Camptocamp.org UI - Build list
</h1>
<p class="subtitle">
Here is the list of active builds
</p>
<div class="notification info" v-if="!branches">Loading</div>
<ul v-else>
<li v-for="branch of branches" :key="branch.name">
<span v-if="branch.buildIsReady === undefined" class="icon has-text-warning" key="1">
<i class="fas fa-hourglass"></i>
</span>
<span v-else-if="branch.buildIsReady === false" class="icon has-text-danger" key="2">
<i class="fas fa-skull"></i>
</span>
<span v-else-if="branch.buildIsReady === true" class="icon has-text-success" key="3">
<i class="fas fa-check-circle"></i>
</span>
<a :href="branch.githubPageUrl" :class="{'has-text-danger': branch.buildIsReady === false}">
<span>{{ branch.name }}</span>
</a>
<span>
->
</span>
<em v-if="branch.pull === undefined">Getting pull request</em>
<em v-else-if="branch.pull === null" class="has-text-warning">There is not PR for this branch</em>
<span v-else>
<a :href="branch.pull.html_url">
Pull request
</a>
<span>by</span>
<a :href="branch.pull.user.html_url">
{{ branch.pull.user.login }} :
</a>
<em>
{{ branch.pull.title }}
</em>
</span>
</li>
</ul>
</div>
</section>
<script>
const ORG_NAME = 'c2corg';
const REPO_NAME = 'CI-CD-test';
const REPO_SLUG = `${ORG_NAME}/${REPO_NAME}`;
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
branches: null,
pulls: null,
githubPageContent: null,
},
created(){
axios.get(`https://api.github.com/repos/${REPO_SLUG}/branches`)
.then((response) => {
this.branches = response.data.filter((branch) => branch.name !== 'gh-pages');
this.branches.map(this.initBranch);
this.dispatchContents();
this.dispatchPulls();
})
axios.get(`https://api.github.com/repos/${REPO_SLUG}/contents?ref=gh-pages`)
.then((response) => {
this.githubPageContent = response.data;
this.dispatchContents();
})
axios.get(`https://api.github.com/repos/${REPO_SLUG}/pulls`)
.then((response) => {
this.pulls = response.data;
this.dispatchPulls();
})
},
methods: {
initBranch(branch){
const url = `https://${ORG_NAME}.github.io/${REPO_NAME}/${branch.name}`;
this.$set(branch, "githubPageUrl", url)
this.$set(branch, "buildIsReady", undefined);
this.$set(branch, "pull", undefined);
},
dispatchPulls(){
if (!this.branches || !this.pulls){
return;
}
this.branches.map((branch) => { branch.pull = null });
const branches = {}
this.branches.map((branch) => { branches[branch.name] = branch });
for (const pull of this.pulls){
if (branches[pull.head.ref] !== undefined) {
branches[pull.head.ref].pull = pull;
}
}
},
dispatchContents(){
if (!this.branches || !this.githubPageContent){
return;
}
this.branches.map((branch) => { branch.buildIsReady = false });
const branches = {}
this.branches.map((branch) => { branches[branch.name] = branch });
for (const item of this.githubPageContent.filter((item) => item.type === 'dir')){
if (branches[item.name] !== undefined) {
branches[item.name].buildIsReady = true;
}
}
}
}
})
</script>
</body>
</html>