From 29f3fc355300ef571fc731a3bbb36db6a806befa Mon Sep 17 00:00:00 2001 From: Nicolas Vuillamy Date: Tue, 31 Dec 2024 00:06:09 +0100 Subject: [PATCH] More fixes about Flow Git Diff & Doc (#957) * Add warning sign when a flow is disabled * fetch-depth for monitoring * Fix get deployment Id from JSON * Fix git listing * fixes --- defaults/monitoring/.gitlab-ci.yml | 1 + src/common/gitProvider/utilsMarkdown.ts | 2 +- src/common/utils/deployUtils.ts | 2 ++ src/common/utils/flowVisualiser/nodeFormatUtils.ts | 12 ++++++++++++ src/common/utils/gitUtils.ts | 14 ++++++++++---- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/defaults/monitoring/.gitlab-ci.yml b/defaults/monitoring/.gitlab-ci.yml index cf69d4ab9..92a61f11a 100644 --- a/defaults/monitoring/.gitlab-ci.yml +++ b/defaults/monitoring/.gitlab-ci.yml @@ -8,6 +8,7 @@ variables: FORCE_COLOR: "1" + GIT_FETCH_EXTRA_FLAGS: --depth 10000 # Pipeline stages stages: diff --git a/src/common/gitProvider/utilsMarkdown.ts b/src/common/gitProvider/utilsMarkdown.ts index 9780fd5bf..80546cbe0 100644 --- a/src/common/gitProvider/utilsMarkdown.ts +++ b/src/common/gitProvider/utilsMarkdown.ts @@ -94,7 +94,7 @@ export async function flowDiffToMarkdownForPullRequest(flowNames: string[], from await generateDiffMarkdownWithSvg(fileMetadata, fromCommit, toCommit, flowDiffMarkdownList, flowName); } } catch (e: any) { - uxLog(this, c.yellow(`[FlowGitDiff] Unable to generate Flow diff: ${e.message}`)); + uxLog(this, c.yellow(`[FlowGitDiff] Unable to generate Flow diff for ${flowName}: ${e.message}`)); const flowGenErrorMd = `# ${flowName} Error while generating Flows visual git diff diff --git a/src/common/utils/deployUtils.ts b/src/common/utils/deployUtils.ts index b171827c8..28bf30a6f 100644 --- a/src/common/utils/deployUtils.ts +++ b/src/common/utils/deployUtils.ts @@ -438,6 +438,7 @@ async function getDeploymentId(rawLog: string) { if (jsonLog) { const deploymentId = jsonLog?.result?.id || null; if (deploymentId) { + globalThis.pullRequestDeploymentId = deploymentId; return deploymentId; } } @@ -448,6 +449,7 @@ async function getDeploymentId(rawLog: string) { globalThis.pullRequestDeploymentId = deploymentId; return deploymentId; } + uxLog(this, c.yellow(`Unable to find deploymentId in logs \n${c.grey(rawLog)}`)); return null; } diff --git a/src/common/utils/flowVisualiser/nodeFormatUtils.ts b/src/common/utils/flowVisualiser/nodeFormatUtils.ts index 3082f1fb8..45fd35ac6 100644 --- a/src/common/utils/flowVisualiser/nodeFormatUtils.ts +++ b/src/common/utils/flowVisualiser/nodeFormatUtils.ts @@ -13,6 +13,14 @@ const FIELDS_WITH_VALUES_TO_FORMAT = [ "type" ]; +const FIELDS_WITH_VALUES_TO_FORMAT_ENUM = { + "status": { + "Draft": "⚠️ Draft", + "Inactive": "⚠️ Inactive", + "InvalidDraft": "⚠️ Invalid Draft" + } +} + const FIELDS_PREFERRED_ORDER_START = [ "type", "object", @@ -20,6 +28,7 @@ const FIELDS_PREFERRED_ORDER_START = [ "triggerType", "recordTriggerType", "label", + "status", "actionType", "actionName", "dataType", @@ -338,6 +347,9 @@ export function stringifyValue(valueIn: any, field: string, allProperties: strin if (allProperties.includes(valueStringified)) { valueStringified = `[${valueStringified}](#${valueStringified.toLowerCase()})` } + else if (FIELDS_WITH_VALUES_TO_FORMAT_ENUM[field] && FIELDS_WITH_VALUES_TO_FORMAT_ENUM[field][valueStringified]) { + valueStringified = FIELDS_WITH_VALUES_TO_FORMAT_ENUM[field][valueStringified]; + } else if (FIELDS_WITH_VALUES_TO_FORMAT.includes(field)) { valueStringified = prettifyFieldName(valueStringified); if (field === "type" && valueStringified.endsWith("s")) { diff --git a/src/common/utils/gitUtils.ts b/src/common/utils/gitUtils.ts index ab6036d16..cbd6c89fc 100644 --- a/src/common/utils/gitUtils.ts +++ b/src/common/utils/gitUtils.ts @@ -1,6 +1,7 @@ import { getConfig } from '../../config/index.js'; import { prompts } from './prompts.js'; import c from 'chalk'; +import fs from "fs-extra"; import * as path from "path"; import sortArray from 'sort-array'; import { @@ -186,8 +187,13 @@ export async function computeCommitsSummary(checkOnly, pullRequestInfo: any) { const updatedFiles = await getCommitUpdatedFiles(logResult.hash); for (const updatedFile of updatedFiles) { if (updatedFile.endsWith(".flow-meta.xml")) { - const flowName = path.basename(updatedFile, ".flow-meta.xml"); - flowList.push(flowName); + if (fs.existsSync(updatedFile)) { + const flowName = path.basename(updatedFile, ".flow-meta.xml"); + flowList.push(flowName); + } + else { + uxLog(this, c.yellow(`[FlowGitDiff] Unable to find Flow file ${updatedFile} (probably has been deleted)`)); + } } } } @@ -214,9 +220,9 @@ async function collectTicketsAndManualActions(str: string, tickets: Ticket[], ma } export async function getCommitUpdatedFiles(commitHash) { - const result = await git().show(["--name-only", commitHash]); + const result = await git().show(["--name-only", "--pretty=format:", commitHash]); // Split the result into lines (file paths) and remove empty lines - const files = result.split('\n').filter(file => file.trim() !== ''); + const files = result.split('\n').filter(file => file.trim() !== '' && fs.existsSync(file)); return files; }