feat(internal/github): 触发时公开github遗言仓库
This commit is contained in:
+17
-10
@@ -6,16 +6,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
DisconnectDuration int `json:"disconnect_duration"` // Hours
|
DisconnectDuration int `json:"disconnect_duration"` // Hours
|
||||||
CatBotUrl string `json:"cat_bot_url"`
|
CatBotUrl string `json:"cat_bot_url"`
|
||||||
CatBotKey string `json:"cat_bot_key"`
|
CatBotKey string `json:"cat_bot_key"`
|
||||||
QQSendGroup []int `json:"qq_send_group"`
|
QQSendGroup []int `json:"qq_send_group"`
|
||||||
QQMsg string `json:"qq_msg"`
|
QQMsg string `json:"qq_msg"`
|
||||||
MailList []string `json:"mail_list"`
|
MailList []string `json:"mail_list"`
|
||||||
MailTitle string `json:"mail_title"`
|
MailTitle string `json:"mail_title"`
|
||||||
SMTPConfig SMTPConfig `json:"smtp_config"`
|
SMTPConfig SMTPConfig `json:"smtp_config"`
|
||||||
MailContent string `json:"mail_content"`
|
MailContent string `json:"mail_content"`
|
||||||
|
GithubConfig GithubConfig `json:"github_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SMTPConfig struct {
|
type SMTPConfig struct {
|
||||||
@@ -25,6 +26,12 @@ type SMTPConfig struct {
|
|||||||
Password string `json:"pass"`
|
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) {
|
func GetConfig() (config Config, err error) {
|
||||||
content, err := os.ReadFile("config.json")
|
content, err := os.ReadFile("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1 +1,37 @@
|
|||||||
package internal
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user