Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(fetch package id): add new logic for promoted pcks #20

Merged
merged 5 commits into from
Apr 17, 2024
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
2 changes: 1 addition & 1 deletion packages/sfp-cli/src/core/apextest/TriggerApexTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class TriggerApexTests {
id: testResult.summary.testRunId,
message: dedent `Unable to fetch test execution results,
Please check the results in the org by using the URL below
https://${this.conn.instanceUrl}/lightning/setup/ApexTestHistory/home
${this.conn.instanceUrl}/lightning/setup/ApexTestHistory/home
Please try the test execution again`,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class PackageDependencyResolver {
for (let i = 0; i < packageDirectory.dependencies.length; i++) {
let dependency = packageDirectory.dependencies[i];
if (this.projectConfig.packageAliases[dependency.package] === undefined && !this.isSubscriberPackageVersionId(dependency.package)) {

throw new Error(`Can't find package id for dependency: ${dependency.package}, Please ensure that the package is added to sfdx-project.json in your packageAliases`);
}

Expand Down Expand Up @@ -86,15 +86,15 @@ export default class PackageDependencyResolver {
delete dependency.versionNumber;
delete dependency.branch;
continue;

}else {
package2VersionForDependency = await this.getPackage2VersionForDependency(
this.conn,
dependency,
packageVersionId
);
}


if (package2VersionForDependency == null) {
packageDirectory.dependencies.splice(i, 1);
Expand All @@ -120,6 +120,8 @@ export default class PackageDependencyResolver {
branch?: string,
): Promise<Package2Version> {

let isReleased = false;

//Dont hit api's if its only for external dependencies
if (this.projectConfig.packageDirectories.find((dir) => dir.package === dependency.package)) {
if (this.resolveExternalDepenciesOnly) return null;
Expand All @@ -129,7 +131,9 @@ export default class PackageDependencyResolver {

let versionNumber: string = dependency.versionNumber;
let vers: string[] = versionNumber.split('.');
if (vers.length === 4 && vers[3] === 'LATEST') {
// fetch only promoted versions
if (vers.length === 4 && vers[3] === 'RELEASED') isReleased = true;
if (vers.length === 4 && (vers[3] === 'LATEST') || (vers[3] === 'RELEASED')) {
versionNumber = `${vers[0]}.${vers[1]}.${vers[2]}`;
}

Expand All @@ -152,10 +156,11 @@ export default class PackageDependencyResolver {
records = await package2VersionFetcher.fetchByPackage2Id(
packageVersionId,
versionNumber,
true
true,
isReleased
);
}

this.package2VersionCache.set(
packageVersionId,
versionNumber,
Expand All @@ -167,12 +172,18 @@ export default class PackageDependencyResolver {
);
}

if (package2Versions.length === 0) {
if (package2Versions.length === 0 && !isReleased) {
throw new Error(
`Failed to find any validated Package2 versions for the dependency ${dependency.package} with version ${dependency.versionNumber}`
);
}

if (package2Versions.length === 0 && isReleased) {
throw new Error(
`Failed to find any promoted Package2 versions for the dependency ${dependency.package} with version ${dependency.versionNumber}`
);
}

if (this.projectConfig.packageDirectories.find((dir) => dir.package === dependency.package && !branch)) {
package2Version = await this.getPackage2VersionFromCurrentBranch(package2Versions, dependency);
} else {
Expand Down Expand Up @@ -211,7 +222,7 @@ export default class PackageDependencyResolver {

if (!package2VersionOnCurrentBranch) {
throw new Error(
`Failed to find validated Package2 version for dependency ${dependency.package} with version ${dependency.versionNumber} created from the current branch,
`Failed to find validated Package2 version for dependency ${dependency.package} with version ${dependency.versionNumber} created from the current branch,
You will need to create a new version of the package on the current branch to resolve this dependency.`
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default class Package2VersionFetcher {
async fetchByPackage2Id(
package2Id: string,
versionNumber?: string,
isValidatedPackages?: boolean
isValidatedPackages?: boolean,
isReleased?: boolean
): Promise<Package2Version[]> {
let query = this.query;

Expand All @@ -39,14 +40,16 @@ export default class Package2VersionFetcher {
}

if (isValidatedPackages) whereClause += `and ValidationSkipped = false `;
if (isReleased) whereClause += `and IsReleased = true `;


whereClause += `and IsDeprecated = false `;
query += whereClause;


const records = await QueryHelper.query<Package2Version>(query, this.conn, true);


if (records.length > 1) {
return records.sort((a, b) => {
const v1 = `${a.MajorVersion}.${a.MinorVersion}.${a.PatchVersion}-${a.BuildNumber}`;
Expand All @@ -67,11 +70,11 @@ export default class Package2VersionFetcher {
}

async fetchByPackageBranchAndName(
packageBranch: string,
packageName: string,
packageBranch: string,
packageName: string,
versionNumber?: string,
): Promise<Package2Version[]> {

let query = this.query;

let whereClause: string = `where Branch='${packageBranch}' and Package2.Name ='${packageName}' `;
Expand All @@ -90,7 +93,7 @@ export default class Package2VersionFetcher {
const records = await QueryHelper.query<Package2Version>(query, this.conn, true);
return records;

}
}
}

export interface Package2Version {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class PreRequisiteCheck {

if (!PreRequisiteCheck.isPrerequisiteMet) {
throw new Error( `Required Prerequisite values in ScratchOrgInfo is missing in the DevHub` +
`For more information Please refer https://sfp.flxbl.io/getting-started/prerequisites \n`);
`For more information Please refer https://docs.flxbl.io/sfp/pools/setting-up-your-salesforce-org-for-scratch-org-pools \n`);
}
}
}
Loading