Merge pull request #22853 from anicke/gerrit-gitilesBaseUrl

Gerrit: Make the gitilesBaseUrl mandatory
This commit is contained in:
Patrik Oldsberg
2024-02-13 13:32:33 +01:00
committed by GitHub
3 changed files with 54 additions and 2 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/backend-common': minor
---
**BREAKING**: `A gitilesBaseUrl` must be provided for the Gerrit integration to work.
You can disable this check by setting `DISABLE_GERRIT_GITILES_REQUIREMENT=1` but
this will be removed in a future release. If you are not able to use the Gitiles
Gerrit plugin, please open an issue towards `https://github.com/backstage/backstage`
@@ -32,10 +32,15 @@ import path from 'path';
import { getVoidLogger } from '../logging';
import { UrlReaderPredicateTuple } from './types';
import { DefaultReadTreeResponseFactory } from './tree';
import { GerritUrlReader } from './GerritUrlReader';
import {
GITILES_BASE_URL_DEPRECATION_MESSSAGE,
GerritUrlReader,
} from './GerritUrlReader';
import getRawBody from 'raw-body';
const mockDir = createMockDirectory({ mockOsTmpDir: true });
const env = process.env;
process.env = { ...env, DISABLE_GERRIT_GITILES_REQUIREMENT: '1' };
const treeResponseFactory = DefaultReadTreeResponseFactory.create({
config: new ConfigReader({}),
@@ -93,10 +98,14 @@ describe.skip('GerritUrlReader', () => {
const worker = setupServer();
setupRequestMockHandlers(worker);
beforeEach(mockDir.clear);
beforeEach(() => {
mockDir.clear();
process.env = { ...env, DISABLE_GERRIT_GITILES_REQUIREMENT: '1' };
});
afterAll(() => {
jest.clearAllMocks();
process.env = env;
});
describe('reader factory', () => {
@@ -117,6 +126,29 @@ describe.skip('GerritUrlReader', () => {
});
});
describe('handle optional gitilesBaseUrl deprecation', () => {
it('should throw if gitilesBaseUrl is not set.', () => {
process.env = env;
expect(() =>
createReader({
integrations: {
gerrit: [{ host: 'gerrit.com' }],
},
}),
).toThrow(GITILES_BASE_URL_DEPRECATION_MESSSAGE);
});
it('should not throw if gitilesBaseUrl requirement is overridden.', () => {
process.env = { ...env, DISABLE_GERRIT_GITILES_REQUIREMENT: '1' };
expect(() =>
createReader({
integrations: {
gerrit: [{ host: 'gerrit.com' }],
},
}),
).not.toThrow();
});
});
describe('predicates without Gitiles', () => {
const readers = createReader({
integrations: {
@@ -49,6 +49,12 @@ import {
const pipeline = promisify(pipelineCb);
export const GITILES_BASE_URL_DEPRECATION_MESSSAGE = `A gitilesBaseUrl must be provided \
for the gerrit integration to work. You can disable this check by setting \
DISABLE_GERRIT_GITILES_REQUIREMENT=1 but this will be removed in a future release. If you \
are not able to use the gitiles gerrit plugin, please open an issue towards \
https://github.com/backstage/backstage`;
const createTemporaryDirectory = async (workDir: string): Promise<string> =>
await fs.mkdtemp(joinPath(workDir, '/gerrit-clone-'));
@@ -81,6 +87,12 @@ export class GerritUrlReader implements UrlReader {
const workDir =
config.getOptionalString('backend.workingDirectory') ?? os.tmpdir();
return integrations.gerrit.list().map(integration => {
if (
integration.config.gitilesBaseUrl === integration.config.baseUrl &&
process.env.DISABLE_GERRIT_GITILES_REQUIREMENT === undefined
) {
throw new Error(GITILES_BASE_URL_DEPRECATION_MESSSAGE);
}
const reader = new GerritUrlReader(
integration,
{ treeResponseFactory },