-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OBS] add Open Build Service service-badge (#6993)
* service: add obs service * service: obs: replaced replaceAll with replace and global regex * service: obs: added space between class members * service: obs: support for multiple instances * service: obs: removed user prefix from auth vars obs_userName is now called obs_user and obs_userPass is called obs_pass Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com> * service: obs: removed constructor hack in favour of serviceKey * service: obs: apply suggestions from @calebcartwright * service: obs: remove unneccesary http status mappings Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e9153ab
commit 8a9efb2
Showing
10 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Joi from 'joi' | ||
import { | ||
isBuildStatus as gIsBuildStatus, | ||
renderBuildStatusBadge as gRenderBuildStatusBadge, | ||
} from '../build-status.js' | ||
|
||
const localStatuses = { | ||
blocked: 'inactive', | ||
disabled: 'inactive', | ||
finished: 'orange', | ||
'scheduled-warning': 'orange', | ||
signing: 'orange', | ||
unknown: 'inactive', | ||
unresolvable: 'red', | ||
} | ||
|
||
const isBuildStatus = Joi.alternatives().try( | ||
gIsBuildStatus, | ||
Joi.equal(...Object.keys(localStatuses)) | ||
) | ||
|
||
function renderBuildStatusBadge({ repository, status }) { | ||
const color = localStatuses[status] | ||
if (color) { | ||
return { | ||
message: status.toLowerCase(), | ||
color, | ||
} | ||
} else { | ||
return gRenderBuildStatusBadge({ status: status.toLowerCase() }) | ||
} | ||
} | ||
|
||
export { isBuildStatus, renderBuildStatusBadge } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Joi from 'joi' | ||
import { BaseXmlService } from '../index.js' | ||
import { optionalUrl } from '../validators.js' | ||
import { isBuildStatus, renderBuildStatusBadge } from './obs-build-status.js' | ||
|
||
const schema = Joi.object({ | ||
status: Joi.object({ | ||
'@_code': isBuildStatus, | ||
}).required(), | ||
}).required() | ||
|
||
export default class ObsService extends BaseXmlService { | ||
static category = 'build' | ||
static route = { | ||
base: 'obs', | ||
pattern: ':project/:packageName/:repository/:arch', | ||
queryParamSchema: Joi.object({ | ||
instance: optionalUrl, | ||
}).required(), | ||
} | ||
|
||
static auth = { | ||
userKey: 'obs_user', | ||
passKey: 'obs_pass', | ||
serviceKey: 'obs', | ||
isRequired: true, | ||
} | ||
|
||
static examples = [ | ||
{ | ||
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', | ||
}), | ||
keywords: ['open build service'], | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'build' } | ||
|
||
static render({ repository, status }) { | ||
return renderBuildStatusBadge({ repository, status }) | ||
} | ||
|
||
async fetch({ instance, project, packageName, repository, arch }) { | ||
return this._requestXml( | ||
this.authHelper.withBasicAuth({ | ||
schema, | ||
url: `${instance}/build/${project}/${repository}/${arch}/${packageName}/_status`, | ||
parserOptions: { | ||
ignoreAttributes: false, | ||
}, | ||
}) | ||
) | ||
} | ||
|
||
async handle( | ||
{ project, packageName, repository, arch }, | ||
{ instance = 'https://api.opensuse.org' } | ||
) { | ||
const resp = await this.fetch({ | ||
instance, | ||
project, | ||
packageName, | ||
repository, | ||
arch, | ||
}) | ||
return this.constructor.render({ | ||
repository, | ||
status: resp.status['@_code'], | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ServiceTester } from '../tester.js' | ||
import { noToken } from '../test-helpers.js' | ||
import ObsService from './obs.service.js' | ||
import { isBuildStatus } from './obs-build-status.js' | ||
|
||
export const t = new ServiceTester({ | ||
id: 'obs', | ||
title: 'openSUSE Open Build Service', | ||
}) | ||
|
||
t.create('status (valid)') | ||
.skipWhen(noToken(ObsService)) | ||
.get('/openSUSE:Factory/aaa_base/standard/x86_64.json?label=standard') | ||
.expectBadge({ | ||
label: 'standard', | ||
message: isBuildStatus, | ||
}) | ||
|
||
t.create('status (invalid)') | ||
.skipWhen(noToken(ObsService)) | ||
.get('/home:sp1rit/this_package_will_never_exist/repo/arch.json') | ||
.expectBadge({ | ||
label: 'build', | ||
message: 'not found', | ||
}) |