This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git


The following commit(s) were added to refs/heads/main by this push:
     new 0630b01  feat: check headers concurrently (#257)
0630b01 is described below

commit 0630b017b4e34f27f0d8719c873d703fb31ec8de
Author: Zac Blanco <[email protected]>
AuthorDate: Thu Jan 15 08:38:15 2026 -0800

    feat: check headers concurrently (#257)
---
 pkg/header/check.go  | 16 +++++++++++++---
 pkg/header/result.go | 25 ++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/pkg/header/check.go b/pkg/header/check.go
index 1644c89..9a02953 100644
--- a/pkg/header/check.go
+++ b/pkg/header/check.go
@@ -24,6 +24,7 @@ import (
        "os"
        "path/filepath"
        "regexp"
+       "runtime"
        "strings"
 
        eyeignore "github.com/apache/skywalking-eyes/pkg/gitignore"
@@ -35,6 +36,7 @@ import (
        "github.com/go-git/go-git/v5"
        "github.com/go-git/go-git/v5/plumbing/format/gitignore"
        "github.com/go-git/go-git/v5/plumbing/object"
+       "golang.org/x/sync/errgroup"
 )
 
 // Check checks the license headers of the specified paths/globs.
@@ -44,10 +46,18 @@ func Check(config *ConfigHeader, result *Result) error {
                return err
        }
 
+       g := new(errgroup.Group)
+       g.SetLimit(runtime.GOMAXPROCS(0))
+
        for _, file := range fileList {
-               if err := CheckFile(file, config, result); err != nil {
-                       return err
-               }
+               f := file
+               g.Go(func() error {
+                       return CheckFile(f, config, result)
+               })
+       }
+
+       if err := g.Wait(); err != nil {
+               return err
        }
 
        return nil
diff --git a/pkg/header/result.go b/pkg/header/result.go
index eab1e5f..4504b62 100644
--- a/pkg/header/result.go
+++ b/pkg/header/result.go
@@ -20,9 +20,11 @@ package header
 import (
        "fmt"
        "strings"
+       "sync"
 )
 
 type Result struct {
+       mu      sync.Mutex
        Success []string
        Failure []string
        Ignored []string
@@ -30,34 +32,49 @@ type Result struct {
 }
 
 func (result *Result) Fail(file string) {
+       result.mu.Lock()
        result.Failure = append(result.Failure, file)
+       result.mu.Unlock()
 }
 
 func (result *Result) Succeed(file string) {
+       result.mu.Lock()
        result.Success = append(result.Success, file)
+       result.mu.Unlock()
 }
 
 func (result *Result) Ignore(file string) {
+       result.mu.Lock()
        result.Ignored = append(result.Ignored, file)
+       result.mu.Unlock()
 }
 
 func (result *Result) Fix(file string) {
+       result.mu.Lock()
        result.Fixed = append(result.Fixed, file)
+       result.mu.Unlock()
 }
 
 func (result *Result) HasFailure() bool {
-       return len(result.Failure) > 0
+       result.mu.Lock()
+       has := len(result.Failure) > 0
+       result.mu.Unlock()
+       return has
 }
 
 func (result *Result) Error() error {
-       return fmt.Errorf(
+       result.mu.Lock()
+       msg := fmt.Errorf(
                "the following files don't have a valid license header: \n%v",
                strings.Join(result.Failure, "\n"),
        )
+       result.mu.Unlock()
+       return msg
 }
 
 func (result *Result) String() string {
-       return fmt.Sprintf(
+       result.mu.Lock()
+       s := fmt.Sprintf(
                "Totally checked %d files, valid: %d, invalid: %d, ignored: %d, 
fixed: %d",
                len(result.Success)+len(result.Failure)+len(result.Ignored),
                len(result.Success),
@@ -65,4 +82,6 @@ func (result *Result) String() string {
                len(result.Ignored),
                len(result.Fixed),
        )
+       result.mu.Unlock()
+       return s
 }

Reply via email to