Files
shields/services/teamcity/teamcity-base.js
Paul Melnikow 226fa67a02 Create shortcut for BaseService-related imports (#2809)
Continue to implement #2698:

- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
2019-01-21 15:41:24 -05:00

45 lines
1.1 KiB
JavaScript

'use strict'
const serverSecrets = require('../../lib/server-secrets')
const { BaseJsonService } = require('..')
module.exports = class TeamCityBase extends BaseJsonService {
async fetch({
protocol,
hostAndPath,
apiPath,
schema,
qs = {},
errorMessages = {},
}) {
if (!hostAndPath) {
// If hostAndPath is undefined then the user specified the legacy default path
protocol = 'https'
hostAndPath = 'teamcity.jetbrains.com'
}
const url = `${protocol}://${hostAndPath}/${apiPath}`
const options = { qs }
// JetBrains API Auth Docs: https://confluence.jetbrains.com/display/TCD18/REST+API#RESTAPI-RESTAuthentication
if (serverSecrets.teamcity_user) {
options.auth = {
user: serverSecrets.teamcity_user,
pass: serverSecrets.teamcity_pass,
}
} else {
qs.guest = 1
}
const defaultErrorMessages = {
404: 'build not found',
}
const errors = { ...defaultErrorMessages, ...errorMessages }
return this._requestJson({
url,
schema,
options,
errorMessages: errors,
})
}
}