Skip to content

feat(Git Sync): UX improvements#8027

Merged
gatzjames merged 14 commits intoKong:developfrom
gatzjames:feature/git-improvements-v10
Oct 15, 2024
Merged

feat(Git Sync): UX improvements#8027
gatzjames merged 14 commits intoKong:developfrom
gatzjames:feature/git-improvements-v10

Conversation

@gatzjames
Copy link
Contributor

@gatzjames gatzjames commented Sep 30, 2024

Highlights:

  • Commit modal UX improvements
    • Align with Insomnia Sync UX
    • Diff viewer like in Insomnia Sync
    • Stage/Unstage changes
    • Undo pending changes (with prompt to not lose any data)
    • Auto-close the modal once there are no more changes to commit

Technical details:

Based on the architecture of isomorphic-git:

  • So far we relied on:
    • Reading the workspace and it's descendants on the database
    • Ask isomorphic-git if there are any changes on any of these files
  • With this change:
    • We tell isomorphic-git that there is always a .insomnia folder available
    • It automatically figures out if there are any changes and we don't need to do so in the database

This change improves the performance of checking for changes by an order of magnitude on my tests especially on large repos with hundreds of changes.

To improve performance further:

  • Currently when we check for changes we read the file contents and try to parse the YAML to read it's name in order to display it on the commit modal
  • We can have a separate function that only checks for changes using the git.statusMatrix function that will be much faster.

Closes INS-4486

Closes #8020

@gatzjames gatzjames self-assigned this Sep 30, 2024
@gatzjames gatzjames force-pushed the feature/git-improvements-v10 branch from 20ddf63 to 18b40a9 Compare October 14, 2024 07:51
@gatzjames gatzjames requested a review from a team October 14, 2024 07:54
for (const change of changes) {
console.log(`[git] Stage ${change.path} | ${change.status}`);
if (change.status[1] === 0) {
await git.remove({ ...this._baseOpts, filepath: convertToPosixSep(path.join('.', change.path)) });

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.
if (change.status[1] === 0) {
await git.remove({ ...this._baseOpts, filepath: convertToPosixSep(path.join('.', change.path)) });
} else {
await git.add({ ...this._baseOpts, filepath: convertToPosixSep(path.join('.', change.path)) });

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.
@gatzjames gatzjames force-pushed the feature/git-improvements-v10 branch from 735fc41 to f4834ce Compare October 15, 2024 10:15
@gatzjames gatzjames marked this pull request as ready for review October 15, 2024 10:15
Comment on lines +254 to +261
// expect(await GitVCS.status(barTxt)).toBe('*added');
// expect(await GitVCS.status(fooTxt)).toBe('*deleted');
// await GitVCS.remove(fooTxt);
// expect(await GitVCS.status(barTxt)).toBe('*added');
// expect(await GitVCS.status(fooTxt)).toBe('deleted');
// await GitVCS.remove(fooTxt);
// expect(await GitVCS.status(barTxt)).toBe('*added');
// expect(await GitVCS.status(fooTxt)).toBe('deleted');
Copy link
Contributor

@jackkav jackkav Oct 15, 2024

Choose a reason for hiding this comment

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

🔪 😉 🇧🇷

Comment on lines +392 to +398
const diff = {
head: result[1],
workdir: result[2],
stage: result[3],
};

return diff;
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

Comment on lines +296 to +301
if ((headType === 'tree' || headType === 'special') && !isBlob) {
return;
}
if (headType === 'commit') {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a significance of returning null or undefined here and below? may be worth a comment if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes according to the map function docs null will not walk the tree anymore while undefined will try to walk it's children

stageType !== 'blob'
) {
// We don't actually NEED the sha. Any sha will do
// TODO: update this logic to handle N trees instead of just 3.
Copy link
Contributor

Choose a reason for hiding this comment

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

💰

Comment on lines +488 to +490
const entry = [undefined, headOid, workdirOid, stageOid];
const result = entry.map(value => entry.indexOf(value));
result.shift();
Copy link
Contributor

Choose a reason for hiding this comment

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

can this use the same expression as above, where you name them out of the array

const { changes, statusNames } = await getGitChanges(GitVCS, workspace);
const { changes, hasUncommittedChanges } = await getGitChanges(GitVCS);

console.log('changes', changes);
Copy link
Contributor

Choose a reason for hiding this comment

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

oops

Comment on lines +853 to +861
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';

return { errors: [errorMessage] };
}
Copy link
Contributor

@jackkav jackkav Oct 15, 2024

Choose a reason for hiding this comment

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

its not clear why these special httperror cases exist, comment or a more meaningful variable name would help

Copy link
Contributor

@jackkav jackkav left a comment

Choose a reason for hiding this comment

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

nice

Copy link
Contributor

@jackkav jackkav left a comment

Choose a reason for hiding this comment

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

looks good, we should do a mob test on this before GA 10.1 though, likely there is an edge we can't catch by reviewing the code

@gatzjames gatzjames merged commit 275b48a into Kong:develop Oct 15, 2024
@gatzjames gatzjames deleted the feature/git-improvements-v10 branch October 15, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High CPU and memory consumption

2 participants