Skip to content

Conversation

zy9ard3
Copy link

@zy9ard3 zy9ard3 commented Aug 24, 2025

Proposed changes

No changes message for github custom template update can be [INF] instead of [ERR] for better logging

better logging

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Improved repository update logging: "already up-to-date" conditions are now reported as informational instead of errors, while real update failures remain errors. Error messages now include clearer repository context, producing more accurate, user-friendly logs and fewer false error alerts during routine updates.

@auto-assign auto-assign bot requested a review from dwisiswant0 August 24, 2025 19:58
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

Walkthrough

Updated error handling in Update (Git pull) in pkg/external/customtemplates/github.go: pullChanges errors matching git.NoErrAlreadyUpToDate are logged at Info; other errors are logged at Error. pullChanges now wraps Git pull errors with repository context via errors.Wrapf(...). No public signatures changed.

Changes

Cohort / File(s) Summary
GitHub custom templates: pull logging & error wrapping
pkg/external/customtemplates/github.go
In Update, treat git.NoErrAlreadyUpToDate returned from pullChanges as informational (log.Info) and log other errors as Error. In pullChanges, wrap Git pull errors with repository context using errors.Wrapf(…, "%s/%s") instead of errors.Errorf string formatting. No API changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Updater as Update()
    participant Git as pullChanges()
    participant Logger as Logger

    Updater->>Git: call pullChanges()
    alt success
        Git-->>Updater: nil
        Updater->>Logger: log Debug/Info (success)
    else already up-to-date
        Git-->>Updater: error (git.NoErrAlreadyUpToDate)
        Updater->>Logger: log Info ("already up-to-date")
    else other error
        Git-->>Updater: wrapped error (errors.Wrapf(... "%s/%s"))
        Updater->>Logger: log Error (propagate/handle)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge the branch, whiskers twitching in the night,
"No change," I say — a soft info, not a fright.
I wrap the name of repo, tidy in my lap,
log the quiet truth, then hop away — a nap. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 (4)
pkg/external/customtemplates/github.go (4)

56-60: Prefer sentinel error check over string matching for “already up-to-date”

String matching on error messages is brittle. go-git exposes the sentinel git.NoErrAlreadyUpToDate; use errors.Is against it and log a clear, structured message.

Apply this diff:

-        if strings.Contains(err.Error(), "already up-to-date") {
-            gologger.Info().Msgf("%s", err)
-        } else {
-            gologger.Error().Msgf("%s", err)
-        }
+        if errors.Is(err, git.NoErrAlreadyUpToDate) {
+            gologger.Info().Msgf("Repo %s/%s is already up-to-date.", customTemplate.owner, customTemplate.reponame)
+        } else {
+            gologger.Error().Msgf("%s", err)
+        }

Note: To make errors.Is work reliably here, ensure pullChanges returns the sentinel (not just a string-wrapped error). See suggested change on Lines 192-195.


192-195: Propagate sentinel error from pullChanges to enable robust handling upstream

pullChanges currently discards the original error by formatting it into a new string, making it impossible to distinguish “already up-to-date” at the call site without string matching. Return the sentinel directly for that case; for other errors, wrap (or annotate) while preserving the cause.

Apply this diff:

 err = w.Pull(pullOpts)
 if err != nil {
-    return errors.Errorf("%s/%s: %s", ctr.owner, ctr.reponame, err.Error())
+    if errors.Is(err, git.NoErrAlreadyUpToDate) {
+        // propagate sentinel so callers can detect and downgrade to info
+        return git.NoErrAlreadyUpToDate
+    }
+    // keep context but avoid losing the original cause
+    return errors.Errorf("%s/%s: pull failed: %s", ctr.owner, ctr.reponame, err.Error())
 }

Optional follow-up: if the codebase allows, prefer wrapping the cause using %w (fmt.Errorf) or errors.Wrapf to preserve the chain for errors.Is/As.


62-62: Remove trailing newline in log message for consistency

gologger adds line endings; the explicit “\n” is unnecessary and can cause formatting inconsistencies.

Apply this diff:

-        gologger.Info().Msgf("Repo %s/%s successfully pulled the changes.\n", customTemplate.owner, customTemplate.reponame)
+        gologger.Info().Msgf("Repo %s/%s successfully pulled the changes.", customTemplate.owner, customTemplate.reponame)

49-51: Typo in comment: “exits” → “exists”

Minor doc polish.

Apply this diff:

-    // If folder does not exits then clone/download the repo
+    // If folder does not exist then clone/download the repo
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 309018f and 5be258f.

📒 Files selected for processing (1)
  • pkg/external/customtemplates/github.go (1 hunks)

@@ -53,7 +53,11 @@ func (customTemplate *customTemplateGitHubRepo) Update(ctx context.Context) {
}
err := customTemplate.pullChanges(clonePath, customTemplate.githubToken)
if err != nil {
gologger.Error().Msgf("%s", err)
if strings.Contains(err.Error(), "already up-to-date") {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if strings.Contains(err.Error(), "already up-to-date") {
if errors.Is(err, git.NoErrAlreadyUpToDate) {

Copy link
Author

@zy9ard3 zy9ard3 Aug 26, 2025

Choose a reason for hiding this comment

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

@dwisiswant0

This doesn't appears to be working as if errors.Is(err, git.NoErrAlreadyUpToDate) is returning false

So, I've adjusted Errorf to Wrapf on PullChanges ( w.Pull ) and now it's working, please check...

@zy9ard3 zy9ard3 requested a review from dwisiswant0 August 26, 2025 03:59
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 (3)
pkg/external/customtemplates/github.go (3)

194-194: Prefer stdlib wrapping with %w to guarantee errors.Is/As interop

Wrapping with pkg/errors.Wrapf can be fine, but using the stdlib fmt.Errorf(... %w ...) avoids any ambiguity and guarantees seamless behavior with errors.Is/As across toolchains. It also ensures the upstream sentinel is preserved without relying on third-party unwrapping semantics.

Apply this diff in-place:

-		return errors.Wrapf(err, "%s/%s", ctr.owner, ctr.reponame)
+		return fmt.Errorf("%s/%s: %w", ctr.owner, ctr.reponame, err)

Additional small change outside this hunk (imports):

// add alongside existing imports
import "fmt"

If you keep pkg/errors, ensure it’s a version that implements Unwrap() so errors.Is keeps working; otherwise the check in Update may misclassify the condition.


61-63: Remove redundant newline in Msgf

Msgf doesn’t need a trailing newline; it’s handled by the logger. Minor polish.

-		gologger.Info().Msgf("Repo %s/%s successfully pulled the changes.\n", customTemplate.owner, customTemplate.reponame)
+		gologger.Info().Msgf("Repo %s/%s successfully pulled the changes.", customTemplate.owner, customTemplate.reponame)

56-60: Harden “already up-to-date” detection and clarify INFO message

Nice catch demoting this to Info. To make the check robust against wrapped errors (and pkg/errors vs. stdlib interop), you can test both errors.Is and a direct equality against git.NoErrAlreadyUpToDate, and log a more user-friendly message that includes the repo context:

-       if errors.Is(err, git.NoErrAlreadyUpToDate) {
-           gologger.Info().Msgf("%s", err)
-       } else {
-           gologger.Error().Msgf("%s", err)
-       }
+       // treat "already up-to-date" as an INFO (no-op) condition
+       if stderrors.Is(err, git.NoErrAlreadyUpToDate) || err == git.NoErrAlreadyUpToDate {
+           gologger.Info().Msgf("Repo %s/%s has no changes (already up-to-date).", customTemplate.owner, customTemplate.reponame)
+       } else {
+           gologger.Error().Msgf("%s", err)
+       }

Don’t forget to alias the stdlib errors package so it doesn’t clash with github.com/pkg/errors:

import (
    stderrors "errors"
    // …other imports…
)

This change will ensure the up-to-date case always logs at Info level and provides clearer context for users.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7debf and 1f0aef9.

📒 Files selected for processing (1)
  • pkg/external/customtemplates/github.go (2 hunks)

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