Skip to content

Conversation

@kohsuke
Copy link
Contributor

@kohsuke kohsuke commented Mar 3, 2025

Making the future commit re-collection easier by overriding the max days from the server side.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced repository operations by improving how server responses are processed, resulting in more reliable handling of shallow clone configurations.

kohsuke added 2 commits March 3, 2025 15:46
This makes it easier for us to retroactively collect and repopulate the
commits data from a prospect after they incorrectly configure
shallow-clone.
@kohsuke kohsuke requested a review from Konboi March 3, 2025 23:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

Walkthrough

The changes modify the CommitGraphCollector class by refactoring the transfer method. The HTTP GET response is now stored in a variable before being passed to getAdvertisedRefs. Additionally, a new private method honorMaxDaysHeader is introduced to inspect the HTTP response for an "X-Max-Days" header and update the maxDays variable accordingly. This update provides a mechanism to adjust the shallow clone configuration in response to server-provided header information.

Changes

File Path Change Summary
src/.../CommitGraphCollector.java Modified the transfer method: now stores HTTP GET response in a variable and passes it to getAdvertisedRefs; added private method honorMaxDaysHeader to check and update the maxDays variable based on the "X-Max-Days" header.

Sequence Diagram(s)

sequenceDiagram
    participant CGC as CommitGraphCollector
    participant S as Server
    CGC->>S: Send HTTP GET request
    S-->>CGC: Return HTTP response (latestResponse)
    CGC->>CGC: Call honorMaxDaysHeader(latestResponse)
    Note right of CGC: Check for "X-Max-Days" header and update maxDays
    CGC->>CGC: Call getAdvertisedRefs(latestResponse)
Loading

Poem

Oh, I hopped through lines of code so bright,
Found a header hiding in plain sight.
"X-Max-Days" whispered secrets anew,
Adjusting settings with a clever clue.
I celebrate these changes with a joyful, bouncy delight!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/java/com/launchableinc/ingest/commits/CommitGraphCollector.java (2)

179-179: Fix code style: add space after if.

The code style is inconsistent with the rest of the file: there should be a space after if.

-    if (h!=null) {
+    if (h != null) {

177-181: Consider adding validation for the maxDays value.

The method accepts any integer value from the header without validation. Consider adding bounds checking to ensure the value is positive and reasonable.

  private void honorMaxDaysHeader(HttpResponse response) {
    Header h = response.getFirstHeader("X-Max-Days");
    if (h != null) {
      try {
        int headerMaxDays = Integer.parseInt(h.getValue());
        if (headerMaxDays > 0) {
          maxDays = headerMaxDays;
          logger.debug("Max days overridden to {} from server header", maxDays);
        } else {
          logger.warn("Ignoring non-positive X-Max-Days header value: {}", headerMaxDays);
        }
      } catch (NumberFormatException e) {
        logger.warn("Invalid X-Max-Days header value: {}", h.getValue(), e);
      }
    }
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34704db and 809f46a.

⛔ Files ignored due to path filters (1)
  • launchable/jar/exe_deploy.jar is excluded by !**/*.jar
📒 Files selected for processing (1)
  • src/main/java/com/launchableinc/ingest/commits/CommitGraphCollector.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: build (windows-latest, 3.12)
  • GitHub Check: build (windows-latest, 3.11)
  • GitHub Check: build (windows-latest, 3.10)
  • GitHub Check: build (windows-latest, 3.9)
  • GitHub Check: build (windows-latest, 3.8)
  • GitHub Check: build (windows-latest, 3.7)
  • GitHub Check: build (windows-latest, 3.6)
  • GitHub Check: build (ubuntu-20.04, 3.12)
  • GitHub Check: build (ubuntu-20.04, 3.11)
  • GitHub Check: build (ubuntu-20.04, 3.10)
  • GitHub Check: build (ubuntu-20.04, 3.9)
  • GitHub Check: build (ubuntu-20.04, 3.8)
  • GitHub Check: build (ubuntu-20.04, 3.7)
  • GitHub Check: build (ubuntu-20.04, 3.6)
🔇 Additional comments (2)
src/main/java/com/launchableinc/ingest/commits/CommitGraphCollector.java (2)

127-129: Good refactoring to enable header inspection.

This change effectively stores the HTTP response in a variable before passing it to getAdvertisedRefs, enabling the inspection of response headers for the new max days override functionality.


343-343:

Details

❓ Verification inconclusive

Verify impact with updated maxDays value.

This line uses the maxDays value that can now be modified by the server through the "X-Max-Days" header. The override could significantly change the commit filtering behavior. Ensure this is the intended behavior.


🏁 Script executed:

#!/bin/bash
# Search for other places where maxDays is used to confirm that overriding it centrally is appropriate
rg "maxDays" --type java

Length of output: 709


Verify the Impact of the Updated maxDays Override

The code now allows the maxDays value to be modified via the "X-Max-Days" header in CommitGraphCollector.java and is passed from a default (30 days) in CommitIngester.java. This change affects the commit filtering logic—in particular, the filter uses the expression:

CommitTimeRevFilter.after(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(maxDays))

Please ensure that:

  • The override of maxDays via the HTTP header is an intentional design choice.
  • A non-default maxDays value (supplied by the header) does not inadvertently broaden or restrict the commit filtering beyond what is expected.
  • The interactions between CommitIngester.java and CommitGraphCollector.java regarding maxDays remain consistent and clear from a maintenance perspective.

Comment on lines +172 to +182
/**
* When a user incorrectly configures shallow clone, the incremental nature of commit collection
* makes it really hard for us and users to collaboratively reset and repopulate the commit data.
* This server-side override mechanism makes it easier.
*/
private void honorMaxDaysHeader(HttpResponse response) {
Header h = response.getFirstHeader("X-Max-Days");
if (h!=null) {
maxDays = Integer.parseInt(h.getValue());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for Integer parsing.

The method correctly extracts and processes the "X-Max-Days" header, but lacks error handling if the header value isn't a valid integer. This could cause runtime exceptions if the server provides a non-numeric value.

  private void honorMaxDaysHeader(HttpResponse response) {
    Header h = response.getFirstHeader("X-Max-Days");
    if (h!=null) {
-      maxDays = Integer.parseInt(h.getValue());
+      try {
+        maxDays = Integer.parseInt(h.getValue());
+        logger.debug("Max days overridden to {} from server header", maxDays);
+      } catch (NumberFormatException e) {
+        logger.warn("Invalid X-Max-Days header value: {}", h.getValue(), e);
+      }
    }
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* When a user incorrectly configures shallow clone, the incremental nature of commit collection
* makes it really hard for us and users to collaboratively reset and repopulate the commit data.
* This server-side override mechanism makes it easier.
*/
private void honorMaxDaysHeader(HttpResponse response) {
Header h = response.getFirstHeader("X-Max-Days");
if (h!=null) {
maxDays = Integer.parseInt(h.getValue());
}
}
/**
* When a user incorrectly configures shallow clone, the incremental nature of commit collection
* makes it really hard for us and users to collaboratively reset and repopulate the commit data.
* This server-side override mechanism makes it easier.
*/
private void honorMaxDaysHeader(HttpResponse response) {
Header h = response.getFirstHeader("X-Max-Days");
if (h!=null) {
try {
maxDays = Integer.parseInt(h.getValue());
logger.debug("Max days overridden to {} from server header", maxDays);
} catch (NumberFormatException e) {
logger.warn("Invalid X-Max-Days header value: {}", h.getValue(), e);
}
}
}

Copy link
Contributor

@Konboi Konboi left a comment

Choose a reason for hiding this comment

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

Make sense!

@kohsuke kohsuke merged commit 7d30646 into main May 27, 2025
18 checks passed
@kohsuke kohsuke deleted the max-days-override branch May 27, 2025 19:03
@github-actions github-actions bot mentioned this pull request May 26, 2025
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.

3 participants