feat(gerrit): make the gitilesBaseUrl config mandatory
Signed-off-by: Niklas Aronsson <niklasar@axis.com>
This commit is contained in:
@@ -326,7 +326,7 @@ export type GerritIntegrationConfig = {
|
||||
host: string;
|
||||
baseUrl?: string;
|
||||
cloneUrl?: string;
|
||||
gitilesBaseUrl?: string;
|
||||
gitilesBaseUrl: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
Vendored
+5
@@ -151,6 +151,11 @@ export interface Config {
|
||||
* @visibility frontend
|
||||
*/
|
||||
baseUrl?: string;
|
||||
/**
|
||||
* The gitiles base url.
|
||||
* @visibility frontend
|
||||
*/
|
||||
gitilesBaseUrl: string;
|
||||
/**
|
||||
* The base url for cloning repos.
|
||||
* @visibility frontend
|
||||
|
||||
@@ -27,6 +27,8 @@ describe('GerritIntegration', () => {
|
||||
host: 'gerrit-review.example.com',
|
||||
username: 'gerrituser',
|
||||
baseUrl: 'https://gerrit-review.example.com/gerrit',
|
||||
gitilesBaseUrl:
|
||||
'https://gerrit-review.example.com/gerrit/plugins/gitiles',
|
||||
password: '1234',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -76,13 +76,14 @@ describe('readGerritIntegrationConfig', () => {
|
||||
const output = readGerritIntegrationConfig(
|
||||
buildConfig({
|
||||
host: 'a.com',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
}),
|
||||
);
|
||||
expect(output).toEqual({
|
||||
host: 'a.com',
|
||||
baseUrl: 'https://a.com',
|
||||
cloneUrl: 'https://a.com',
|
||||
gitilesBaseUrl: 'https://a.com',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
username: undefined,
|
||||
password: undefined,
|
||||
});
|
||||
@@ -106,6 +107,7 @@ describe('readGerritIntegrationConfig', () => {
|
||||
await buildFrontendConfig({
|
||||
host: 'a.com',
|
||||
baseUrl: 'https://a.com/gerrit',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
username: 'u',
|
||||
password: 'p',
|
||||
}),
|
||||
@@ -114,7 +116,7 @@ describe('readGerritIntegrationConfig', () => {
|
||||
host: 'a.com',
|
||||
baseUrl: 'https://a.com/gerrit',
|
||||
cloneUrl: 'https://a.com/gerrit',
|
||||
gitilesBaseUrl: 'https://a.com',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -130,12 +132,14 @@ describe('readGerritIntegrationConfigs', () => {
|
||||
{
|
||||
host: 'a.com',
|
||||
baseUrl: 'https://a.com/api',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
username: 'u',
|
||||
password: 'p',
|
||||
},
|
||||
{
|
||||
host: 'b.com',
|
||||
baseUrl: 'https://b.com/api',
|
||||
gitilesBaseUrl: 'https://b.com/gerrit/plugins/gitiles',
|
||||
},
|
||||
]),
|
||||
);
|
||||
@@ -144,7 +148,7 @@ describe('readGerritIntegrationConfigs', () => {
|
||||
host: 'a.com',
|
||||
baseUrl: 'https://a.com/api',
|
||||
cloneUrl: 'https://a.com/api',
|
||||
gitilesBaseUrl: 'https://a.com',
|
||||
gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles',
|
||||
username: 'u',
|
||||
password: 'p',
|
||||
},
|
||||
@@ -152,7 +156,7 @@ describe('readGerritIntegrationConfigs', () => {
|
||||
host: 'b.com',
|
||||
baseUrl: 'https://b.com/api',
|
||||
cloneUrl: 'https://b.com/api',
|
||||
gitilesBaseUrl: 'https://b.com',
|
||||
gitilesBaseUrl: 'https://b.com/gerrit/plugins/gitiles',
|
||||
username: undefined,
|
||||
password: undefined,
|
||||
},
|
||||
|
||||
@@ -45,12 +45,11 @@ export type GerritIntegrationConfig = {
|
||||
cloneUrl?: string;
|
||||
|
||||
/**
|
||||
* Optional base url for Gitiles. This is needed for creating a valid
|
||||
* Base url for Gitiles. This is needed for creating a valid
|
||||
* user-friendly url that can be used for browsing the content of the
|
||||
* provider. If not set a default value will be created in the same way
|
||||
* as the "baseUrl" option.
|
||||
* provider.
|
||||
*/
|
||||
gitilesBaseUrl?: string;
|
||||
gitilesBaseUrl: string;
|
||||
|
||||
/**
|
||||
* The username to use for requests to gerrit.
|
||||
@@ -76,7 +75,7 @@ export function readGerritIntegrationConfig(
|
||||
const host = config.getString('host');
|
||||
let baseUrl = config.getOptionalString('baseUrl');
|
||||
let cloneUrl = config.getOptionalString('cloneUrl');
|
||||
let gitilesBaseUrl = config.getOptionalString('gitilesBaseUrl');
|
||||
let gitilesBaseUrl = config.getString('gitilesBaseUrl');
|
||||
const username = config.getOptionalString('username');
|
||||
const password = config.getOptionalString('password')?.trim();
|
||||
|
||||
@@ -92,7 +91,7 @@ export function readGerritIntegrationConfig(
|
||||
throw new Error(
|
||||
`Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl`,
|
||||
);
|
||||
} else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {
|
||||
} else if (!isValidUrl(gitilesBaseUrl)) {
|
||||
throw new Error(
|
||||
`Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`,
|
||||
);
|
||||
|
||||
@@ -134,9 +134,11 @@ describe('gerrit core', () => {
|
||||
host: 'gerrit.com',
|
||||
username: 'U',
|
||||
password: 'P',
|
||||
gitilesBaseUrl: 'https://gerrit.com/gerrit/plugins/gitiles',
|
||||
};
|
||||
const anonymousRequest: GerritIntegrationConfig = {
|
||||
host: 'gerrit.com',
|
||||
gitilesBaseUrl: 'https://gerrit.com/gerrit/plugins/gitiles',
|
||||
};
|
||||
expect(
|
||||
(getGerritRequestOptions(authRequest).headers as any).Authorization,
|
||||
|
||||
Reference in New Issue
Block a user