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

Add support for diff-informed queries #2559

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Oct 21, 2024

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@cklin cklin marked this pull request as ready for review October 22, 2024 15:43
@cklin cklin requested a review from a team as a code owner October 22, 2024 15:43
Copy link
Contributor

@henrymercer henrymercer left a comment

Choose a reason for hiding this comment

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

Thanks! I have a bunch of comments and questions — feel free to only address the ones that make sense.

Comment on lines 165 to 171
/**
* Deepen the git history of the given ref by one level. Errors are ignored.
*/
export const deepenGitHistory = async function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two comments about the additions to this file in general:

  • Why completely ignore errors? Does it make sense to at least debug log them?
  • Nit, optional: This PR adds a bunch of functionality that interacts with git — now might be a good time to pull this functionality out into its own file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error is indeed logged centrally within runGitCommand(). By "Errors are ignored", I was trying to convey that errors are not reported back to the caller. I have update the function documentation to clarify the behavior.

Moving the git interactions to its own file sounds like a good idea, though trying to incorporate that into this PR is a bit messy. Can I defer that to a dedicated PR after this one merges?

export const deepenGitHistory = async function () {
try {
await runGitCommand(
getOptionalInput("checkout_path"),
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth noting that this function (and others) only work when called from analyze or upload-sarif.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a note to the function documentation, here and for other git functions.

Comment on lines +230 to +243
"-c",
"core.quotePath=false",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain the difference between this approach and using the -z flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The -z flag affects only specific modes: --raw, --numstat, --name-only and --name-status. Since we need the actual diff line ranges (as opposed to only the file-level information), we cannot use any of these modes, and as a result specifying -z here has no effect.

src/analyze-action.ts Outdated Show resolved Hide resolved
src/analyze.ts Show resolved Hide resolved
src/analyze.ts Outdated Show resolved Hide resolved
const results = new Array<[string, number, number]>();

let changedFile = "";
for (const line of diffHunkHeaders) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general this seems to keep going when it sees certain kinds of unexpected items in the diff. It seems that there's a risk of missing changed files — should we be more robust here, or fail more eagerly, or is that not important for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you tell me more about the risk you see, and how the code can be made more robust?

@@ -161,6 +162,147 @@ export const determineBaseBranchHeadCommitOid = async function (
}
};

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: same comment about considering moving this bunch of self-contained functionality to a new file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see response to your earlier mention of the same suggestion.

src/analyze.ts Outdated Show resolved Hide resolved
src/analyze.ts Outdated Show resolved Hide resolved
@cklin
Copy link
Contributor Author

cklin commented Oct 24, 2024

Thanks! I have a bunch of comments and questions — feel free to only address the ones that make sense.

Thanks for the detailed comments and helpful suggestions! PTAL.

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.

2 participants