Skip to content

[WIP] Delete old plan comments on PR update #1943

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ZIJ
Copy link
Contributor

@ZIJ ZIJ commented Apr 30, 2025

Currently on every PR update a bunch of new plan comments are appended to the PR. This creates a lot of noise, especially in large monorepos.

New behavior: delete old plan comments (not summaries!) before starting new batch of plan jobs

Summary by CodeRabbit

  • Documentation

    • Improved clarity and completeness of instructions in the README, including updates for migration commands and local PostgreSQL usage.
  • New Features

    • Added the ability to delete comments via GitHub integration.
    • Introduced a method to retrieve all jobs associated with a specific pull request.
  • Other Changes

    • Enhanced job tracking with an additional field for pull request comment IDs.
Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

Walkthrough

The changes introduce several updates across documentation and backend code. The README.md received formatting improvements and expanded instructions, particularly for PostgreSQL usage and migration commands. In the backend, the DiggerJob struct was extended with an optional PRCommentId field. The Database struct now includes a new method to fetch all jobs related to a specific pull request. Additionally, the GitHub service layer gained a method for deleting comments by ID, following existing error handling conventions.

Changes

File(s) Change Summary
README.md Improved formatting, clarified instructions, updated migration command, and added PostgreSQL usage notes.
backend/models/scheduler.go Added PRCommentId *int64 field to the DiggerJob struct.
backend/models/storage.go Added GetDiggerJobsForPR method to retrieve all jobs for a given PR, with error handling and logging.
libs/ci/github/github.go Added DeleteComment method to GithubService for deleting comments by ID, with error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Database
    participant Logger

    User->>Database: GetDiggerJobsForPR(orgId, repoFullName, prNumber)
    Database->>Database: Query DiggerBatch by repoFullName and prNumber
    Database->>Logger: Log error if batch query fails
    loop For each batch
        Database->>Database: GetDiggerJobsForBatch(batchId)
        Database->>Logger: Log error if job retrieval fails
    end
    Database->>Logger: Log summary info
    Database-->>User: Return aggregated jobs or error
Loading
sequenceDiagram
    participant Service
    participant GitHubAPI

    Service->>Service: DeleteComment(id string)
    Service->>GitHubAPI: DeleteComment(int64(id))
    GitHubAPI-->>Service: Success/Error
    Service-->>Caller: Return error if any
Loading

Poem

In README fields and backend code,
New methods and fields gently flowed.
With jobs for PRs now fetched with care,
And comments on GitHub vanish in air.
The rabbit hops, the docs refined—
Clearer steps for all combined!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR introduces functionality to manage comment noise in pull requests by deleting old plan comments when PRs are updated, particularly beneficial for large monorepos.

  • Added DeleteComment method in github.go to remove old plan comments via GitHub API
  • Introduced PRCommentId field in DiggerJob struct to track comment IDs for deletion
  • Added GetDiggerJobsForPR function in storage.go to retrieve all jobs associated with a PR
  • Consider documenting when PRCommentId should be null vs populated
  • Include PRCommentId in MapToJsonStruct() serialization for system-wide consistency

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +208 to +209
_, err = svc.Client.Issues.DeleteComment(context.Background(), svc.Owner, svc.RepoName, commentId)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding structured logging here to match the rest of the codebase's logging pattern

Comment on lines +1856 to +1867
allJobs := make([]DiggerJob, 0)
for _, batch := range batches {
jobs, err := db.GetDiggerJobsForBatch(batch.ID)
if err != nil {
slog.Error("error fetching digger jobs for batch",
"batchId", batch.ID,
"prNumber", prNumber,
"error", err)
return nil, err
}
allJobs = append(allJobs, jobs...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a single query with JOIN to fetch all jobs instead of multiple queries in a loop to improve performance

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: 0

🧹 Nitpick comments (2)
README.md (1)

85-86: Improve grammar in the PostgreSQL SSL note.

The phrasing could be improved for better clarity.

-Might need disabling ssl if running default docker image
+You might need to disable SSL if running the default Docker image
🧰 Tools
🪛 LanguageTool

[uncategorized] ~85-~85: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...irty ``` ## Local postgres Might need disabling ssl if running default docker image ``...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

backend/models/storage.go (1)

1842-1877: Well-implemented method to retrieve all jobs for a PR.

The new GetDiggerJobsForPR method effectively aggregates jobs across all batches for a specific PR, supporting the PR's objective of managing plan comments. The implementation includes proper error handling and detailed logging.

Consider adding a limit or pagination option if PRs with many batches could lead to performance concerns.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 349de90 and 67f1821.

📒 Files selected for processing (4)
  • README.md (5 hunks)
  • backend/models/scheduler.go (2 hunks)
  • backend/models/storage.go (1 hunks)
  • libs/ci/github/github.go (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~85-~85: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...irty ``` ## Local postgres Might need disabling ssl if running default docker image ``...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

🪛 markdownlint-cli2 (0.17.2)
README.md

87-87: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (4)
backend/models/scheduler.go (1)

55-55: Added PRCommentId field to track comment associations.

The addition of PRCommentId field as a nullable *int64 type allows for tracking which GitHub PR comments are associated with each digger job. This complements the new functionality to delete old plan comments on PR updates.

libs/ci/github/github.go (1)

203-210: Good implementation of DeleteComment method following existing patterns.

The implementation follows the same pattern as the existing EditComment method, with proper error handling for ID conversion and clear return of any GitHub API errors. This new method enables the deletion of old plan comments as described in the PR objectives.

README.md (2)

80-81: Added important flag to migration command.

Including the --allow-dirty flag in the migration command example provides better guidance for users running migrations.


88-88: Added useful example for DATABASE_URL with SSL disabled.

This provides clear guidance for users working with local PostgreSQL instances, which is helpful for developers setting up their environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant