Skip to content

refactor: store diff in action object (#1693) - #1701

Open
amnkarn wants to merge 2 commits into
finos:mainfrom
amnkarn:fix-1693
Open

refactor: store diff in action object (#1693)#1701
amnkarn wants to merge 2 commits into
finos:mainfrom
amnkarn:fix-1693

Conversation

@amnkarn

@amnkarn amnkarn commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #1693

Description

This PR refactors getDiff and related consumers to store and access the git diff directly on the action object (action.diff). This makes it easier for plugins and subsequent actions (like scanDiff) to retrieve the diff without needing to extract it from the step content.

Changes Made

  • Backend: Updated getDiff to assign the diff string directly to action.diff and updated the Action interface.
  • Processors: Updated scanDiff.ts to retrieve the diff from action.diff.
  • UI: Updated PushActionView in types.ts to accept Step | string for the diff property.
  • UI Services: Modified getPush in git-push.ts to handle the new string format.

Backward Compatibility

To ensure historical database records and existing UI components do not break, fallback logic has been added. If action.diff is not present (or is not a string), the system gracefully falls back to extracting the content from steps.find((s) => s.stepName === 'diff')?.content in both scanDiff.ts and git-push.ts.

@amnkarn
amnkarn requested a review from a team as a code owner August 26, 2026 11:20
@netlify

netlify Bot commented Aug 26, 2026

Copy link
Copy Markdown

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 6a75417
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/6a8eccac60675c0008309419

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: amnkarn / name: Aman Karn (6a75417)
  • ✅ login: amnkarn / name: Aman Kumar Karn (ed30c23)

@dcoric dcoric left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @amnkarn, I verified the consumer coverage end-to-end (scanDiff, getPush, PushDetails, Cypress mocks) and the legacy fallbacks keep old DB records working, so the compat approach is right. Requesting changes on one compile-level issue plus a few design/test follow-ups:

  • PushActionView type breaks tsc (inline, blocking)
  • diff now persisted 3x per push (inline)
  • two test gaps (inline)
  • plugin access expectation (inline)

Also: the -40 lines in package-lock.json (removal of "extraneous": true entries) look like an unrelated npm-prune side effect from a local install. Could you revert them or move them to a separate PR so the diff stays clean?

Comment thread src/ui/types.ts

export interface PushActionView extends Omit<Action, ActionMethods> {
diff: Step;
diff: Step | string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Blocking] This introduces a TypeScript compile error:

src/ui/types.ts(56,18): error TS2430: Interface 'PushActionView' incorrectly extends interface 'Omit<Action, ActionMethods>'.
  Types of property 'diff' are incompatible.
    Type 'string | Step' is not assignable to type 'string | undefined'.
      Type 'Step' is not assignable to type 'string'.

Action.diff added in this PR is string | undefined, so this declaration no longer satisfies the base interface. Current PR CI doesn't run check-types, so it slips through, but it breaks npm run check-types and every contributor's IDE.

Suggested fix: diff: string | Step | undefined;. That is also more honest, since records without a diff step (e.g. tag pushes) are already undefined at runtime today.

const diff = await git.diff([revisionRange]);
action.diff = diff;
step.log(diff);
step.setContent(diff);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is now persisted in three places per push: action.diff, step content, and step logs. All three get serialized into the audit DB on every writeAudit (NeDB and Mongo). NeDB's getPushes has no projection, so the pushes-list payload also grows by another full-diff copy per push.

Now that all consumers read action.diff (the legacy fallback is only needed for old records), could we drop step.setContent(diff) and the full-diff step.log(diff) here and keep just a summary (e.g. diff size)? If you'd rather keep this PR minimal, let's at least note the extra storage copy in the description and track the cleanup as a follow-up.


const { steps, commitFrom, commitTo } = action;
step.log(`Scanning diff: ${commitFrom}:${commitTo}`);
const diff = action.diff ?? steps.find((s) => s.stepName === 'diff')?.content;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two test gaps worth closing:

  1. Precedence is untested. If action.diff and the diff step content ever diverge, this silently prefers action.diff. A test pinning that precedence would lock the semantics in (the legacy fallback itself is already covered by the existing scanDiff tests).
  2. getPush in test/ui/git-push.test.ts is only mocked with the legacy step shape, so the new typeof data.diff == 'string' branch has no coverage. A test with a top-level string diff (including the empty-string case, which should still win over the fallback) would help.

...data,
diff: data.steps.find((x: Step) => x.stepName === 'diff')!,
diff:
typeof data.diff == 'string'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use === over == to match codebase style.

One more expectation to manage: the plugin benefit from #1693 won't materialize from this change alone. Plugins are prepended to the chain, so they run before getDiff and can't read action.diff in the same pass. Real plugin access needs post-diff plugin positioning (part of the #1683 revamp scope). Worth softening that point in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor getDiff to store the diff into the action

2 participants