Gerrit config: Make the apiBaseUrl optional
If the apiBaseUrl is not set assume that the gerrit instance uses https and can be reached on the address specified by the "host" option. Signed-off-by: Niklas Aronsson <niklasar@axis.com>
This commit is contained in:
@@ -29,8 +29,9 @@ you can list the Gerrit instances you want to fetch data from. Each entry is
|
||||
a structure with up to four elements:
|
||||
|
||||
- `host`: The host of the Gerrit instance, e.g. `gerrit.company.com`.
|
||||
- `apiBaseUrl`: The base url of the Gerrit API. This would typically be the address
|
||||
up to but not including the authentication ("/a/") prefix.
|
||||
- `apiBaseUrl` (optional): Needed if the Gerrit instance is not reachable at
|
||||
the base of the `host` option (e.g. `https://gerrit.company.com`). This is
|
||||
the address that you would open in a browser.
|
||||
- `username` (optional): The Gerrit username to use in API requests. If
|
||||
neither a username nor password are supplied, anonymous access will be used.
|
||||
- `password` (optional): The password or http token for the Gerrit user.
|
||||
|
||||
@@ -97,6 +97,8 @@ nav:
|
||||
- Discovery: 'integrations/bitbucket/discovery.md'
|
||||
- Datadog:
|
||||
- Installation: 'integrations/datadog-rum/installation.md'
|
||||
- Gerrit:
|
||||
- Locations: 'integrations/gerrit/locations.md'
|
||||
- GitHub:
|
||||
- Locations: 'integrations/github/locations.md'
|
||||
- Discovery: 'integrations/github/discovery.md'
|
||||
|
||||
@@ -136,7 +136,7 @@ export class GerritIntegration implements ScmIntegration {
|
||||
// @public
|
||||
export type GerritIntegrationConfig = {
|
||||
host: string;
|
||||
apiBaseUrl: string;
|
||||
apiBaseUrl?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
Vendored
+1
-1
@@ -68,7 +68,7 @@ export interface Config {
|
||||
*/
|
||||
host: string;
|
||||
/**
|
||||
* The base url for the Gerrit API.
|
||||
* The base url for the Gerrit instance.
|
||||
* @visibility frontend
|
||||
*/
|
||||
apiBaseUrl?: string;
|
||||
|
||||
@@ -68,12 +68,23 @@ describe('readGerritIntegrationConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can create a default value if the API base URL is missing', () => {
|
||||
const output = readGerritIntegrationConfig(
|
||||
buildConfig({
|
||||
host: 'a.com',
|
||||
}),
|
||||
);
|
||||
expect(output).toEqual({
|
||||
host: 'a.com',
|
||||
apiBaseUrl: 'https://a.com',
|
||||
username: undefined,
|
||||
password: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects funky configs', () => {
|
||||
const valid: any = {
|
||||
host: 'a.com',
|
||||
apiBaseUrl: 'https://a.com/api',
|
||||
username: 'u',
|
||||
appPassword: 'p',
|
||||
};
|
||||
expect(() =>
|
||||
readGerritIntegrationConfig(buildConfig({ ...valid, host: 2 })),
|
||||
|
||||
@@ -30,10 +30,13 @@ export type GerritIntegrationConfig = {
|
||||
host: string;
|
||||
|
||||
/**
|
||||
* The base URL of the API of this provider, e.g. "https://gerrit-review.com/gerrit",
|
||||
* with no trailing slash.
|
||||
* The optional base URL of the Gerrit instance. It is assumed that https
|
||||
* is used and that the base path is "/" on the host. If that is not the
|
||||
* case set the complete base url to the gerrit instance, e.g.
|
||||
* "https://gerrit-review.com/gerrit". This is the url that you would open
|
||||
* in a browser.
|
||||
*/
|
||||
apiBaseUrl: string;
|
||||
apiBaseUrl?: string;
|
||||
|
||||
/**
|
||||
* The username to use for requests to gerrit.
|
||||
@@ -57,7 +60,7 @@ export function readGerritIntegrationConfig(
|
||||
config: Config,
|
||||
): GerritIntegrationConfig {
|
||||
const host = config.getString('host');
|
||||
let apiBaseUrl = config.getString('apiBaseUrl');
|
||||
let apiBaseUrl = config.getOptionalString('apiBaseUrl');
|
||||
const username = config.getOptionalString('username');
|
||||
const password = config.getOptionalString('password');
|
||||
|
||||
@@ -65,13 +68,15 @@ export function readGerritIntegrationConfig(
|
||||
throw new Error(
|
||||
`Invalid Gerrit integration config, '${host}' is not a valid host`,
|
||||
);
|
||||
} else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {
|
||||
} else if (apiBaseUrl && !isValidUrl(apiBaseUrl)) {
|
||||
throw new Error(
|
||||
`Invalid Gerrit integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,
|
||||
);
|
||||
}
|
||||
if (apiBaseUrl) {
|
||||
apiBaseUrl = trimEnd(apiBaseUrl, '/');
|
||||
} else {
|
||||
apiBaseUrl = `https://${host}`;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user