feat(gateway): 优化gateway相关功能
Quality check / Web UI (push) Successful in 9m19s

This commit is contained in:
mei
2026-09-12 15:32:27 +08:00
parent 0d89b7fe8f
commit 9b656cebee
84 changed files with 2769 additions and 825 deletions
+22 -18
View File
@@ -6,33 +6,37 @@ import (
"fmt"
"github.com/google/go-github/v84/github"
"github.com/ssdomei232/goodBaby/handler/db"
"github.com/ssdomei232/goodBaby/model"
)
// GetGithubReposAndAccountFromRule 从 rule 中获取 GithubReposConfig 和 GithubAccount
func GetGithubReposAndAccountFromRule(rule *model.Rule) (*GithubReposConfig, *GithubAccount, error) {
var githubReposConfig GithubReposConfig
if err := json.Unmarshal([]byte(rule.ConfigJson), &githubReposConfig); err != nil {
return nil, nil, fmt.Errorf("解析 GitHub 规则配置失败: %w", err)
// ParseAccountConfig 解析 GitHub 账号配置
func ParseAccountConfig(config string) (*GithubAccount, error) {
if config == "" {
return nil, fmt.Errorf("解析GitHub账号配置失败: 规则没有关联账号")
}
var githubAccount GithubAccount
if err := db.LoadAccountConfig(rule.AccountID, &githubAccount); err != nil {
return nil, nil, err
var account GithubAccount
if err := json.Unmarshal([]byte(config), &account); err != nil {
return nil, fmt.Errorf("解析GitHub账号配置失败: %v", err)
}
return &githubReposConfig, &githubAccount, nil
return &account, nil
}
// SetRepositoryPublic 将仓库设置为 public
// ParseReposConfig 解析仓库规则配置
func ParseReposConfig(configJSON string) (*GithubReposConfig, error) {
var config GithubReposConfig
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
return nil, fmt.Errorf("解析GitHub规则配置失败: %v", err)
}
return &config, nil
}
// SetRepositoryPublic 把一个仓库设置为 public
func SetRepositoryPublic(ctx context.Context, token, owner, repo string) error {
client := github.NewClient(nil).WithAuthToken(token)
opts := &github.Repository{
if _, _, err := client.Repositories.Edit(ctx, owner, repo, &github.Repository{
Visibility: github.Ptr("public"),
}); err != nil {
return fmt.Errorf("设置仓库 %s 为 public 失败: %w", repo, err)
}
_, _, err := client.Repositories.Edit(ctx, owner, repo, opts)
return err
return nil
}