mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 22:55:27 +00:00
Merge pull request #6422 from zy9ard3/dev
No changes message for github custom template update to INF from ERR for better logging
This commit is contained in:
commit
876974f38b
37
pkg/external/customtemplates/github.go
vendored
37
pkg/external/customtemplates/github.go
vendored
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/projectdiscovery/gologger"
|
"github.com/projectdiscovery/gologger"
|
||||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
||||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||||
|
"github.com/projectdiscovery/utils/errkit"
|
||||||
fileutil "github.com/projectdiscovery/utils/file"
|
fileutil "github.com/projectdiscovery/utils/file"
|
||||||
folderutil "github.com/projectdiscovery/utils/folder"
|
folderutil "github.com/projectdiscovery/utils/folder"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -46,17 +47,43 @@ func (customTemplate *customTemplateGitHubRepo) Update(ctx context.Context) {
|
|||||||
downloadPath := config.DefaultConfig.CustomGitHubTemplatesDirectory
|
downloadPath := config.DefaultConfig.CustomGitHubTemplatesDirectory
|
||||||
clonePath := customTemplate.getLocalRepoClonePath(downloadPath)
|
clonePath := customTemplate.getLocalRepoClonePath(downloadPath)
|
||||||
|
|
||||||
// If folder does not exits then clone/download the repo
|
// If folder does not exist then clone/download the repo
|
||||||
if !fileutil.FolderExists(clonePath) {
|
if !fileutil.FolderExists(clonePath) {
|
||||||
customTemplate.Download(ctx)
|
customTemplate.Download(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to pull changes and handle the result
|
||||||
|
customTemplate.handlePullChanges(clonePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// handlePullChanges attempts to pull changes and logs the appropriate message
|
||||||
|
func (customTemplate *customTemplateGitHubRepo) handlePullChanges(clonePath string) {
|
||||||
err := customTemplate.pullChanges(clonePath, customTemplate.githubToken)
|
err := customTemplate.pullChanges(clonePath, customTemplate.githubToken)
|
||||||
if err != nil {
|
|
||||||
gologger.Error().Msgf("%s", err)
|
switch {
|
||||||
} else {
|
case err == nil:
|
||||||
|
customTemplate.logPullSuccess()
|
||||||
|
case errors.Is(err, git.NoErrAlreadyUpToDate):
|
||||||
|
customTemplate.logAlreadyUpToDate(err)
|
||||||
|
default:
|
||||||
|
customTemplate.logPullError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// logPullSuccess logs a success message when changes are pulled
|
||||||
|
func (customTemplate *customTemplateGitHubRepo) logPullSuccess() {
|
||||||
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.\n", customTemplate.owner, customTemplate.reponame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logAlreadyUpToDate logs an info message when repo is already up to date
|
||||||
|
func (customTemplate *customTemplateGitHubRepo) logAlreadyUpToDate(err error) {
|
||||||
|
gologger.Info().Msgf("%s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// logPullError logs an error message when pull fails
|
||||||
|
func (customTemplate *customTemplateGitHubRepo) logPullError(err error) {
|
||||||
|
gologger.Error().Msgf("%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGitHubProviders returns new instance of GitHub providers for downloading custom templates
|
// NewGitHubProviders returns new instance of GitHub providers for downloading custom templates
|
||||||
@ -187,7 +214,7 @@ func (ctr *customTemplateGitHubRepo) pullChanges(repoPath, githubToken string) e
|
|||||||
|
|
||||||
err = w.Pull(pullOpts)
|
err = w.Pull(pullOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("%s/%s: %s", ctr.owner, ctr.reponame, err.Error())
|
return errkit.Wrapf(err, "%s/%s", ctr.owner, ctr.reponame)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user