diff --git a/packages/sfp-cli/messages/impact_release_config.json b/packages/sfp-cli/messages/impact_release_config.json index d96edc890..8cd21e90e 100644 --- a/packages/sfp-cli/messages/impact_release_config.json +++ b/packages/sfp-cli/messages/impact_release_config.json @@ -1,7 +1,9 @@ { "commandDescription": "Figures out impacted release configurations of a project, due to a change,from the last known tags", "releaseConfigFileFlagDescription":"Path to the directory containing release defns", + "branchFlagDescription":"The branch on which the comparison is carried out", "baseCommitOrBranchFlagDescription": "The base branch on which the git tags should be used from", "filterByFlagDescription": "Filter by a specific release config name", + "filterByChangesInBranchFlagDescription": "Filter packages by changes with the provided branches as opposed to tags", "explictDependencyCheckFlagDescription": "Activate to consider dependencyOn attribut while handling impact" } diff --git a/packages/sfp-cli/src/commands/impact/releaseconfig.ts b/packages/sfp-cli/src/commands/impact/releaseconfig.ts index b8e7bec9c..fa6090efa 100644 --- a/packages/sfp-cli/src/commands/impact/releaseconfig.ts +++ b/packages/sfp-cli/src/commands/impact/releaseconfig.ts @@ -18,6 +18,10 @@ const messages = Messages.loadMessages('@flxblio/sfp', 'impact_release_config'); export default class ReleaseConfig extends sfpCommand { public static flags = { loglevel, + branch: Flags.string({ + description: messages.getMessage('branchFlagDescription'), + required: true, + }), basebranch: Flags.string({ description: messages.getMessage('baseCommitOrBranchFlagDescription'), required: true, @@ -33,6 +37,9 @@ export default class ReleaseConfig extends sfpCommand { filterBy: Flags.string({ description: messages.getMessage('filterByFlagDescription'), }), + filterByChangesInBranch: Flags.boolean({ + description: messages.getMessage('filterByChangesInBranchFlagDescription'), + }), }; public static description = messages.getMessage('commandDescription'); @@ -52,6 +59,13 @@ export default class ReleaseConfig extends sfpCommand { }, }; + if(this.flags.filterByChangesInBranch) + { + this.props.diffOptions.useBranchCompare=true; + this.props.diffOptions.branch=this.flags.branch; + this.props.diffOptions.baseBranch=this.flags.basebranch; + } + const impactedPackageResolver = new ImpactedPackageResolver(this.props, new ConsoleLogger()); let packagesToBeBuiltWithReasons = await impactedPackageResolver.getImpactedPackages(); diff --git a/packages/sfp-cli/src/core/git/GitTags.ts b/packages/sfp-cli/src/core/git/GitTags.ts index 846585451..845806c6d 100644 --- a/packages/sfp-cli/src/core/git/GitTags.ts +++ b/packages/sfp-cli/src/core/git/GitTags.ts @@ -45,12 +45,13 @@ export default class GitTags { let refTagsPointingToBranch: string[] = refTags.filter((refTag) => commits.includes(refTag.substring(0, 40))); // Only match the name of the tags pointing to the branch - refTagsPointingToBranch = refTagsPointingToBranch.map( - (refTagPointingToBranch) => refTagPointingToBranch.match(/(?:refs\/tags\/)(.*)((?:-ALIGN)|(?:\^{}))/)[1] - ); + refTagsPointingToBranch = refTagsPointingToBranch.map((refTagPointingToBranch) => { + const match = refTagPointingToBranch.match(/(?:refs\/tags\/)(.*)((?:-ALIGN)|(?:\^{}))/); + return match ? match[1] : null; + }); // Filter the sorted tags - only including tags that point to the branch - let tagsPointingToBranch: string[] = tags.filter((tag) => refTagsPointingToBranch.includes(tag)); + let tagsPointingToBranch: string[] = tags.filter((tag) => refTagsPointingToBranch?.includes(tag)); return tagsPointingToBranch; } diff --git a/packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts b/packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts index e620bf96c..89a954c1b 100644 --- a/packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts +++ b/packages/sfp-cli/src/core/package/diff/PackageDiffImpl.ts @@ -15,6 +15,9 @@ export class PackageDiffOptions { useLatestGitTags?:boolean=true; packagesMappedToLastKnownCommitId?: { [p: string]: string }; pathToReplacementForceIgnore?: string; + useBranchCompare?: boolean = false; + branch?: string; + baseBranch?: string; } export default class PackageDiffImpl { @@ -52,7 +55,14 @@ export default class PackageDiffImpl { // Get the list of modified files between the tag and HEAD refs let modified_files: string[]; try { - modified_files = await git.diff([`${tag}`, `HEAD`, `--no-renames`, `--name-only`]); + if(this.diffOptions?.useBranchCompare) + { + modified_files = await git.diff(['--name-only', `${this.diffOptions.baseBranch}...${this.diffOptions.branch}`]); + } + else + { + modified_files = await git.diff([`${tag}`, `HEAD`, `--no-renames`, `--name-only`]); + } } catch (error) { SFPLogger.log(COLOR_ERROR(`Unable to compute diff, The head of the branch is not reachable from the commit id ${tag}`)); SFPLogger.log(COLOR_ERROR(`Check your current branch (in case of build) or the scratch org in case of validate command`));