Skip to content

No changes message for github custom template update to INF from ERR for better logging#6422

Merged
Mzack9999 merged 5 commits intoprojectdiscovery:devfrom
zy9ard3:dev
Sep 12, 2025
Merged

No changes message for github custom template update to INF from ERR for better logging#6422
Mzack9999 merged 5 commits intoprojectdiscovery:devfrom
zy9ard3:dev

Conversation

@zy9ard3
Copy link
Contributor

@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" is now informational instead of an error. Update failures remain errors, and messages include clearer repository context for 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

Walkthrough

Refactors GitHub custom templates pull flow in pkg/external/customtemplates/github.go: introduces a dedicated pull-result handler and centralized logging, replaces error wrapping with errkit.Wrapf including repo context, and adds helper logging methods; control flow distinguishes success, already-up-to-date, and other errors. No public signatures changed.

Changes

Cohort / File(s) Summary
GitHub custom templates: pull-result handler & logging
pkg/external/customtemplates/github.go
Introduces handlePullChanges(clonePath string) and helper logging methods (logPullSuccess(), logAlreadyUpToDate(err), logPullError(err)). Update delegates pull handling to the new handler. Pull errors are wrapped with repository context using errkit.Wrapf(err, "%s/%s", ...). Control flow: success -> logPullSuccess; git.NoErrAlreadyUpToDate -> logAlreadyUpToDate; otherwise -> logPullError. Minor comment typo fix. No public API changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Update as Update()
    participant Pull as pullChanges()
    participant Handler as handlePullChanges()
    participant Logger as Logger

    Update->>Pull: call pullChanges(clonePath)
    Pull-->>Update: (err)
    Update->>Handler: handlePullChanges(err)
    alt err == nil
        Handler->>Logger: logPullSuccess() (Debug/Info)
    else err is git.NoErrAlreadyUpToDate
        Handler->>Logger: logAlreadyUpToDate(err) (Info)
    else other err
        Handler->>Logger: logPullError(err) (Error)
        Note over Pull: error wrapped with repo context via errkit.Wrapf
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and directly describes the PR's main change—switching the "no changes" log message for GitHub custom template updates from ERR to INF to improve logging—and aligns with the provided PR description and code summary. It is specific to the primary change and clear enough for a reviewer to understand the intent.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Poem

I tug the branch with careful paws and cheer,
"No change" or "pulled" — I log what I hear.
I wrap the repo name, tidy as a map,
then hop away content, a small code-savvy chap. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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)

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
Contributor 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...

Co-authored-by: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com>
@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)

@Mzack9999 Mzack9999 self-requested a review September 12, 2025 15:19
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 (4)
pkg/external/customtemplates/github.go (4)

50-50: Minor comment grammar

Suggestion: “If folder does not exist, clone the repo.”

-	// If folder does not exist then clone/download the repo
+	// If the folder does not exist, clone the repo

74-77: Remove trailing newline and tighten message

gologger adds its own line ending. Also simplify the text.

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

79-82: Prefer an explicit, non-error-looking INFO message

Printing the wrapped error string for the no-change case can still look like an error. Be explicit and consistent with the PR objective.

-	gologger.Info().Msgf("%s", err)
+	gologger.Info().Msgf("Repo %s/%s is already up-to-date.", customTemplate.owner, customTemplate.reponame)

217-217: Wrap with repo context is good; consider wrapping other returns in this function too

For consistency, also wrap errors from Validate/Open/Worktree with repo context.

Example (outside changed range, for illustration only):

if err := pullOpts.Validate(); err != nil {
    return fmt.Errorf("%s/%s: %w", ctr.owner, ctr.reponame, err)
}
r, err := git.PlainOpen(repoPath)
if err != nil {
    return fmt.Errorf("%s/%s: %w", ctr.owner, ctr.reponame, err)
}
w, err := r.Worktree()
if err != nil {
    return fmt.Errorf("%s/%s: %w", ctr.owner, ctr.reponame, 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 1f0aef9 and fde6f72.

📒 Files selected for processing (1)
  • pkg/external/customtemplates/github.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: Format Go code using go fmt
Run static analysis with go vet

Files:

  • pkg/external/customtemplates/github.go
🔇 Additional comments (3)
pkg/external/customtemplates/github.go (3)

56-58: Good: centralized pull-result handling

Delegating to handlePullChanges simplifies Update() and aligns with the PR goal.


84-87: LGTM: error path remains at ERR level

This keeps genuine pull failures visible.


16-16: No change required — errkit.Wrapf preserves Unwrap semantics
errkit.Wrapf implements Go 1.13-compatible Unwrap chaining, so errors.Is will match sentinels like go-git/v5.NoErrAlreadyUpToDate.

@Mzack9999
Copy link
Member

@coderabbitai resolve
@coderabbitai make an issue for this PR with the implemented changes

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

🧩 Analysis chain

I'll resolve the review comments and create an issue documenting the implemented changes.


🏁 Script executed:

#!/bin/bash
# Get detailed information about the PR changes
gh pr view 6422 --json title,body,author,url,files,additions,deletions

# Get the diff to understand the specific changes made
gh pr diff 6422

# Get the commit messages to understand the implementation details
gh pr view 6422 --json commits

Length of output: 6542


Now I'll create an issue documenting the implemented changes from this PR.

@Mzack9999 I've created an issue documenting the implemented changes from this PR. The issue covers the enhanced GitHub custom template logging system, improved error handling, and the structural refactoring that was completed.


🏁 Script executed:

#!/bin/bash
# Create an issue documenting the implemented changes
gh issue create \
  --title "Implemented: Enhanced GitHub Custom Template Logging and Error Handling" \
  --body "## Overview

This issue documents the changes implemented in PR #6422 to improve GitHub custom template update logging and error handling.

## Implemented Changes

### Logging Improvements
- Changed \"already up-to-date\" messages from **ERR** level to **INF** level for better logging experience
- Centralized logging with dedicated helper methods:
  - \`logPullSuccess()\` - for successful pulls
  - \`logAlreadyUpToDate()\` - for no-change scenarios (now INFO level)
  - \`logPullError()\` - for actual errors

### Code Structure Enhancements
- Refactored pull flow with new \`handlePullChanges()\` method for better organization
- Improved error handling using \`errkit.Wrapf()\` for better error context
- Added three-path control flow for pull results:
  - Success → Info log
  - Already up-to-date → Info log (previously Error)
  - Actual errors → Error log

### Technical Details
- File modified: \`pkg/external/customtemplates/github.go\`
- Added import: \`errkit\`
- Fixed minor comment typo: \"exits\" → \"exist\"
- Total changes: +33 additions, -6 deletions

## Benefits
- Reduced false error alerts during routine template updates
- More accurate and user-friendly logging
- Better error context with repository information
- Cleaner code organization with centralized logging

## References
- **Original PR**: https://github.com/projectdiscovery/nuclei/pull/6422
- **Author**: @zy9ard3
- **Contributors**: @dwisiswant0
- **Requester**: @Mzack9999

## Status
✅ **Implemented** - Changes have been successfully merged and are now part of the codebase." \
  --assignee "Mzack9999"

Length of output: 54


Perfect! I've successfully completed both requested actions:

  1. Resolved all review comments in this PR
  2. Created issue Implemented: Enhanced GitHub Custom Template Logging and Error Handling #6476 documenting the implemented changes: Implemented: Enhanced GitHub Custom Template Logging and Error Handling #6476

The issue comprehensively documents the enhanced GitHub custom template logging and error handling improvements that were implemented in PR #6422, including the key change from ERR to INF level logging for "already up-to-date" scenarios and the structural refactoring with centralized logging methods.

✅ Actions performed

Comments resolved.

@Mzack9999 Mzack9999 merged commit 876974f into projectdiscovery:dev Sep 12, 2025
21 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.

Implemented: Enhanced GitHub Custom Template Logging and Error Handling

3 participants