From ed30c233a7addf2d798ce427303e335595cd3ab0 Mon Sep 17 00:00:00 2001 From: Aman Kumar Karn Date: Wed, 26 Aug 2026 16:35:29 +0530 Subject: [PATCH] refactor: store diff in action object (#1693) --- package-lock.json | 51 ------------------- src/proxy/actions/Action.ts | 1 + src/proxy/processors/push-action/getDiff.ts | 1 + src/proxy/processors/push-action/scanDiff.ts | 7 ++- src/ui/services/git-push.ts | 5 +- src/ui/types.ts | 2 +- src/ui/views/PushDetails/PushDetails.tsx | 8 ++- test/fixtures/test-package/package-lock.json | 42 +++++++-------- .../integration/forcePush.integration.test.ts | 4 ++ test/processors/getDiff.test.ts | 4 +- 10 files changed, 44 insertions(+), 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7bdeca97b..78a1d58dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2218,18 +2218,6 @@ "react-dom": "^16.8.0 || ^17.0.0" } }, - "node_modules/@finos/git-proxy/node_modules/@types/react": { - "version": "17.0.93", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.93.tgz", - "integrity": "sha512-KM4Ty/ZTLZupiYxZVAlP+InNJS3De6uBMdq0ePa6/04+eG9Y7ftnWfst1xTLQ5rwAhgHwQ4momt/O4KepdGBTw==", - "extraneous": true, - "license": "MIT", - "dependencies": { - "@types/prop-types": "*", - "@types/scheduler": "^0.16", - "csstype": "^3.2.2" - } - }, "node_modules/@finos/git-proxy/node_modules/dom-serializer": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", @@ -4303,17 +4291,6 @@ "assertion-error": "^2.0.1" } }, - "node_modules/@types/chai": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", - "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/deep-eql": "*", - "assertion-error": "^2.0.1" - } - }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -4532,13 +4509,6 @@ "@types/passport": "*" } }, - "node_modules/@types/prop-types": { - "version": "15.7.15", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", - "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "extraneous": true, - "license": "MIT" - }, "node_modules/@types/qs": { "version": "6.15.1", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz", @@ -4581,13 +4551,6 @@ "@types/react": "*" } }, - "node_modules/@types/scheduler": { - "version": "0.16.8", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.8.tgz", - "integrity": "sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==", - "extraneous": true, - "license": "MIT" - }, "node_modules/@types/send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", @@ -16953,20 +16916,6 @@ } } }, - "node_modules/vite-tsconfig-paths/node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "extraneous": true, - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/vite/node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", diff --git a/src/proxy/actions/Action.ts b/src/proxy/actions/Action.ts index 66dc172b1..2766e9df9 100644 --- a/src/proxy/actions/Action.ts +++ b/src/proxy/actions/Action.ts @@ -62,6 +62,7 @@ class Action { commitData?: CommitData[] = []; commitFrom?: string; commitTo?: string; + diff?: string; branch?: string; message?: string; author?: string; diff --git a/src/proxy/processors/push-action/getDiff.ts b/src/proxy/processors/push-action/getDiff.ts index 445b119e4..723405291 100644 --- a/src/proxy/processors/push-action/getDiff.ts +++ b/src/proxy/processors/push-action/getDiff.ts @@ -49,6 +49,7 @@ const exec = async (_req: Request, action: Action): Promise => { step.log(`Executing "git diff ${commitFrom} ${action.commitTo}" in ${path}`); const revisionRange = `${commitFrom}..${action.commitTo}`; const diff = await git.diff([revisionRange]); + action.diff = diff; step.log(diff); step.setContent(diff); } catch (error: unknown) { diff --git a/src/proxy/processors/push-action/scanDiff.ts b/src/proxy/processors/push-action/scanDiff.ts index a9cfa5d78..9410c9b53 100644 --- a/src/proxy/processors/push-action/scanDiff.ts +++ b/src/proxy/processors/push-action/scanDiff.ts @@ -179,11 +179,10 @@ const exec = async (_req: Request, action: Action): Promise => { const { steps, commitFrom, commitTo } = action; step.log(`Scanning diff: ${commitFrom}:${commitTo}`); + const diff = action.diff ?? steps.find((s) => s.stepName === 'diff')?.content; - const diff = steps.find((s) => s.stepName === 'diff')?.content; - - step.log(diff); - const diffViolations = getDiffViolations(diff, action.project, step); + step.log(diff as string); + const diffViolations = getDiffViolations(diff as string, action.project, step); if (diffViolations) { const formattedMatches = Array.isArray(diffViolations) diff --git a/src/ui/services/git-push.ts b/src/ui/services/git-push.ts index f2522ccf2..b72d30eae 100644 --- a/src/ui/services/git-push.ts +++ b/src/ui/services/git-push.ts @@ -30,7 +30,10 @@ const getPush = async (id: string): Promise> => { const data: Action = response.data; const actionView: PushActionView = { ...data, - diff: data.steps.find((x: Step) => x.stepName === 'diff')!, + diff: + typeof data.diff == 'string' + ? data.diff + : data.steps.find((x: Step) => x.stepName === 'diff')!, }; return successResult(actionView); } catch (error: unknown) { diff --git a/src/ui/types.ts b/src/ui/types.ts index 8d125221a..b9afffa5b 100644 --- a/src/ui/types.ts +++ b/src/ui/types.ts @@ -54,7 +54,7 @@ export interface BackendResponse { } export interface PushActionView extends Omit { - diff: Step; + diff: Step | string; } export interface RepoView extends Repo { diff --git a/src/ui/views/PushDetails/PushDetails.tsx b/src/ui/views/PushDetails/PushDetails.tsx index f54ed0dee..2936bae60 100644 --- a/src/ui/views/PushDetails/PushDetails.tsx +++ b/src/ui/views/PushDetails/PushDetails.tsx @@ -232,7 +232,11 @@ const PushDetails = () => { if (!push) return
No push data found
; const commitCount = push.commitData?.length ?? 0; - const changeFileCount = countDiffFiles(push.diff?.content ?? ''); + const diffText = + typeof push.diff === 'string' + ? push.diff + : (push.diff?.content ?? push.steps?.find((s) => s.stepName === 'diff')?.content ?? ''); + const changeFileCount = countDiffFiles(diffText); const stepCount = push.steps?.length ?? 0; let statusTitle: PushStatusTitle = 'Pending'; @@ -456,7 +460,7 @@ const PushDetails = () => { - + diff --git a/test/fixtures/test-package/package-lock.json b/test/fixtures/test-package/package-lock.json index fd06b72be..a77041309 100644 --- a/test/fixtures/test-package/package-lock.json +++ b/test/fixtures/test-package/package-lock.json @@ -20,11 +20,13 @@ ], "dependencies": { "@aws-sdk/credential-providers": "^3.980.0", - "@fontsource/roboto": "^5.2.9", - "@material-ui/core": "^4.12.4", - "@material-ui/icons": "4.11.3", - "@primer/octicons-react": "^19.21.2", + "@headlessui/react": "^2.2.10", + "@heroicons/react": "^2.2.0", + "@primer/octicons-react": "^19.23.1", + "@primer/primitives": "^11.6.0", + "@primer/react": "^38.17.0", "@seald-io/nedb": "^4.1.2", + "@tanstack/react-query": "^5.97.0", "agent-base": "^7.1.4", "axios": "^1.18.1", "bcryptjs": "^3.0.3", @@ -39,8 +41,8 @@ "express-http-proxy": "^2.1.2", "express-rate-limit": "^8.2.1", "express-session": "^1.19.0", - "font-awesome": "^4.7.0", "history": "5.3.0", + "html-react-parser": "^5.2.17", "httpntlm": "^1.8.13", "https-proxy-agent": "^7.0.6", "isomorphic-git": "^1.36.3", @@ -48,19 +50,17 @@ "load-plugin": "^6.0.3", "lodash": "^4.17.23", "lusca": "^1.7.0", - "material-design-icons": "^3.0.1", - "moment": "^2.30.1", + "luxon": "^3.7.2", "mongodb": "^5.9.2", "openid-client": "^6.8.1", "parse-diff": "^0.11.1", "passport": "^0.7.0", "passport-activedirectory": "^1.4.0", "passport-local": "^1.0.0", - "perfect-scrollbar": "^1.5.6", - "react": "^16.14.0", - "react-dom": "^16.14.0", - "react-html-parser": "^2.0.2", - "react-router-dom": "^6.30.4", + "react": "^19.2.5", + "react-dom": "^19.2.5", + "react-is": "^19.0.0", + "react-router": "^7.14.1", "simple-git": "^3.30.0", "ssh2": "~1.17.0", "uuid": "^14.0.0", @@ -77,32 +77,33 @@ "@commitlint/cli": "^19.8.1", "@commitlint/config-conventional": "^19.8.1", "@eslint/compat": "^2.0.2", - "@eslint/js": "^9.39.2", + "@eslint/js": "^9.39.4", "@eslint/json": "^2.0.0", + "@tailwindcss/vite": "^4.2.2", "@types/activedirectory2": "^1.2.6", "@types/cors": "^2.8.19", - "@types/domutils": "^2.1.0", "@types/express": "^5.0.6", "@types/express-http-proxy": "^1.6.7", "@types/express-session": "^1.18.2", "@types/jsonwebtoken": "^9.0.10", - "@types/lodash": "^4.17.23", + "@types/lodash": "^4.17.24", "@types/lusca": "^1.7.5", + "@types/luxon": "^3.7.1", "@types/node": "^22.19.7", "@types/passport": "^1.0.17", "@types/passport-local": "^1.0.38", - "@types/react-dom": "^17.0.26", - "@types/react-html-parser": "^2.0.7", + "@types/react": "^19.2.14", + "@types/react-dom": "^19.2.3", "@types/ssh2": "^1.15.5", "@types/supertest": "^7.2.0", "@types/validator": "^13.15.10", "@types/yargs": "^17.0.35", "@vitejs/plugin-react": "^6.0.2", - "@vitest/coverage-v8": "^3.2.7", + "@vitest/coverage-v8": "^4.1.8", "c8": "^11.0.0", "cross-env": "^10.1.0", "cypress": "^15.18.1", - "eslint": "^9.39.2", + "eslint": "^9.39.4", "eslint-config-prettier": "^10.1.8", "eslint-plugin-cypress": "^5.2.1", "eslint-plugin-license-header": "^0.9.0", @@ -115,13 +116,14 @@ "prettier": "^3.8.1", "quicktype": "^23.2.6", "supertest": "^7.2.2", + "tailwindcss": "^4.2.2", "ts-node": "^10.9.2", "tsx": "^4.21.0", "typescript": "^6.0.3", "typescript-eslint": "^8.61.1", "vite": "^8.0.14", "vite-tsconfig-paths": "^5.1.4", - "vitest": "^3.2.7" + "vitest": "^4.1.8" }, "engines": { "node": ">=22.13.1 || >=24.0.0" diff --git a/test/integration/forcePush.integration.test.ts b/test/integration/forcePush.integration.test.ts index 50e520b60..ed8bba07c 100644 --- a/test/integration/forcePush.integration.test.ts +++ b/test/integration/forcePush.integration.test.ts @@ -116,6 +116,10 @@ describe('Force Push Integration Test', () => { expect(typeof diffStep.content).toBe('string'); expect(diffStep.content.length).toBeGreaterThan(0); + expect(typeof afterGetDiff.diff).toBe('string'); + expect((afterGetDiff.diff as string).length).toBeGreaterThan(0); + expect(afterGetDiff.diff).toEqual(diffStep.content); + const afterScanDiff = await scanDiff(req, afterGetDiff); const scanStep = afterScanDiff.steps.find((s: Step) => s.stepName === 'scanDiff'); diff --git a/test/processors/getDiff.test.ts b/test/processors/getDiff.test.ts index af2f4eb4a..507435c0a 100644 --- a/test/processors/getDiff.test.ts +++ b/test/processors/getDiff.test.ts @@ -73,8 +73,8 @@ describe('getDiff', () => { const result = await exec({} as Request, action); expect(result.steps[0].error).toBe(false); - expect(result.steps[0].content).toContain('modified content'); - expect(result.steps[0].content).toContain('initial content'); + expect(result.diff).toContain('modified content'); + expect(result.diff).toContain('initial content'); }); it('should get diff between commits with no changes', async () => {