Skip to content

Commit

Permalink
service: obs: apply suggestions from @calebcartwright
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1ritCS committed Sep 25, 2021
1 parent 10e33d1 commit 3add9f3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 64 deletions.
1 change: 1 addition & 0 deletions services/build-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const greenStatuses = [
const orangeStatuses = ['partially succeeded', 'unstable', 'timeout']

const redStatuses = [
'broken',
'error',
'errored',
'failed',
Expand Down
1 change: 1 addition & 0 deletions services/build-status.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test(renderBuildStatusBadge, () => {

test(renderBuildStatusBadge, () => {
forCases([
given({ status: 'broken' }),
given({ status: 'error' }),
given({ status: 'errored' }),
given({ status: 'failed' }),
Expand Down
83 changes: 24 additions & 59 deletions services/obs/obs-build-status.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,34 @@
import Joi from 'joi'
import {
isBuildStatus as gIsBuildStatus,
renderBuildStatusBadge as gRenderBuildStatusBadge,
} from '../build-status.js'

// colors from OBS webinterface
/* const statusmap = {
//Green
succeeded: "#008000",
// Blue
building: "#069",
// Cyan
scheduled: "#007a7c",
// Yellow
signing: "#f0ad4e",
finished: "#f0ad4e",
// Red
unresolvable: "#dc3545",
broken: "#dc3545",
failed: "#dc3545",
// Gray
disabled: "#6c757d",
blocked: "#6c757d",
// Orange
"scheduled-warning": "#a50",
unknown: "#a50"
} */

// shields colors
const statusmap = {
// Green
succeeded: 'success',
// Blue
building: 'blue',
// Cyan
scheduled: '#007a7c',
// Yellow
signing: 'yellow',
finished: 'yellow',
// Red
unresolvable: 'critical',
broken: 'critical',
failed: 'critical',
// Gray
disabled: 'inactive',
const localStatuses = {
blocked: 'inactive',
// Orange
'scheduled-warning': 'important',
unknown: 'lightgray',
disabled: 'inactive',
finished: 'orange',
'scheduled-warning': 'orange',
signing: 'orange',
unknown: 'inactive',
unresolvable: 'red',
}

const isBuildStatus = Joi.equal(...Object.keys(statusmap))
function getIsMessageStatus() {
const status = []
Object.keys(statusmap).forEach(key =>
status.push(key.charAt(0).toUpperCase() + key.slice(1))
)

return Joi.equal(...status)
}
const isBuildStatus = Joi.alternatives().try(
gIsBuildStatus,
Joi.equal(...Object.keys(localStatuses))
)

function renderBuildStatusBadge({ repository, status }) {
const color = statusmap[status]

return {
label: repository.replace(/_/g, ' '),
message: status.charAt(0).toUpperCase() + status.slice(1),
color,
const color = localStatuses[status]
if (color) {
return {
message: status.toLowerCase(),
color,
}
} else {
return gRenderBuildStatusBadge({ status: status.toLowerCase() })
}
}

export { isBuildStatus, getIsMessageStatus, renderBuildStatusBadge }
export { isBuildStatus, renderBuildStatusBadge }
5 changes: 3 additions & 2 deletions services/obs/obs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export default class ObsService extends BaseXmlService {

static examples = [
{
title: 'openSUSE OBS package build status',
title: 'OBS package build status',
namedParams: {
project: 'openSUSE:Tools',
packageName: 'osc',
repository: 'Debian_11',
arch: 'x86_64',
},
queryParams: { instance: 'https://api.opensuse.org' },
staticPreview: this.render({
repository: 'Debian_11',
status: 'succeeded',
Expand All @@ -43,7 +44,7 @@ export default class ObsService extends BaseXmlService {
},
]

static defaultBadgeData = { label: 'OBS' }
static defaultBadgeData = { label: 'build' }

static render({ repository, status }) {
return renderBuildStatusBadge({ repository, status })
Expand Down
6 changes: 3 additions & 3 deletions services/obs/obs.tester.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceTester } from '../tester.js'
import { noToken } from '../test-helpers.js'
import ObsService from './obs.service.js'
import { getIsMessageStatus } from './obs-build-status.js'
import { isBuildStatus } from './obs-build-status.js'

export const t = new ServiceTester({
id: 'obs',
Expand All @@ -10,10 +10,10 @@ export const t = new ServiceTester({

t.create('status (valid)')
.skipWhen(noToken(ObsService))
.get('/openSUSE:Factory/aaa_base/standard/x86_64.json')
.get('/openSUSE:Factory/aaa_base/standard/x86_64.json?label=standard')
.expectBadge({
label: 'standard',
message: getIsMessageStatus(),
message: isBuildStatus,
})

t.create('status (invalid)')
Expand Down

0 comments on commit 3add9f3

Please sign in to comment.