Skip to content

Commit

Permalink
notify v1
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Jan 2, 2025
1 parent 433a062 commit 019322a
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/commands/hardis/project/deploy/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AnyJson } from '@salesforce/ts-types';
import { CONSTANTS } from '../../../../config/index.js';
import { buildCheckDeployCommitSummary, handlePostDeploymentNotifications } from '../../../../common/utils/gitUtils.js';
import { GitProvider } from '../../../../common/gitProvider/index.js';
import c from "chalk"
import { uxLog } from '../../../../common/utils/index.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('sfdx-hardis', 'org');
Expand All @@ -28,7 +30,11 @@ export default class DeployNotify extends SfCommand<any> {
You can also use [sfdx-hardis wrapper commands of SF deployment commands](${CONSTANTS.DOC_URL_ROOT}/salesforce-deployment-assistant-setup/#using-custom-cicd-pipeline)
`

public static examples = ['$ sf hardis:project:audit:apiversion'];
public static examples = [
'$ sf hardis:project:deploy:notify --check-only --deploy-status valid --message "This deployment check is valid\\n\\nYahooo !!"',
'$ sf hardis:project:deploy:notify --check-only --deploy-status invalid --message "This deployment check has failed !\\n\\Oh no !!"',
'$ sf hardis:project:deploy:notify --deploy-status valid --message "This deployment has been processed !\\n\\nYahooo !!"'
];

public static flags: any = {
"check-only": Flags.boolean({
Expand Down Expand Up @@ -73,34 +79,42 @@ export default class DeployNotify extends SfCommand<any> {
public async run(): Promise<AnyJson> {
const { flags } = await this.parse(DeployNotify);
this.checkOnly = flags["check-only"] === true ? true : false;
this.deployStatus = flags.status || "unknown";
this.deployStatus = flags["deploy-status"] || "unknown";
this.debugMode = flags.debug || false;

// Compute commitsSummary and store it in globalThis.pullRequestData.commitsSummary
// Deployment check mode
if (this.checkOnly) {
uxLog(this, c.cyan("Handling Pull Request comments for a deployment check job..."));
await buildCheckDeployCommitSummary();

// Add deployment info
const prData: any = {
messageKey: "deployment",
title:
(this.checkOnly && this.deployStatus === "valid") ? "✅ Deployment check success" :
(!this.checkOnly && this.deployStatus === "valid") ? "✅ Deployment success" :
(this.checkOnly && this.deployStatus === "invalid") ? "❌ Deployment check failure" :
(!this.checkOnly && this.deployStatus === "invalid") ? "❌ Deployment failure" :
(this.checkOnly && this.deployStatus === "unknown") ? "🤷 Deployment check status unknown" :
"🤷 Deployment status unknown",
deployErrorsMarkdownBody: this.message,
status: this.deployStatus,
};
globalThis.pullRequestData = Object.assign(globalThis.pullRequestData || {}, prData);
// Post comments :)
await GitProvider.managePostPullRequestComment();
}

// Add deployment info
const prData: any = {
messageKey: "deployment",
title:
(this.checkOnly && this.deployStatus === "valid") ? "✅ Deployment check success" :
(!this.checkOnly && this.deployStatus === "valid") ? "✅ Deployment success" :
(this.checkOnly && this.deployStatus === "invalid") ? "❌ Deployment check failure" :
(!this.checkOnly && this.deployStatus === "invalid") ? "❌ Deployment failure" :
(this.checkOnly && this.deployStatus === "unknown") ? "🤷 Deployment check status unknown" :
"🤷 Deployment status unknown",
deployErrorsMarkdownBody: this.message,
deployStatus: this.deployStatus,
};
globalThis.pullRequestData = Object.assign(globalThis.pullRequestData || {}, prData);

if (this.checkOnly === false) {
// Post notifications after successful deployment
else if (this.checkOnly === false && this.deployStatus === "valid") {
await handlePostDeploymentNotifications(flags, flags["target-org"].getUsername(), false, false, this.debugMode);
}

await GitProvider.managePostPullRequestComment();
// Fallback
else {
uxLog(this, c.yellow("No notification has been sent"));
uxLog(this, c.yellow("- Pull Request comments are sent if --check-only is true"));
uxLog(this, c.yellow("- Slack / Teams / Email / JIRA messages are sent only if --check-only is false and --deploy-status is valid"));
}

return { message: "Processed notifications" }
}
Expand Down

0 comments on commit 019322a

Please sign in to comment.