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

improved source repository validation #34

Merged
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: 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
Loading