7
7
>
8
8
<div class =" status" >
9
9
<p :class =" build.build.status" >{{ build.build.status | formatStatus }}</p >
10
+ <span v-if =" build.status == 'running'" >{{ build.build.started*1000 | formatTimeAgo }} ago</span >
11
+ <span v-else-if =" build.status != 'pending' " >{{ formatBuildDuration(build) }}</span >
12
+ <span v-else >{{ build.build.created*1000 | formatTimeAgo }} ago</span >
10
13
</div >
11
14
<div class =" info" >
12
- <p class =" build-name" ><a :href =" build.git_http_url" target =" _blank" >{{ build.name }}</a ></p >
13
- <p class =" build-desc" >
14
- <a :href =" build.baseurl + '/' + build.slug + '/' +build.build.number" target =" _blank" >{{ build.build.number }}</a >
15
- <template v-if =" build .event == ' pull_request' " >
16
- <a :href =" build.build.link" target =" _blank" class =" droneci-extra-info" >#{{ formatPrId(build.build.link) }}</a > to <span class =" droneci-info-link" >{{ build.build.target }}</span >
17
- </template >
18
- <template v-if =" build .event == ' push' " >
19
- <a :href =" build.build.link" target =" _blank" class =" droneci-extra-info" >push</a > to <span class =" droneci-extra-info" >{{ build.build.target }}</span >
20
- </template >
21
- <template v-else >
22
- <span class =" droneci-extra-info" >{{ build.build.target }}</span >
23
- </template >
24
- <span v-if =" build.status == 'running'" >{{ build.build.started*1000 | formatTimeAgo }}</span >
25
- <span v-else-if =" build.status != 'running' || build.status != 'pending' " >{{ formatBuildDuration(build) }}</span >
26
- <span v-else >Missing Time</span >
27
- </p >
15
+ <div class =" build-name" >
16
+ {{ build.name }} <a class =" droneci-build-number" :href =" build.baseurl + '/' + build.slug + '/' +build.build.number" target =" _blank" >{{ build.build.number }}</a >
17
+ </div >
18
+ <div class =" build-desc" >
19
+ <span class =" droneci-extra" >
20
+ <template v-if =" build .build .event == ' pull_request' " >
21
+ <a :href =" build.build.link" target =" _blank" class =" droneci-extra-info" >#{{ formatPrId(build.build.link) }}</a > to
22
+ </template >
23
+ <template v-else-if =" build .build .event == ' push' " >
24
+ <a :href =" build.build.link" target =" _blank" class =" droneci-extra-info" >push</a > to
25
+ </template >
26
+ <a :href =" build.git_http_url" target =" _blank" class =" droneci-extra-info" >{{ build.build.target }}</a >
27
+ </span >
28
+ </div >
28
29
</div >
29
30
</div >
30
31
</div >
@@ -60,9 +61,21 @@ export default {
60
61
},
61
62
computed: {
62
63
/* API endpoint, either for self-hosted or managed instance */
63
- endpoint () {
64
+ endpointBuilds () {
64
65
if (this .options .host ) return ` ${ this .options .host } /api/user/builds` ;
65
- this .error (' Drone CI Host is required' );
66
+ this .error (' drone.ci Host is required' );
67
+ },
68
+ endpointRepoInfo () {
69
+ if (! this .options .host ) this .error (' drone.ci Host is required' );
70
+ return ` ${ this .options .host } /api/repos/${ this .options .repo } ` ;
71
+ },
72
+ endpointRepoBuilds () {
73
+ if (! this .options .host ) this .error (' drone.ci Host is required' );
74
+ return ` ${ this .options .host } /api/repos/${ this .options .repo } /builds` ;
75
+ },
76
+ repo (){
77
+ if (this .options .repo ) return this .options .repo ;
78
+ return false ;
66
79
},
67
80
apiKey () {
68
81
if (! this .options .apiKey ) {
@@ -82,17 +95,35 @@ export default {
82
95
fetchData () {
83
96
this .overrideProxyChoice = true ;
84
97
const authHeaders = { ' Authorization' : ` Bearer ${ this .apiKey } ` };
85
- this .makeRequest (this .endpoint , authHeaders).then (
86
- (response ) => { this .processData (response); },
87
- );
98
+ if (this .repo !== false ){
99
+ this .makeRequest (this .endpointRepoInfo , authHeaders).then (
100
+ (repoInfo ) => {
101
+ this .makeRequest (this .endpointRepoBuilds , authHeaders).then (
102
+ (buildInfo ) => {
103
+ this .processRepoBuilds (repoInfo, buildInfo);
104
+ },
105
+ );
106
+ },
107
+ );
108
+ }else {
109
+ this .makeRequest (this .endpointBuilds , authHeaders).then (
110
+ (response ) => { this .processBuilds (response); },
111
+ );
112
+ }
88
113
},
89
114
/* Assign data variables to the returned data */
90
- processData (data ) {
115
+ processBuilds (data ) {
91
116
const results = data .slice (0 , this .options .limit ).map (obj => {
92
117
return {... obj, baseurl: this .options .host };
93
118
});
94
119
this .builds = results;
95
120
},
121
+ processRepoBuilds (repo , builds ) {
122
+ const results = builds .slice (0 , this .options .limit ).map (obj => {
123
+ return {build: {... obj}, baseurl: this .options .host , ... repo};
124
+ });
125
+ this .builds = results;
126
+ },
96
127
infoTooltip (build ) {
97
128
const content = ` <b>Trigger:</b> ${ build .build .event } by ${ build .build .trigger } <br>`
98
129
+ ` <b>Repo:</b> ${ build .slug } <br>`
@@ -115,12 +146,12 @@ export default {
115
146
.droneci-builds-wrapper {
116
147
color : var (--widget-text-color );
117
148
.build-row {
118
- display : flex ;
149
+ display : grid ;
150
+ grid-template-columns : 1fr 2fr ;
119
151
justify-content : left ;
120
152
align-items : center ;
121
153
padding : 0.25rem 0 ;
122
154
.status {
123
- min-width : 5rem ;
124
155
font-size : 1rem ;
125
156
font-weight : bold ;
126
157
p {
@@ -131,35 +162,43 @@ export default {
131
162
& .error { color : var (--danger ); }
132
163
& .running { color : var (--neutral ); }
133
164
}
165
+ span {
166
+ font-size : 0.75rem ;
167
+ color : var (--secondary );
168
+ }
134
169
}
135
170
.info {
136
- p .build-name {
171
+ div .build-name {
137
172
margin : 0.25rem 0 ;
138
173
font-weight : bold ;
139
174
color : var (--widget-text-color );
140
175
a , a :hover , a :visited , a :active {
141
176
color : inherit ;
142
177
text-decoration : none ;
143
178
}
179
+ .droneci-build-number ::before {
180
+ content : " #" ;
181
+ }
144
182
}
145
- p .build-desc {
183
+ div .build-desc {
146
184
margin : 0 ;
185
+ font-size : 0.85rem ;
147
186
color : var (--widget-text-color );
148
187
opacity : var (--dimming-factor );
149
188
a , a :hover , a :visited , a :active {
150
189
color : inherit ;
151
190
text-decoration : none ;
152
191
}
153
- .droneci-extra-info {
154
- margin : 0.25em ;
155
- padding : 0.25em ;
156
- background : var (--item-background );
157
- border : 1px solid var (--primary );
158
- border-radius : 5px ;
192
+ .droneci-extra {
193
+ .droneci-extra-info {
194
+ margin : 0.25em ;
195
+ padding : 0em 0.25em ;
196
+ background : var (--item-background );
197
+ border : 1px solid var (--primary );
198
+ border-radius : 5px ;
199
+ }
159
200
}
160
- }
161
- p .build-desc ::before {
162
- content : " #" ;
201
+
163
202
}
164
203
}
165
204
& :not (:last-child ) {
0 commit comments