Skip to content

Commit

Permalink
One comment by flow diff ^^
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Dec 20, 2024
1 parent 7b4fe7f commit 8692c3a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/commands/hardis/project/deploy/smart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 13 additions & 2 deletions src/common/gitProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,30 @@ 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,
message: markdownBody,
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"));
Expand Down
29 changes: 12 additions & 17 deletions src/common/gitProvider/utilsMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,34 @@ export function deployCodeCoverageToMarkdown(orgCoverage: number, orgCoverageTar
}
}

export async function flowDiffToMarkdown(flowNames: string[], fromCommit: string, toCommit: string): Promise<string> {
export async function flowDiffToMarkdown(flowNames: string[], fromCommit: string, toCommit: string): Promise<any> {
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 = `<details><summary>🤖 <b>${flowName}</b> 🤖</summary>
${flowDiffMarkdownMermaid}
</details>
<br/>
`
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 = `<details><summary>🤖 <b>${flowName}</b> 🤖</summary>
Unable to generate Flow diff: ${e.message}
const flowGenErrorMd = `# ${flowName}
</details>
<br/>
`
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8692c3a

Please sign in to comment.