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

automerge failure patch #1917

Merged
merged 3 commits into from
Mar 25, 2025
Merged

automerge failure patch #1917

merged 3 commits into from
Mar 25, 2025

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Mar 25, 2025

temporary patch for failure to merge in #1906

Summary by CodeRabbit

  • New Features
    • Enhanced feedback for automatic pull request merges: if a merge attempt fails, a comment is posted with detailed error information.
    • Introduced a new function to facilitate posting comments on pull requests, improving error handling and communication.

Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Walkthrough

This pull request revises the error handling approach in the project controller. When automerging a pull request fails, the system now posts a comment on the associated batch with error details instead of directly returning an internal server error to the client. A new utility function, PostCommentForBatch, has been added to facilitate posting comments on GitHub pull requests. This function handles GitHub service retrieval and logs any errors encountered during its operations.

Changes

File(s) Change Summary
backend/controllers/projects.go Updated SetJobStatusForProject: On failure to automerge PR, posts a comment to the batch with error details instead of returning a JSON error; logs any failures to post the comment.
backend/utils/batch_utils.go Added new function PostCommentForBatch: Checks if the VCS is GitHub, retrieves a GitHub service via a client provider, attempts to post a comment on the PR, logs errors if service retrieval or posting fails.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Controller as SetJobStatusForProject
    participant AutoMerge as AutomergePRforBatchIfEnabled
    participant CommentUtil as PostCommentForBatch
    participant GitHubCP as GithubClientProvider
    participant GitHubSvc as GitHub Service
    participant Logger as Logger

    Controller ->> AutoMerge: Attempt auto merge PR
    AutoMerge -->> Controller: Return error if merge fails
    Controller ->> CommentUtil: Call PostCommentForBatch(batch, comment, GitHubCP)
    CommentUtil ->> CommentUtil: Check if VCS is GitHub
    CommentUtil ->> GitHubCP: Retrieve GitHub service using batch details
    GitHubCP -->> CommentUtil: Return service or error
    alt Service retrieved
        CommentUtil ->> GitHubSvc: Post comment on PR
        GitHubSvc -->> CommentUtil: Return success/error
    else Service retrieval error
        CommentUtil ->> Logger: Log retrieval error
    end
    alt Comment post error
        CommentUtil ->> Logger: Log posting error
    end

Poem

I'm just a bunny, hopping along,
Celebrating changes in code so strong.
No more crashing errors in our PR dance,
Instead, a friendly comment gets its chance.
With logs and code, our projects shine bright—
A carrot of success in every byte!
🥕🐇 Happy coding day and night!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41e63f7 and 7ab22df.

📒 Files selected for processing (1)
  • backend/utils/batch_utils.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/utils/batch_utils.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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

@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)
backend/utils/batch_utils.go (2)

9-25: Function implementation looks good, with minor improvements needed

The function correctly posts comments on GitHub PRs with proper error handling. However, there are a few issues to address:

  1. There's a grammatical error in the error message on line 20.
  2. The function lacks documentation.
  3. The function has redundant return statements.
  4. It silently returns nil for non-GitHub VCS without any warning.
+// PostCommentForBatch posts a comment on the pull request associated with the given batch.
+// It currently only supports GitHub repositories, with other VCS support planned.
+// Returns an error if the GitHub service cannot be retrieved or if posting the comment fails.
 func PostCommentForBatch(batch *models.DiggerBatch, comment string, githubClientProvider GithubClientProvider) error {
 	// todo: perform for rest of vcs as well
 	if batch.VCS == models.DiggerVCSGithub {
 		ghService, _, err := GetGithubService(githubClientProvider, batch.GithubInstallationId, batch.RepoFullName, batch.RepoOwner, batch.RepoName)
 		if err != nil {
 			log.Printf("error getting ghService: %v", err)
 			return fmt.Errorf("error getting ghService: %v", err)
 		}
 		_, err = ghService.PublishComment(batch.PrNumber, comment)
 		if err != nil {
 			log.Printf("error publishing comment (%v): %v", comment, err)
-			return fmt.Errorf("error getting publishing comment (%v): %v", comment, err)
+			return fmt.Errorf("error publishing comment (%v): %v", comment, err)
 		}
 		return nil
 	}
+	log.Printf("skipping comment posting for non-GitHub VCS: %s", batch.VCS)
 	return nil
 }

19-20: Fix error message grammatical error

The error message "error getting publishing comment" has a grammatical issue.

-			return fmt.Errorf("error getting publishing comment (%v): %v", comment, err)
+			return fmt.Errorf("error publishing comment (%v): %v", comment, err)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3378761 and a4c10fc.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • backend/controllers/projects.go (1 hunks)
  • backend/utils/batch_utils.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
backend/controllers/projects.go (1)
backend/utils/github.go (3)
  • err (174-174)
  • err (189-189)
  • GithubClientProvider (69-73)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (2)
backend/controllers/projects.go (1)

493-500: Improved error handling with user notification

The code now posts a GitHub comment when automerge fails instead of silently logging the error. This is a great improvement as it actively notifies users about the failure and reminds them to merge manually.

backend/utils/batch_utils.go (1)

10-10: Consider implementing support for other VCS systems

The TODO comment correctly flags the need to support other version control systems, but there's no defined timeline or issue tracking this work.

Could you create an issue to track this enhancement for other VCS platforms like GitLab which is already supported elsewhere in the codebase?

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

Based on the provided information, I'll summarize the key changes in this pull request focusing only on the most recent updates:

Enhanced error handling for automerge failures in Digger with improved user feedback:

  • Added new PostCommentForBatch function in /backend/utils/batch_utils.go to handle GitHub PR comment posting with proper error handling
  • Modified SetJobStatusForProject in /backend/controllers/projects.go to post warning comments instead of failing jobs when automerge fails
  • Improved error message formatting and logging for better clarity when automerge operations encounter issues

The changes effectively address issue #1906 by ensuring jobs complete successfully while providing clear feedback about merge failures.

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

_, err = ghService.PublishComment(batch.PrNumber, comment)
if err != nil {
log.Printf("error publishing comment (%v): %v", comment, err)
return fmt.Errorf("error getting publishing comment (%v): %v", comment, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Error message has incorrect wording 'error getting publishing comment' - should be 'error publishing comment'

Suggested change
return fmt.Errorf("error getting publishing comment (%v): %v", comment, err)
return fmt.Errorf("error publishing comment (%v): %v", comment, err)

}
return nil
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Silent failure for non-GitHub VCS types. Consider logging a warning or returning an error to indicate unsupported VCS type

@motatoes motatoes merged commit e40aac8 into develop Mar 25, 2025
12 checks passed
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.

1 participant