diff --git a/.changeset/cyan-ducks-sin.md b/.changeset/cyan-ducks-sin.md new file mode 100644 index 0000000000..4b69fabcc2 --- /dev/null +++ b/.changeset/cyan-ducks-sin.md @@ -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` diff --git a/packages/backend-common/src/reading/GerritUrlReader.test.ts b/packages/backend-common/src/reading/GerritUrlReader.test.ts index 4a3b0a5de6..66943cac51 100644 --- a/packages/backend-common/src/reading/GerritUrlReader.test.ts +++ b/packages/backend-common/src/reading/GerritUrlReader.test.ts @@ -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: { diff --git a/packages/backend-common/src/reading/GerritUrlReader.ts b/packages/backend-common/src/reading/GerritUrlReader.ts index 665770815f..76de711dec 100644 --- a/packages/backend-common/src/reading/GerritUrlReader.ts +++ b/packages/backend-common/src/reading/GerritUrlReader.ts @@ -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 => 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 },