Skip to content

Commit 6b2747f

Browse files
committed
updated Format and allow single repo listing
1 parent 120c351 commit 6b2747f

File tree

2 files changed

+76
-36
lines changed

2 files changed

+76
-36
lines changed

docs/widgets.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,8 @@ Display the last builds from a [Drone CI](https://www.drone.ci) instance. A self
19231923
--- | --- | --- | ---
19241924
**`host`** | `string` | Required | The histname of the Drone CI instance.
19251925
**`apiKey`** | `string` | Required | The API key (https://<your-drone-instance>/account).
1926-
**`limit`** | `integer` | Optional | Limit the amounts of listed builds.
1926+
**`limit`** | `integer` | _Optional_ | Limit the amounts of listed builds.
1927+
**`repo`** | `string` | _Optional_ | Show only builds of the specified repo
19271928

19281929
#### Example
19291930

src/components/Widgets/DroneCi.vue

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
>
88
<div class="status">
99
<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>
1013
</div>
1114
<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>
2829
</div>
2930
</div>
3031
</div>
@@ -60,9 +61,21 @@ export default {
6061
},
6162
computed: {
6263
/* API endpoint, either for self-hosted or managed instance */
63-
endpoint() {
64+
endpointBuilds() {
6465
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;
6679
},
6780
apiKey() {
6881
if (!this.options.apiKey) {
@@ -82,17 +95,35 @@ export default {
8295
fetchData() {
8396
this.overrideProxyChoice = true;
8497
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+
}
88113
},
89114
/* Assign data variables to the returned data */
90-
processData(data) {
115+
processBuilds(data) {
91116
const results = data.slice(0, this.options.limit).map(obj => {
92117
return {...obj, baseurl: this.options.host};
93118
});
94119
this.builds = results;
95120
},
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+
},
96127
infoTooltip(build) {
97128
const content = `<b>Trigger:</b> ${build.build.event} by ${build.build.trigger}<br>`
98129
+ `<b>Repo:</b> ${build.slug}<br>`
@@ -115,12 +146,12 @@ export default {
115146
.droneci-builds-wrapper {
116147
color: var(--widget-text-color);
117148
.build-row {
118-
display: flex;
149+
display: grid;
150+
grid-template-columns: 1fr 2fr;
119151
justify-content: left;
120152
align-items: center;
121153
padding: 0.25rem 0;
122154
.status {
123-
min-width: 5rem;
124155
font-size: 1rem;
125156
font-weight: bold;
126157
p {
@@ -131,35 +162,43 @@ export default {
131162
&.error { color: var(--danger); }
132163
&.running { color: var(--neutral); }
133164
}
165+
span {
166+
font-size: 0.75rem;
167+
color: var(--secondary);
168+
}
134169
}
135170
.info {
136-
p.build-name {
171+
div.build-name {
137172
margin: 0.25rem 0;
138173
font-weight: bold;
139174
color: var(--widget-text-color);
140175
a, a:hover, a:visited, a:active {
141176
color: inherit;
142177
text-decoration: none;
143178
}
179+
.droneci-build-number::before {
180+
content: "#";
181+
}
144182
}
145-
p.build-desc {
183+
div.build-desc {
146184
margin: 0;
185+
font-size: 0.85rem;
147186
color: var(--widget-text-color);
148187
opacity: var(--dimming-factor);
149188
a, a:hover, a:visited, a:active {
150189
color: inherit;
151190
text-decoration: none;
152191
}
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+
}
159200
}
160-
}
161-
p.build-desc::before {
162-
content: "#";
201+
163202
}
164203
}
165204
&:not(:last-child) {

0 commit comments

Comments
 (0)