Skip to content

Commit

Permalink
refactor: 更新接口定义,将BackupProvider更改为Provider,并调整相关查询结构
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Dec 9, 2024
1 parent 44f302f commit d2f2033
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion provider/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config struct {
AuthUsername string `json:"auth_username"`
}

var _ provider.BackupProvider = &Gitea{}
var _ provider.Provider = &Gitea{}

type Gitea struct {
conf *Config
Expand Down
29 changes: 12 additions & 17 deletions provider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewGithub(token string) *Github {
func (g *Github) LoadAllRepos(owner string, isOrg bool) ([]Repo, error) {
tmpl := `
query {
%s {
repositories: %s {
repositories(
first: 100,
after: %s
Expand All @@ -53,13 +53,10 @@ query {
`
next := "null"
queryType := ""
dataKey := ""
var repos []Repo
if isOrg {
dataKey = "organization"
queryType = fmt.Sprintf("organization(login: \"%s\")", owner)
} else {
dataKey = "repositoryOwner"
queryType = fmt.Sprintf("repositoryOwner(login: \"%s\")", owner)
}
token := request.WithAuthorization(g.Token, "bearer")
Expand All @@ -70,31 +67,29 @@ query {
if err != nil {
return nil, err
}
info, ok := data.Data[dataKey]
if !ok {
return nil, fmt.Errorf("no data key %s", dataKey)
}
for _, repo := range info.Repositories.Nodes {
for _, repo := range data.Data.Repositories.Repositories.Nodes {
if strings.ToLower(repo.Owner.Login) == ownerLower {
repos = append(repos, repo)
}
}
if !info.Repositories.PageInfo.HasNextPage {
if !data.Data.Repositories.Repositories.PageInfo.HasNextPage {
break
}
next = fmt.Sprintf(`"%s"`, info.Repositories.PageInfo.EndCursor)
next = fmt.Sprintf(`"%s"`, data.Data.Repositories.Repositories.PageInfo.EndCursor)
}
return repos, nil
}

type reposQuery struct {
Data map[string]struct {
Data struct {
Repositories struct {
PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
EndCursor string `json:"endCursor"`
} `json:"pageInfo"`
Nodes []Repo `json:"nodes"`
Repositories struct {
PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
EndCursor string `json:"endCursor"`
} `json:"pageInfo"`
Nodes []Repo `json:"nodes"`
} `json:"repositories"`
} `json:"repositories"`
} `json:"data"`
}
2 changes: 1 addition & 1 deletion provider/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Repo struct {
AuthToken string
}

type BackupProvider interface {
type Provider interface {
LoadRepos(owner *Owner) ([]string, error)
MigrateRepo(from *Owner, to *Owner, repo *Repo) (string, error)
DeleteRepo(owner, repo string) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"log"
)

func BuildBackupProvider(conf *config.BackupProviderConfig) (provider.BackupProvider, error) {
func BuildBackupProvider(conf *config.BackupProviderConfig) (provider.Provider, error) {
switch conf.Type {
case config.BackupProviderConfigTypeGitea:
c, err := config.ConvertToBackupProviderConfig[gitea.Config](conf.Config)
Expand Down

0 comments on commit d2f2033

Please sign in to comment.