Skip to content

Commit

Permalink
fix(sfpPackage): improved source repository validation (#34)
Browse files Browse the repository at this point in the history
* improved source repository validation

* chore: update pnpm lock

* fix: update deps locks

---------

Co-authored-by: Azlam <[email protected]>
Co-authored-by: azlam-abdulsalam <[email protected]>
  • Loading branch information
3 people committed Mar 26, 2024
1 parent d717da4 commit 6365196
Show file tree
Hide file tree
Showing 3 changed files with 11,962 additions and 16,323 deletions.
2 changes: 2 additions & 0 deletions packages/sfp-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@flxbl-io/apexlink": "^3.0.1",
"@flxbl-io/sfdx-process-wrapper": "^2.0.1",
"git-url-parse": "14.0.0",
"@flxbl-io/sfp-logger": "^3.0.1",
"@flxbl-io/sfprofiles": "^4.0.1",
"@newrelic/telemetry-sdk": "^0.6.0",
Expand Down Expand Up @@ -71,6 +72,7 @@
"@salesforce/dev-config": "3.0.1",
"@salesforce/ts-sinon": "^1.3.21",
"@salesforce/ts-types": "2.0.5",
"@types/git-url-parse": "9.0.3",
"@types/adm-zip": "^0.4.33",
"@types/fs-extra": "11.0.4",
"@types/jest": "^29.5.3",
Expand Down
64 changes: 22 additions & 42 deletions packages/sfp-cli/src/core/package/SfpPackageInquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SFPLogger, { Logger, LoggerLevel } from '@flxbl-io/sfp-logger';
import * as fs from 'fs-extra';
import path = require('path');
import lodash = require('lodash');
import { URL } from 'url';
import gitUrlParse = require('git-url-parse');
import SfpPackage from './SfpPackage';

/**
Expand Down Expand Up @@ -84,56 +84,36 @@ export default class SfpPackageInquirer {
* Verify that artifacts are from the same source repository
*/
public validateArtifactsSourceRepository(): void {
let remoteURL: RemoteURL;
let remoteURL: gitUrlParse.GitUrl;

for (let sfpPackage of this.sfpPackages) {
let currentRemoteURL: RemoteURL;

let isHttp: boolean = sfpPackage.repository_url.match(/^https?:\/\//) ? true : false;
if (isHttp) {
const url = new URL(sfpPackage.repository_url);
currentRemoteURL = {
ref: url.toString(),
hostName: url.hostname,
pathName: url.pathname,
};
} else {
// Handle SSH URL separately, as it is not supported by URL module
currentRemoteURL = {
ref: sfpPackage.repository_url,
hostName: null,
pathName: null,
};
}
let currentRemoteURL = gitUrlParse(sfpPackage.repository_url);

if (remoteURL == null) {
remoteURL = currentRemoteURL;
continue;
}

let isValid: boolean;
if (isHttp) {
if (
currentRemoteURL.hostName === remoteURL.hostName &&
currentRemoteURL.pathName === remoteURL.pathName
)
isValid = true;
else isValid = false;
} else {
if (currentRemoteURL.ref === remoteURL.ref) isValid = true;
else isValid = false;
}
const propertiesToVerify: string[] = [
'source', 'full_name'
];

if (!isValid) {
SFPLogger.log(`remoteURL: ${JSON.stringify(remoteURL)}`, LoggerLevel.DEBUG, this.packageLogger);
SFPLogger.log(
`currentRemoteURL: ${JSON.stringify(currentRemoteURL)}`,
LoggerLevel.DEBUG,
this.packageLogger
);
throw new Error(
`Artifacts must originate from the same source repository, for deployment to work. The artifact ${sfpPackage.packageName} has repository URL that doesn't meet the current repository URL ${JSON.stringify(currentRemoteURL)} not equal ${JSON.stringify(remoteURL)}`
);
for (let property of propertiesToVerify) {
if (currentRemoteURL[property] !== remoteURL[property]) {
SFPLogger.log(
`remoteURL: ${JSON.stringify(remoteURL)}`,
LoggerLevel.DEBUG,
this.packageLogger
);
SFPLogger.log(
`currentRemoteURL: ${JSON.stringify(currentRemoteURL)}`,
LoggerLevel.DEBUG,
this.packageLogger
);
throw new Error(
`Artifacts must originate from the same source repository, for deployment to work. The artifact ${sfpPackage.packageName} has repository URL that doesn't meet the current repository URL ${JSON.stringify(currentRemoteURL)} not equal ${JSON.stringify(remoteURL)}`
);
}
}
}
}
Expand Down
Loading

0 comments on commit 6365196

Please sign in to comment.