Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/__tests__/Search/fetchRevisionFromLando.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ describe('Lando to commit validating', () => {
(console.error as jest.Mock).mockClear();
});

it('should use the new Lando instance when landoInstance=lando-prod-2025', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
fetchMock.get('glob:https://lando.moz.tools/*', { status: 404 });
await router.navigate(
'/compare-lando-results?baseLando=123&baseRepo=try&newLando=456&newRepo=try&framework=1&landoInstance=lando-prod-2025',
);
render(<App />);
expect(console.error).toHaveBeenCalledWith(
new Error('Error when requesting lando: (404) Not Found'),
);
expect(fetchMock.callHistory.called('glob:https://lando.moz.tools/*')).toBe(
true,
);
expect(
fetchMock.callHistory.called(
'glob:https://api.lando.services.mozilla.com/*',
),
).toBe(false);
(console.error as jest.Mock).mockClear();
});

it('should reject', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
fetchMock.get(
Expand Down
17 changes: 12 additions & 5 deletions src/components/CompareResults/landoToCommitLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkValues, getComparisonInformation } from './loader';
import { compareView } from '../../common/constants';
import { fetchRevisionFromLandoId } from '../../logic/lando';
import { fetchRevisionFromLandoId, LandoInstance } from '../../logic/lando';
import {
Changeset,
CombinedResultsItemType,
Expand All @@ -24,6 +24,9 @@ export async function loader({ request }: { request: Request }) {
'newRepo',
) as Repository['name'][];
const frameworkFromUrl = url.searchParams.get('framework');
const landoInstanceFromUrl =
(url.searchParams.get('landoInstance') as LandoInstance | null) ??
undefined;
if (!baseLandoIDFromUrl || !newLandoIDFromUrl) {
throw new Error(
'Not all values were supplied please check you provided both baseLando and newLando',
Expand All @@ -34,10 +37,14 @@ export async function loader({ request }: { request: Request }) {
'enable_silverman_kde',
);

const baseRevisionsFromLando =
await fetchRevisionFromLandoId(baseLandoIDFromUrl);
const newRevisionsFromLando =
await fetchRevisionFromLandoId(newLandoIDFromUrl);
const baseRevisionsFromLando = await fetchRevisionFromLandoId(
baseLandoIDFromUrl,
landoInstanceFromUrl,
);
const newRevisionsFromLando = await fetchRevisionFromLandoId(
newLandoIDFromUrl,
landoInstanceFromUrl,
);
const testVersionFromUrl = url.searchParams.get(
'test_version',
) as TestVersion;
Expand Down
17 changes: 14 additions & 3 deletions src/logic/lando.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { LandoToCommit } from '../types/state';

const landoBaseUrl = 'https://api.lando.services.mozilla.com';
const landoInstances = {
'lando-dev': 'api.dev.lando.nonprod.cloudops.mozgcp.net',
'lando-dev-2025': 'lando-dev.allizom.org',
'lando-prod': 'api.lando.services.mozilla.com',
'lando-prod-2025': 'lando.moz.tools',
};

export type LandoInstance = keyof typeof landoInstances;

async function fetchFromLando(url: string) {
const response = await fetch(url);
Expand All @@ -12,8 +19,12 @@ async function fetchFromLando(url: string) {
return response;
}

export async function fetchRevisionFromLandoId(landoid: string) {
const url = `${landoBaseUrl}/landing_jobs/${landoid}`;
export async function fetchRevisionFromLandoId(
landoid: string,
instance: LandoInstance = 'lando-prod',
) {
const host = landoInstances[instance] ?? landoInstances['lando-prod'];
const url = `https://${host}/landing_jobs/${landoid}`;
const response = await fetchFromLando(url);
return response.json() as Promise<LandoToCommit>;
}