From 8692c3a2de15517fdd77b9e3b9247fb304148cb0 Mon Sep 17 00:00:00 2001 From: Nicolas Vuillamy Date: Fri, 20 Dec 2024 13:56:26 +0100 Subject: [PATCH] One comment by flow diff ^^ --- src/commands/hardis/project/deploy/smart.ts | 2 +- src/common/gitProvider/index.ts | 15 +++++++++-- src/common/gitProvider/utilsMarkdown.ts | 29 +++++++++------------ src/common/utils/gitUtils.ts | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/commands/hardis/project/deploy/smart.ts b/src/commands/hardis/project/deploy/smart.ts index d052ffccd..852cdc03b 100644 --- a/src/commands/hardis/project/deploy/smart.ts +++ b/src/commands/hardis/project/deploy/smart.ts @@ -342,7 +342,7 @@ If testlevel=RunRepositoryTests, can contain a regular expression to keep only c const commitsSummary = await computeCommitsSummary(true, pullRequestInfo); const prDataCommitsSummary = { commitsSummary: commitsSummary.markdown, - flowDiffSummary: commitsSummary.flowDiffMarkdown + flowDiffMarkdown: commitsSummary.flowDiffMarkdown }; globalThis.pullRequestData = Object.assign(globalThis.pullRequestData || {}, prDataCommitsSummary); } catch (e3) { diff --git a/src/common/gitProvider/index.ts b/src/common/gitProvider/index.ts index 7eaac60b3..3f34bb9fb 100644 --- a/src/common/gitProvider/index.ts +++ b/src/common/gitProvider/index.ts @@ -119,8 +119,8 @@ export abstract class GitProvider { if (prData.commitsSummary) { markdownBody += "\n\n" + prData.commitsSummary; } - if (prData.flowDiffSummary) { - markdownBody += "\n\n" + prData.flowDiffSummary; + if (prData?.flowDiffMarkdown?.markdownSummary) { + markdownBody += "\n\n" + prData.flowDiffMarkdown.markdownSummary; } const prMessageRequest: PullRequestMessageRequest = { title: prData.title, @@ -128,10 +128,21 @@ export abstract class GitProvider { status: prData.status, messageKey: prData.messageKey, }; + // Post main message const postResult = await gitProvider.tryPostPullRequestMessage(prMessageRequest); if (postResult && postResult.posted === true) { globalThis.pullRequestCommentSent = true; } + // Post additional comments + for (const flowDiff of prData?.flowDiffMarkdown?.flowDiffMarkdownList || []) { + const prMessageRequestAdditional: PullRequestMessageRequest = { + title: `Differences for Flow ${flowDiff.name}`, + message: flowDiff.markdown, + status: "valid", + messageKey: `sfdx-hardis-flow-diff-${flowDiff.name}`, + }; + await gitProvider.tryPostPullRequestMessage(prMessageRequestAdditional); + } } else { uxLog(this, c.gray(`${JSON.stringify(prData || { noPrData: "" })} && ${gitProvider} && ${prCommentSent}`)); uxLog(this, c.yellow("[Git Provider] Skip post pull request comment")); diff --git a/src/common/gitProvider/utilsMarkdown.ts b/src/common/gitProvider/utilsMarkdown.ts index d8efaf1c6..c2c9fed80 100644 --- a/src/common/gitProvider/utilsMarkdown.ts +++ b/src/common/gitProvider/utilsMarkdown.ts @@ -75,39 +75,34 @@ export function deployCodeCoverageToMarkdown(orgCoverage: number, orgCoverageTar } } -export async function flowDiffToMarkdown(flowNames: string[], fromCommit: string, toCommit: string): Promise { +export async function flowDiffToMarkdown(flowNames: string[], fromCommit: string, toCommit: string): Promise { if (flowNames.length === 0) { return ""; } + const flowDiffMarkdownList: any = []; let flowDiffFilesSummary = "## Flow changes\n\n"; for (const flowName of flowNames) { + flowDiffFilesSummary += `- [${flowName}](#${flowName})\n`; const fileMetadata = await MetadataUtils.findMetaFileFromTypeAndName("Flow", flowName); try { const diffMdFile = await generateFlowVisualGitDiff(fileMetadata, fromCommit, toCommit, { mermaidMd: true, svgMd: false, debug: false }); if (diffMdFile) { const flowDiffMarkdownMermaid = await fs.readFile(diffMdFile + ".mermaid.md", "utf8"); - const flowSection = `
🤖 ${flowName} 🤖 - -${flowDiffMarkdownMermaid} - -
-
-` - flowDiffFilesSummary += flowSection + flowDiffMarkdownList.push({ name: flowName, markdown: flowDiffMarkdownMermaid }); } } catch (e: any) { uxLog(this, c.yellow(`[FlowGitDiff] Unable to generate Flow diff: ${e.message}`)); - const flowSection = `
🤖 ${flowName} 🤖 - -Unable to generate Flow diff: ${e.message} + const flowGenErrorMd = `# ${flowName} -
-
-` - flowDiffFilesSummary += flowSection +Error while generating Flows visual git diff +`; + flowDiffMarkdownList.push({ name: flowName, markdown: flowGenErrorMd }); } } - return flowDiffFilesSummary; + return { + markdownSummary: flowDiffFilesSummary, + flowDiffMarkdownList: flowDiffMarkdownList + } } function getAiPromptResponseMarkdown(title, message) { diff --git a/src/common/utils/gitUtils.ts b/src/common/utils/gitUtils.ts index df8309187..7d7218581 100644 --- a/src/common/utils/gitUtils.ts +++ b/src/common/utils/gitUtils.ts @@ -173,7 +173,7 @@ export async function computeCommitsSummary(checkOnly, pullRequestInfo: any) { } // Add Flow diff in Markdown - let flowDiffMarkdown = ""; + let flowDiffMarkdown: any = {}; if (checkOnly || GitProvider.isDeployBeforeMerge()) { const flowList: string[] = []; for (const logResult of logResults) {