From ef1040484d4487039f07efa713abe95a68e8e5f8 Mon Sep 17 00:00:00 2001 From: mei Date: Mon, 6 Oct 2025 18:44:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(internal/github):=20=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=97=B6=E5=85=AC=E5=BC=80github=E9=81=97=E8=A8=80=E4=BB=93?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/config.go | 27 +++++++++++++++++---------- internal/github.go | 36 ++++++++++++++++++++++++++++++++++++ main.go | 1 + 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/configs/config.go b/configs/config.go index 348b735..7ee07df 100644 --- a/configs/config.go +++ b/configs/config.go @@ -6,16 +6,17 @@ import ( ) type Config struct { - Debug bool `json:"debug"` - DisconnectDuration int `json:"disconnect_duration"` // Hours - CatBotUrl string `json:"cat_bot_url"` - CatBotKey string `json:"cat_bot_key"` - QQSendGroup []int `json:"qq_send_group"` - QQMsg string `json:"qq_msg"` - MailList []string `json:"mail_list"` - MailTitle string `json:"mail_title"` - SMTPConfig SMTPConfig `json:"smtp_config"` - MailContent string `json:"mail_content"` + Debug bool `json:"debug"` + DisconnectDuration int `json:"disconnect_duration"` // Hours + CatBotUrl string `json:"cat_bot_url"` + CatBotKey string `json:"cat_bot_key"` + QQSendGroup []int `json:"qq_send_group"` + QQMsg string `json:"qq_msg"` + MailList []string `json:"mail_list"` + MailTitle string `json:"mail_title"` + SMTPConfig SMTPConfig `json:"smtp_config"` + MailContent string `json:"mail_content"` + GithubConfig GithubConfig `json:"github_config"` } type SMTPConfig struct { @@ -25,6 +26,12 @@ type SMTPConfig struct { Password string `json:"pass"` } +type GithubConfig struct { + Owner string `json:"owner"` + Repos []string `json:"repos"` + Token string `json:"token"` +} + func GetConfig() (config Config, err error) { content, err := os.ReadFile("config.json") if err != nil { diff --git a/internal/github.go b/internal/github.go index 5bf0569..acfd2a1 100644 --- a/internal/github.go +++ b/internal/github.go @@ -1 +1,37 @@ package internal + +import ( + "log" + "time" + + "github.com/ssdomei232/goodBaby/configs" + "github.com/ssdomei232/goodBaby/pkg" +) + +func Github() { + config, err := configs.GetConfig() + if err != nil { + log.Fatalln(err) + } + + for _, repo := range config.GithubConfig.Repos { + // 添加重试机制 + maxRetries := 10 + for attempt := range maxRetries { + err := pkg.MakeRepositoryPublic(config.GithubConfig.Owner, repo, config.GithubConfig.Token) + if err == nil { + // 成功执行,跳出重试循环 + break + } + + log.Printf("尝试设置仓库 %s 为私有失败 (尝试 %d/%d): %v", repo, attempt+1, maxRetries, err) + + // 如果不是最后一次尝试,则等待一段时间后重试 + if attempt < maxRetries-1 { + time.Sleep(time.Duration(attempt+1) * time.Second) // 逐步增加等待时间 + } else { + log.Printf("设置仓库 %s 为私有最终失败", repo) + } + } + } +} diff --git a/main.go b/main.go index 6267cad..9fe03da 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ func init() { func trigger() { go internal.SendQQ() go internal.SendMail() + go internal.Github() } func main() {