Skip to content

Commit

Permalink
fix(nx-cloud): do not use bff api for onboarding (#26712)
Browse files Browse the repository at this point in the history
## Current Behavior
CLI uses BFF

## Expected Behavior
CLI should not use BFF
  • Loading branch information
StalkAltan authored Jun 27, 2024
1 parent 88efb21 commit 544eff0
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions packages/nx/src/nx-cloud/utilities/url-shorten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function shortenedCloudUrl(

const version = await getNxCloudVersion(apiUrl);

if (version && lt(truncateToSemver(version), '2406.11.5')) {
if (version && lt(removeVersionModifier(version), '2406.11.5')) {
return apiUrl;
}

Expand Down Expand Up @@ -110,16 +110,18 @@ function getURLifShortenFailed(

async function getInstallationSupportsGitHub(apiUrl: string): Promise<boolean> {
try {
const response = await require('axios').get(`${apiUrl}/vcs-integrations`);
const response = await require('axios').get(
`${apiUrl}/nx-cloud/system/features`
);
if (!response?.data || response.data.message) {
throw new Error(
response?.data?.message ?? 'Failed to shorten Nx Cloud URL'
);
}
return !!response.data.github;
return !!response.data.isGithubIntegrationEnabled;
} catch (e) {
if (process.env.NX_VERBOSE_LOGGING) {
logger.warn(`Failed to access vcs-integrations endpoint.
logger.warn(`Failed to access system features. GitHub integration assumed to be disabled.
${e}`);
}
return false;
Expand All @@ -128,10 +130,10 @@ async function getInstallationSupportsGitHub(apiUrl: string): Promise<boolean> {

async function getNxCloudVersion(apiUrl: string): Promise<string | null> {
try {
const response = await require('axios').get(`${apiUrl}/version`, {
responseType: 'document',
});
const version = extractVersion(response.data);
const response = await require('axios').get(
`${apiUrl}/nx-cloud/system/version`
);
const version = removeVersionModifier(response.data.version);
if (!version) {
throw new Error('Failed to extract version from response.');
}
Expand All @@ -142,16 +144,7 @@ async function getNxCloudVersion(apiUrl: string): Promise<string | null> {
}
}

function extractVersion(htmlString: string): string | null {
// The pattern assumes 'Version' is inside an h1 tag and the version number is the next span's content
const regex =
/<h1[^>]*>Version<\/h1>\s*<div[^>]*><div[^>]*><div[^>]*><span[^>]*>([^<]+)<\/span>/;
const match = htmlString.match(regex);

return match ? match[1].trim() : null;
}

function truncateToSemver(versionString: string): string {
function removeVersionModifier(versionString: string): string {
// version may be something like 2406.13.5.hotfix2
return versionString.split(/[\.-]/).slice(0, 3).join('.');
}

0 comments on commit 544eff0

Please sign in to comment.