in pkg/review/header.go [61:108]
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
}
if !IsPR() {
return
}
if !IsGHA() {
panic(fmt.Errorf("this must be run on GitHub Actions or you have to set the environment variables %v manually", requiredEnvVars))
}
s, err := GetSha()
if err != nil {
logger.Log.Warnln("failed to get sha", err)
return
}
sha = s
token := os.Getenv("GITHUB_TOKEN")
ref := os.Getenv("GITHUB_REF")
fullName := os.Getenv("GITHUB_REPOSITORY")
logger.Log.Debugln("ref:", ref, "; repo:", fullName, "; sha:", sha)
ownerRepo := strings.Split(fullName, "/")
if len(ownerRepo) != 2 {
logger.Log.Warnln("Length of ownerRepo is not 2", ownerRepo)
return
}
owner, repo = ownerRepo[0], ownerRepo[1]
matches := regexp.MustCompile(`refs/pull/(\d+)/merge`).FindStringSubmatch(ref)
if len(matches) < 1 {
logger.Log.Warnln("Length of ref < 1", matches)
return
}
prString := matches[1]
if p, err := strconv.Atoi(prString); err == nil {
pr = p
} else {
logger.Log.Warnln("Failed to parse pull request number.", err)
return
}
ctx = context.Background()
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
tc := oauth2.NewClient(ctx, ts)
gh = github.NewClient(tc)
}