This commit is contained in:
+22
-18
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user