diff --git a/pkg/model/github_context.go b/pkg/model/github_context.go index 5ed3d962ffa..8c488d40030 100644 --- a/pkg/model/github_context.go +++ b/pkg/model/github_context.go @@ -4,11 +4,17 @@ import ( "context" "fmt" "strings" + "sync" "github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common/git" ) +var ( + loggedWarnings = make(map[string]bool) + mu sync.Mutex +) + type GithubContext struct { Event map[string]interface{} `json:"event"` EventPath string `json:"event_path"` @@ -168,7 +174,11 @@ func (ghc *GithubContext) SetRepositoryAndOwner(ctx context.Context, githubInsta if ghc.Repository == "" { repo, err := git.FindGithubRepo(ctx, repoPath, githubInstance, remoteName) if err != nil { - common.Logger(ctx).Warningf("unable to get git repo: %v", err) + warningMsg := fmt.Sprintf("unable to get git repo: %v", err) + if !hasLoggedWarning(warningMsg) { + common.Logger(ctx).Warningf(warningMsg) + markWarningAsLogged(warningMsg) + } return } ghc.Repository = repo @@ -211,3 +221,16 @@ func (ghc *GithubContext) SetBaseAndHeadRef() { } } } + +func hasLoggedWarning(msg string) bool { + mu.Lock() + defer mu.Unlock() + _, exists := loggedWarnings[msg] + return exists +} + +func markWarningAsLogged(msg string) { + mu.Lock() + defer mu.Unlock() + loggedWarnings[msg] = true +}