Skip to content

Support diff-informed queries under Default Setup #2817

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

Merged
merged 4 commits into from
Mar 21, 2025

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Mar 21, 2025

This PR extends the diff-informed queries functionality to also work under the Default Setup.

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 March 21, 2025 15:16
@Copilot Copilot AI review requested due to automatic review settings March 21, 2025 15:16
@cklin cklin requested a review from a team as a code owner March 21, 2025 15:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the diff-informed queries functionality to work under the Default Setup by introducing a new branch interface and updating diff-related functions.

  • Introduces a new interface (PullRequestBranches) and helper function (getPullRequestBranches) to consistently extract branch information.
  • Refactors several functions in both the src and lib directories to use the new branch structure.
  • Simplifies diff-informed query setup in analyze-action files by removing redundant pull_request checks.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

File Description
src/analyze.ts Updated to use PullRequestBranches; refactored diff range retrieval.
lib/analyze.js Updated to use PullRequestBranches; refactored diff range retrieval.
src/analyze-action.ts Removed direct pull_request usage, now relying on unified branch info.
lib/analyze-action.js Removed direct pull_request usage, now relying on unified branch info.
Comments suppressed due to low confidence (2)

src/analyze.ts:257

  • Ensure that the new branch handling logic in getPullRequestBranches is adequately tested for both scenarios: when the pull_request context is available and when falling back to the CODE_SCANNING_REF and CODE_SCANNING_BASE_BRANCH environment variables.
interface PullRequestBranches {

lib/analyze.js:162

  • Ensure that the new getPullRequestBranches implementation covers both the pull_request context and the Default Setup environment variable fallback case in the unit tests.
function getPullRequestBranches() {

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

NlightNFotis
NlightNFotis previously approved these changes Mar 21, 2025
Copy link
Member

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

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

Some minor comments, thank you for your work here.

// PR analysis under Default Setup analyzes the PR head commit instead of
// the merge commit, so we can use the provided ref directly.
head: codeScanningRef,
};
Copy link
Member

Choose a reason for hiding this comment

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

Can we get a (debug?) log message here that the environment variables weren't set in the else branch?

I'm thinking this might make it easier to identify where it goes wrong in the future, for either ourselves or an end user.

What are your thoughts on this one?

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 two info log statements:

  • One to indicate that we are not performing diff-informed analysis because we are not analyzing a PR
  • One to indicate that we are analyzing a PR, and what refs are being used for diff range calculation

@@ -254,6 +254,25 @@ async function finalizeDatabaseCreation(
};
}

interface PullRequestBranches {
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for this refactoring. I always appreciate bundling information into its own semantic bundle.

Would it be possible to get some documentation above the interface as to what it's supposed to signify? I think it's clear from the context, but it might make future mantainer's life better.

I think some of that documentation could be sourced from the previous @param documentation in the getPullRequestEditedDiffRanges function.

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 thought about it and decided that additional documentation would not have provided much value.

The interface is basically what the definition says: a record for storing the base and head branches of a pull request. Repeating the same thing in English does not seem to be all that useful.

Previous @param documentation for getPullRequestEditedDiffRanges() contains some useful information, and I have already incorporated them into code comments in getPullRequestBranches(). That documentation does not quite fit at the PullRequestBranches level, because the pull_request context is now only one of two possible sources for obtaining branch information. (When we set the head branch using CODE_SCANNING_REF, we are relying on the Default Setup workflow to set the environment variable correctly, without requiring the variable to use a head ref.)

All that is explained in getPullRequestBranches(), next to the code that creates PullRequestBranches values. I think that is a better place for that explanation because it is easier to keep the code comments up-to-date if the code needs to be changed in the future.

@cklin cklin force-pushed the cklin/default-setup-diff-informed branch from 35e42c3 to 9c674ba Compare March 21, 2025 16:25
@cklin cklin merged commit ac67cff into main Mar 21, 2025
270 checks passed
@cklin cklin deleted the cklin/default-setup-diff-informed branch March 21, 2025 16:47
@github-actions github-actions bot mentioned this pull request Mar 24, 2025
8 tasks
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