You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by ke...@apache.org on 2022/06/04 01:51:38 UTC

[skywalking-eyes] 01/01: Lazy initialize GitHub client for comment

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

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

commit eec4e6e0c186fc5d4ae33879126a8beba3237230
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Sat Jun 4 09:51:04 2022 +0800

    Lazy initialize GitHub client for comment
---
 pkg/review/header.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pkg/review/header.go b/pkg/review/header.go
index bc00800..139c51e 100644
--- a/pkg/review/header.go
+++ b/pkg/review/header.go
@@ -26,6 +26,7 @@ import (
 	"regexp"
 	"strconv"
 	"strings"
+	"sync"
 
 	"github.com/google/go-github/v33/github"
 	"golang.org/x/oauth2"
@@ -54,9 +55,11 @@ var (
 		"GITHUB_EVENT_NAME",
 		"GITHUB_EVENT_PATH",
 	}
+
+	ghOnce sync.Once
 )
 
-func init() {
+func Init() {
 	if os.Getenv("GITHUB_TOKEN") == "" {
 		logger.Log.Infoln("GITHUB_TOKEN is not set, license-eye won't comment on the pull request")
 		return
@@ -107,6 +110,8 @@ func init() {
 
 // Header reviews the license header, including suggestions on the pull request and an overview of the checks.
 func Header(result *header2.Result, config *config2.Config) error {
+	ghOnce.Do(Init)
+
 	if !result.HasFailure() || !IsPR() || gh == nil || config.Header.Comment == header2.Never {
 		return nil
 	}