@@ -3,6 +3,8 @@ package githubcheck
33import (
44 "encoding/json"
55 "net/http"
6+ "os"
7+ "path/filepath"
68 "strconv"
79 "strings"
810 "time"
@@ -12,9 +14,10 @@ import (
1214)
1315
1416const (
15- apiBase = "https://api.github.com"
16- apiTimeout = 30 * time .Second
17- apiPerPage = 100 // 单页数量,减少漏判(GitHub 默认 30)
17+ apiBase = "https://api.github.com"
18+ apiTimeout = 30 * time .Second
19+ apiPerPage = 100 // 单页数量,减少漏判(GitHub 默认 30)
20+ runnerTokenFile = ".github_check_token" // 各 runner 目录下可选文件,内容为用于 List runners API 的 PAT
1821)
1922
2023// githubRunnersResponse 与 GitHub API 返回结构一致
@@ -29,18 +32,32 @@ type githubRunnersResponse struct {
2932}
3033
3134// Run 根据配置对每个 runner 调用 GitHub API 检查是否已在 GitHub 显示,并写入 .github_status.json
35+ // Token 仅从该 runner 目录下的 .github_check_token 读取,无则跳过该 runner
3236func Run (cfg * config.Config ) {
33- if cfg == nil || cfg . GitHub . Token == "" {
37+ if cfg == nil {
3438 return
3539 }
3640 client := & http.Client {Timeout : apiTimeout }
3741 for _ , item := range cfg .Runners .Items {
3842 installDir := item .InstallPath (cfg .Runners .BasePath )
39- registered := checkOne (client , cfg .GitHub .Token , item .TargetType , item .Target , item .Name )
43+ token := tokenForRunner (installDir )
44+ if token == "" {
45+ continue
46+ }
47+ registered := checkOne (client , token , item .TargetType , item .Target , item .Name )
4048 _ = runner .WriteGitHubStatus (installDir , registered )
4149 }
4250}
4351
52+ // tokenForRunner 返回该 runner 用于 GitHub 检查的 token:从 installDir 下的 .github_check_token 读取,不存在或为空则返回空
53+ func tokenForRunner (installDir string ) string {
54+ b , err := os .ReadFile (filepath .Join (installDir , runnerTokenFile ))
55+ if err != nil {
56+ return ""
57+ }
58+ return strings .TrimSpace (string (b ))
59+ }
60+
4461// isValidTargetFormat 与 handler.validateTarget 规则一致,避免对无效 target 发起 API 请求;targetType 会规范为小写
4562func isValidTargetFormat (targetType , target string ) bool {
4663 raw := strings .TrimSpace (target )
0 commit comments