From 0948a3f8458883b2863aeb15a78ef746be58fbe8 Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Sun, 8 Jan 2023 08:58:08 +0100 Subject: [PATCH] updated Format and allow single repo listing --- docs/widgets.md | 3 +- src/components/Widgets/DroneCi.vue | 149 ++++++++++++++++++++--------- 2 files changed, 107 insertions(+), 45 deletions(-) diff --git a/docs/widgets.md b/docs/widgets.md index a1cd1543..8c06120b 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -1923,7 +1923,8 @@ Display the last builds from a [Drone CI](https://www.drone.ci) instance. A self --- | --- | --- | --- **`host`** | `string` | Required | The histname of the Drone CI instance. **`apiKey`** | `string` | Required | The API key (https:///account). -**`limit`** | `integer` | Optional | Limit the amounts of listed builds. +**`limit`** | `integer` | _Optional_ | Limit the amounts of listed builds. +**`repo`** | `string` | _Optional_ | Show only builds of the specified repo #### Example diff --git a/src/components/Widgets/DroneCi.vue b/src/components/Widgets/DroneCi.vue index 8d9259e5..4bd32ded 100644 --- a/src/components/Widgets/DroneCi.vue +++ b/src/components/Widgets/DroneCi.vue @@ -7,24 +7,50 @@ >

{{ build.build.status | formatStatus }}

+ + {{ build.build.started*1000 | formatTimeAgo }} ago + + + {{ formatBuildDuration(build) }} + + + {{ build.build.created*1000 | formatTimeAgo }} ago +
-

{{ build.name }}

-

- {{ build.build.number }} - - - - {{ build.build.started*1000 | formatTimeAgo }} - {{ formatBuildDuration(build) }} - Missing Time -

+
+ {{ build.name }} + {{ build.build.number }} +
+
@@ -60,9 +86,21 @@ export default { }, computed: { /* API endpoint, either for self-hosted or managed instance */ - endpoint() { - if (this.options.host) return `${this.options.host}/api/user/builds`; - this.error('Drone CI Host is required'); + endpointBuilds() { + if (!this.options.host) this.error('drone.ci Host is required'); + return `${this.options.host}/api/user/builds`; + }, + endpointRepoInfo() { + if (!this.options.host) this.error('drone.ci Host is required'); + return `${this.options.host}/api/repos/${this.options.repo}`; + }, + endpointRepoBuilds() { + if (!this.options.host) this.error('drone.ci Host is required'); + return `${this.options.host}/api/repos/${this.options.repo}/builds`; + }, + repo() { + if (this.options.repo) return this.options.repo; + return false; }, apiKey() { if (!this.options.apiKey) { @@ -80,23 +118,38 @@ export default { }, /* Make GET request to Drone CI API endpoint */ fetchData() { - this.overrideProxyChoice = true; - const authHeaders = { 'Authorization': `Bearer ${this.apiKey}` }; - this.makeRequest(this.endpoint, authHeaders).then( - (response) => { this.processData(response); }, - ); + const authHeaders = { Authorization: `Bearer ${this.apiKey}` }; + if (this.repo !== false) { + this.makeRequest(this.endpointRepoInfo, authHeaders).then( + (repoInfo) => { + this.makeRequest(this.endpointRepoBuilds, authHeaders).then( + (buildInfo) => { + this.processRepoBuilds(repoInfo, buildInfo); + }, + ); + }, + ); + } else { + this.makeRequest(this.endpointBuilds, authHeaders).then( + (response) => { this.processBuilds(response); }, + ); + } }, /* Assign data variables to the returned data */ - processData(data) { - const results = data.slice(0, this.options.limit).map(obj => { - return {...obj, baseurl: this.options.host}; - }); + processBuilds(data) { + const results = data.slice(0, this.options.limit) + .map((obj) => ({ ...obj, baseurl: this.options.host })); + this.builds = results; + }, + processRepoBuilds(repo, builds) { + const results = builds.slice(0, this.options.limit) + .map((obj) => ({ build: { ...obj }, baseurl: this.options.host, ...repo })); this.builds = results; }, infoTooltip(build) { const content = `Trigger: ${build.build.event} by ${build.build.trigger}
` + `Repo: ${build.slug}
` - + `Branch: ${build.build.target}
` + + `Branch: ${build.build.target}
`; return { content, html: true, trigger: 'hover focus', delay: 250, classes: 'build-info-tt', }; @@ -104,8 +157,8 @@ export default { formatPrId(link) { return link.split('/').pop(); }, - formatBuildDuration(build){ - return getTimeDifference(build.build.started*1000, build.build.finished*1000); + formatBuildDuration(build) { + return getTimeDifference(build.build.started * 1000, build.build.finished * 1000); }, }, }; @@ -115,12 +168,12 @@ export default { .droneci-builds-wrapper { color: var(--widget-text-color); .build-row { - display: flex; + display: grid; + grid-template-columns: 1fr 2.5fr; justify-content: left; align-items: center; padding: 0.25rem 0; .status { - min-width: 5rem; font-size: 1rem; font-weight: bold; p { @@ -131,9 +184,13 @@ export default { &.error { color: var(--danger); } &.running { color: var(--neutral); } } + span { + font-size: 0.75rem; + color: var(--secondary); + } } .info { - p.build-name { + div.build-name { margin: 0.25rem 0; font-weight: bold; color: var(--widget-text-color); @@ -141,25 +198,29 @@ export default { color: inherit; text-decoration: none; } + .droneci-build-number::before { + content: "#"; + } } - p.build-desc { + div.build-desc { margin: 0; + font-size: 0.85rem; color: var(--widget-text-color); opacity: var(--dimming-factor); a, a:hover, a:visited, a:active { color: inherit; text-decoration: none; } - .droneci-extra-info { - margin: 0.25em; - padding: 0.25em; - background: var(--item-background); - border: 1px solid var(--primary); - border-radius: 5px; + .droneci-extra { + .droneci-extra-info { + margin: 0.25em; + padding: 0em 0.25em; + background: var(--item-background); + border: 1px solid var(--primary); + border-radius: 5px; + } } - } - p.build-desc::before { - content: "#"; + } } &:not(:last-child) {