Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only select diff lines #34

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

valentindeaconu
Copy link
Contributor

@valentindeaconu valentindeaconu commented Aug 30, 2024

Fixes #28.

We can pass the --unified=0 argument to the git diff command to only return actual diffs, without any contextual lines before and after. The action doesn't really need to select lines before and after the suggestion since the suggestion is annotated in GitHub and users can view the exact location of the changes in the UI.

This fixes the problem where the suggestion contains lines that are not part of the diff.


Example index.js
     1	const SOME_VARIABLE = "test";
     2	const SOME_OTHER_VARIABLE_TO_ADD_LINES = "new-test";
     3
     4	export function main(args) {
     5	  console.log("Hello, World!");
     6	}
     7
     8	function foo() {
     9	  console.log("foo");
    10	  console.log("bar");
    11	  console.log("baz");
    12	}
    13
    14	function bar() {
    15	  console.log("baz");
    16	  console.log("bar");
    17	  console.log("foo");
    18	}
Line deletion output

If we want to delete the line 9, git diff will output:

diff --git a/index.js b/index.js
index e7fad5537..bfe5e5fff 100644
--- a/index.js
+++ b/index.js
@@ -6,7 +6,6 @@ export function main(args) {
 }

 function foo() {
-  console.log("foo");
   console.log("bar");
   console.log("baz");
 }

while git diff --unified=0 will output:

diff --git a/index.js b/index.js
index e7fad5537..bfe5e5fff 100644
--- a/index.js
+++ b/index.js
@@ -9 +8,0 @@ function foo() {
-  console.log("foo");
Line addition output

If we want to add a line above the line 9, git diff will output:

diff --git a/index.js b/index.js
index e7fad5537..2c4768e93 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,7 @@ export function main(args) {
 }

 function foo() {
+  console.log("foo");
   console.log("foo");
   console.log("bar");
   console.log("baz");

while git diff --unified=0 will output:

diff --git a/index.js b/index.js
index e7fad5537..2c4768e93 100644
--- a/index.js
+++ b/index.js
@@ -8,0 +9 @@ function foo() {
+  console.log("foo");
Line modification output

If we want to change the line 9, git diff will output:

diff --git a/index.js b/index.js
index e7fad5537..5a7c6f20e 100644
--- a/index.js
+++ b/index.js
@@ -6,7 +6,7 @@ export function main(args) {
 }

 function foo() {
-  console.log("foo");
+  console.log("oof");
   console.log("bar");
   console.log("baz");
 }

while git diff --unified=0 will output:

diff --git a/index.js b/index.js
index e7fad5537..5a7c6f20e 100644
--- a/index.js
+++ b/index.js
@@ -9 +9 @@ function foo() {
-  console.log("foo");
+  console.log("oof");

Copy link
Owner

@parkerbxyz parkerbxyz left a comment

Choose a reason for hiding this comment

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

Thank you, @valentindeaconu! ✨

@parkerbxyz parkerbxyz merged commit ab5a7c4 into parkerbxyz:main Aug 30, 2024
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.

RequestError: Unprocessable Entity: Pull request review thread line must be part of the diff
2 participants