Skip to content

Commit

Permalink
Flows in documentations & visual git diff in Pull Requests (#938)
Browse files Browse the repository at this point in the history
* Flow doc v0

* Generate mermaid svg

* Remove mermaid-cli and call it via npx

* diff v0

* Flow diff v0.1: TODO: add tooltips for diff

* flow2markdown & refacto

* Temporary embed FlowVisualiser

* starts to be good :)

* factorize

* gitdiff for PR

* x

* Improve perfs

* rb

* all good !

* changelog

* fixes

* [Mega-Linter] Apply linters fixes

* x

* Do not run docker image as root

* test

* Revert "test"

This reverts commit 640234f.

* Fixes

* Fixes to generate only mmd for PRs

* One comment by flow diff ^^

* Allow SFDX_DISABLE_FLOW_DIFF

* Handle more cases

* More visuals to show diffs

* Add flow details

* More styling

* add formulas

* Flow index + rebranding of icons

* More styling

* Filter sections without updates

* Display only updated lines in tables

* Apply PR summary and git diff to wrapped SF Cli commands

* Fix wraputils & doc

* lint fixes

* doc

* Fix constants and tables

* changelog

* doc

* typo

* jscpd

* [Mega-Linter] Apply linters fixes :)

---------

Co-authored-by: nvuillam <[email protected]>
  • Loading branch information
nvuillam and nvuillam authored Dec 22, 2024
1 parent c47c05f commit 21a1e2c
Show file tree
Hide file tree
Showing 27 changed files with 1,778 additions and 426 deletions.
15 changes: 13 additions & 2 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@
"Eqoehef",
"Explainability",
"Externe",
"Famille",
"FGGF",
"FHDHGDH",
"FILEIO",
"Fonction",
"FSEDS",
"Facturation",
"Famille",
"Finet",
"Firstname",
"Flexi",
"Fonction",
"Fswg",
"GHSA",
"GHTRGDHD",
Expand Down Expand Up @@ -161,6 +161,7 @@
"Sfdx",
"Solva",
"Stmts",
"Subflow",
"Sublicensing",
"Suspendre",
"Sustn",
Expand All @@ -181,6 +182,7 @@
"VCAS",
"VERSIONNUMBER",
"Viewfile",
"Visualiser",
"Vuillamy",
"WIPO",
"XSLX",
Expand Down Expand Up @@ -358,6 +360,8 @@
"emailservices",
"emailvalid",
"emptyitems",
"endswitch",
"enduml",
"errorflow",
"erroronwarnings",
"errorprone",
Expand Down Expand Up @@ -597,6 +601,7 @@
"missingattributes",
"mkdir",
"mkdocs",
"mmdc",
"mocharc",
"monitoringhardisgroup",
"mrkdwn",
Expand All @@ -622,6 +627,7 @@
"nopull",
"nosmart",
"notestrunrunspecifiedtestsrunlocaltestsrunalltestsinorg",
"nothrow",
"notif",
"notificationtypes",
"notifs",
Expand Down Expand Up @@ -676,6 +682,7 @@
"peut",
"picklist",
"pjson",
"plantuml",
"ployer",
"pmdconfig",
"pocessed",
Expand Down Expand Up @@ -719,6 +726,7 @@
"remotesites",
"removedonly",
"removepackagexml",
"renderable",
"rendez",
"reportfile",
"reportname",
Expand Down Expand Up @@ -786,8 +794,10 @@
"sourceusername",
"standarditems",
"startchunknumber",
"startuml",
"staticresources",
"stefanzweifel",
"subflows",
"suspiscious",
"sustn",
"systemdebug",
Expand Down Expand Up @@ -857,6 +867,7 @@
"validateddeployrequestid",
"venv",
"viewdefinitions",
"visualiser",
"vous",
"vuln",
"wapp",
Expand Down
32 changes: 21 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@

Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta`

- [hardis:project:deploy:smart](https://sfdx-hardis.cloudity.com/hardis/project/deploy/smart/): Refactor deployment errors parsing: use JSON output instead of text output
- [hardis:org:test:apex](https://sfdx-hardis.cloudity.com/hardis/org/test/apex/): Display the number of failed tests in messages and notifications
- [hardis:org:monitor:backup](https://sfdx-hardis.cloudity.com/hardis/org/monitor/backup/): New option **--exclude-namespaces** that can be used with **--full** option
- Obfuscate some data from text log files
- Kill some exit handlers in case they are making the app crash after a throw SfError
- Trigger notifications during the command execution, not after
- Do not display warning in case no notification has been configured in case we are running locally
- Fix Individual deployment tips markdown docs by adding quotes to YML properties
- Fix init sfdx-hardis project commands and docs
- Display warning message in case package.xml has wrong format
- Allow to override package-no-overwrite from a branch .sfdx-hardis.yml config file
- Visual flow management, using MermaidJs
- [hardis:doc:project2markdown](https://sfdx-hardis.cloudity.com/hardis/doc/project2markdown/): Add a markdown file for each Flow
- [hardis:doc:flow2markdown](https://sfdx-hardis.cloudity.com/hardis/doc/flow2markdown/): Generate the markdown documentation of a single flow (available from VsCode extension)
- [hardis:project:generate:flow-git-diff](https://sfdx-hardis.cloudity.com/hardis/project/generate/flow-git-diff/): Generate the visual git diff for a single flow (available from VsCode extension)
- [hardis:project:deploy:smart](https://sfdx-hardis.cloudity.com/hardis/project/deploy/smart/): Add visual git diff for flows updated by a Pull Request
- Flow Visual Git diff also added to [standard SF Cli commands wrappers](https://sfdx-hardis.cloudity.com/salesforce-deployment-assistant-setup/#using-custom-cicd-pipeline)

- Command updates
- [hardis:project:deploy:smart](https://sfdx-hardis.cloudity.com/hardis/project/deploy/smart/): Refactor deployment errors parsing: use JSON output instead of text output
- [hardis:org:test:apex](https://sfdx-hardis.cloudity.com/hardis/org/test/apex/): Display the number of failed tests in messages and notifications
- [hardis:org:monitor:backup](https://sfdx-hardis.cloudity.com/hardis/org/monitor/backup/): New option **--exclude-namespaces** that can be used with **--full** option

- Core enhancements & fixes
- Obfuscate some data from text log files
- Kill some exit handlers in case they are making the app crash after a throw SfError
- Trigger notifications during the command execution, not after
- Do not display warning in case no notification has been configured in case we are running locally
- Fix Individual deployment tips markdown docs by adding quotes to YML properties
- Fix init sfdx-hardis project commands and docs
- Display warning message in case package.xml has wrong format
- Allow to override package-no-overwrite from a branch .sfdx-hardis.yml config file

## [5.10.1] 2024-12-12

Expand Down
6 changes: 6 additions & 0 deletions defaults/puppeteer-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"args": [
"--no-sandbox",
"--disable-setuid-sandbox"
]
}
Binary file added docs/assets/images/flow-visual-git-diff.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion docs/salesforce-deployment-assistant-home.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ Deployment errors are common and quite boring, right ?

Sfdx-hardis deployment assistant will help you to solve them, even if you are not using sfdx-hardis CI/CD pipelines !

The assistant contain core rules and can be integrated with AI to provide you the best guidance :)
The assistant contain core rules and can optionally be integrated with AI to provide you the best guidance :)

![](assets/images/AI-Assistant.gif)

## Flow Visual Git Diff

In addition to deployment tips, comments will be posted with Visual Git Diff for Flows.

🟩 = added

🟥 = removed

🟧 = updated

![](assets/images/flow-visual-git-diff.jpg)

## Integrations

Deployment assistant will provide tips in Pull Request comments (GitHub, Gitlab, Azure, Bitbucket).
Expand Down
21 changes: 13 additions & 8 deletions docs/salesforce-deployment-assistant-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ description: Learn how to setup Salesforce deployment assistant

# Setup Salesforce Deployment Assistant

## Using sfdx-hardis CI/CD

If you are using [sfdx-hardis CI/CD](https://sfdx-hardis.cloudity.com/salesforce-ci-cd-home/), you are already all set !
## Configure integrations

Just make sure to have configured your [GitHub](salesforce-ci-cd-setup-integration-github.md), [Gitlab](salesforce-ci-cd-setup-integration-gitlab.md), [Azure Pipelines](salesforce-ci-cd-setup-integration-azure.md) or [BitBucket](salesforce-ci-cd-setup-integration-bitbucket.md) integration so the deployment assistant can post its help in Pull Request comments.
Make sure to have configured your [GitHub](salesforce-ci-cd-setup-integration-github.md), [Gitlab](salesforce-ci-cd-setup-integration-gitlab.md), [Azure Pipelines](salesforce-ci-cd-setup-integration-azure.md) or [BitBucket](salesforce-ci-cd-setup-integration-bitbucket.md) integration so the deployment assistant can post its help in Pull Request comments.

If you want to **supercharge Salesforce deployment assistant with AI**, process [sfdx-hardis AI setup](salesforce-ai-setup.md).

You can also receive [Slack](salesforce-ci-cd-setup-integration-slack.md), [Ms Teams](salesforce-ci-cd-setup-integration-ms-teams.md) and [Email](salesforce-ci-cd-setup-integration-email.md) notifications in case of successful deployment.

If you configure [JIRA](salesforce-ci-cd-setup-integration-jira.md) or [Generic Ticketing](salesforce-ci-cd-setup-integration-generic-ticketing.md) integrations, ticket numbers will be extracted and displayed in the Pull Request comment.

## Using sfdx-hardis CI/CD

If you are using [sfdx-hardis CI/CD](https://sfdx-hardis.cloudity.com/salesforce-ci-cd-home/), you are already all set !

## Using custom CI/CD pipeline

Replace your calls to Salesforce CLI by calls to sfdx-hardis commands wrapper.
Expand All @@ -31,15 +37,14 @@ Configure your [GitHub](salesforce-ci-cd-setup-integration-github.md), [Gitlab](

_Notes:_

- _sfdx-hardis deployment assistant currently do not support --json option. If you really need it please request it in sfdx-hardis GitHub issues !_
- _there is no sfdx-hardis wrapper command yet for `sf project deploy start`. If you really need it please request it in sfdx-hardis GitHub issues !_
- _sfdx-hardis deployment assistant now works better with **--json** option please use it :)_

### Example

Replace:

`sfdx force:source:deploy -x manifest/package.xml --checkonly`
`sf project:deploy:start -x manifest/package.xml --checkonly`

by

`sf hardis:source:deploy -x manifest/package.xml --checkonly`
`sf hardis:project:deploy:start -x manifest/package.xml --checkonly`
2 changes: 1 addition & 1 deletion docs/schema/sfdx-hardis-json-schema-parameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -5825,6 +5825,6 @@ <h2 class="mb-0">
</div>

<footer>
<p class="generated-by-footer">Generated using <a href="https://github.com/coveooss/json-schema-for-humans">json-schema-for-humans</a> on 2024-12-17 at 22:22:38 +0100</p>
<p class="generated-by-footer">Generated using <a href="https://github.com/coveooss/json-schema-for-humans">json-schema-for-humans</a> on 2024-12-19 at 02:10:33 +0100</p>
</footer></body>
</html>
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"cross-spawn": "^7.0.6",
"csv-stringify": "^6.5.2",
"debug": "^4.3.6",
"diff": "^7.0.0",
"email-validator": "^2.0.4",
"exceljs": "^4.4.0",
"extract-zip": "^2.0.1",
"fast-xml-parser": "^4.5.1",
"fs-extra": "^11.2.0",
"fs-readdir-recursive": "^1.1.0",
"glob": "^11.0.0",
Expand Down Expand Up @@ -68,6 +70,7 @@
"@types/columnify": "^1.5.4",
"@types/cosmiconfig": "^6.0.3",
"@types/cross-spawn": "^6.0.6",
"@types/diff": "^6.0.0",
"@types/extract-zip": "^2.0.1",
"@types/fs-extra": "^11.0.4",
"@types/fs-readdir-recursive": "^1.1.3",
Expand Down
90 changes: 90 additions & 0 deletions src/commands/hardis/doc/flow2markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* jscpd:ignore-start */
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import c from "chalk";
import * as path from "path";
import fs from "fs-extra";
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { WebSocketClient } from '../../../common/websocketClient.js';
import { isCI, uxLog } from '../../../common/utils/index.js';
import { MetadataUtils } from '../../../common/metadata-utils/index.js';
import { generateFlowMarkdownFile, generateMarkdownFileWithMermaid } from '../../../common/utils/mermaidUtils.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('sfdx-hardis', 'org');

export default class Flow2Markdown extends SfCommand<any> {
public static title = 'Flow to Markdown';

public static description = `Generates a markdown documentation from a Flow file`;

public static examples = [
'$ sf hardis:doc:flow2markdown',
'$ sf hardis:doc:flow2markdown --inputfile force-app/main/default/flows/MyFlow.flow-meta.xml'
];

public static flags: any = {
inputfile: Flags.string({
char: 'x',
description: 'Path to Flow metadata file. If not specified, the command will prompt the user',
}),
outputfile: Flags.string({
char: 'f',
description: 'Force the path and name of output markdown file. Must end with .md',
}),
debug: Flags.boolean({
char: 'd',
default: false,
description: messages.getMessage('debugMode'),
}),
websocket: Flags.string({
description: messages.getMessage('websocket'),
}),
skipauth: Flags.boolean({
description: 'Skip authentication check when a default username is required',
}),
};

// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
public static requiresProject = false;

protected inputFile;
protected outputFile;
protected debugMode = false;
/* jscpd:ignore-end */

public async run(): Promise<AnyJson> {
const { flags } = await this.parse(Flow2Markdown);
this.inputFile = flags.inputfile || null;
this.outputFile = flags.outputfile || null;
this.debugMode = flags.debug || false;

if (this.inputFile === null && !isCI) {
this.inputFile = await MetadataUtils.promptFlow();
}
if (!this.outputFile) {
await fs.ensureDir(path.join("docs", "flows"));
this.outputFile = path.join("docs", "flows", path.basename(this.inputFile).replace(".flow-meta.xml", ".md"));
}

uxLog(this, c.grey(`Generating markdown for Flow ${this.inputFile}...`));
const flowXml = (await fs.readFile(this.inputFile, "utf8")).toString();
const genRes = await generateFlowMarkdownFile(this.inputFile, flowXml, this.outputFile);
if (!genRes) {
throw new Error("Error generating markdown file");
}
if (this.debugMode) {
await fs.copyFile(this.outputFile, this.outputFile + ".mermaid.md");
}
const gen2res = await generateMarkdownFileWithMermaid(this.outputFile);
if (!gen2res) {
throw new Error("Error generating mermaid markdown file");
}
// Open file in a new VsCode tab if available
WebSocketClient.requestOpenFile(this.outputFile);

// Return an object to be displayed with --json
return { outputFile: this.outputFile };
}

}
2 changes: 0 additions & 2 deletions src/commands/hardis/doc/packagexml2markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import { WebSocketClient } from '../../../common/websocketClient.js';
import { generatePackageXmlMarkdown } from '../../../common/utils/docUtils.js';
import { killBoringExitHandlers } from '../../../common/utils/index.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('sfdx-hardis', 'org');
Expand Down Expand Up @@ -62,7 +61,6 @@ export default class PackageXml2Markdown extends SfCommand<any> {
WebSocketClient.requestOpenFile(this.outputFile);

// Return an object to be displayed with --json
killBoringExitHandlers();
return { outputFile: this.outputFile };
}

Expand Down
Loading

0 comments on commit 21a1e2c

Please sign in to comment.