Skip to content

Commit cdc16ac

Browse files
committed
feat: refactor Gitea repository handling and imports
- Add a `MigrateRepo` method to the `gitea` struct - Remove the import of `code.gitea.io/sdk/gitea` in `cmd/repo.go` Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 3f7edfb commit cdc16ac

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cmd/gitea.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,32 @@ func (g *gitea) CreateAndGetOrg(opts CreateOrgOption) (*gsdk.Organization, error
9797

9898
return newOrg, nil
9999
}
100+
101+
// MigrateRepoOption migrate repository option
102+
type MigrateRepoOption struct {
103+
RepoName string
104+
RepoOwner string
105+
CloneAddr string
106+
Private bool
107+
Description string
108+
AuthUsername string
109+
AuthPassword string
110+
}
111+
112+
// MigrateRepo migrate repository
113+
func (g *gitea) MigrateRepo(opts MigrateRepoOption) (*gsdk.Repository, error) {
114+
newRepo, _, err := g.client.MigrateRepo(gsdk.MigrateRepoOption{
115+
RepoName: opts.RepoName,
116+
RepoOwner: opts.RepoOwner,
117+
CloneAddr: opts.CloneAddr,
118+
Private: opts.Private,
119+
Description: opts.Description,
120+
AuthUsername: opts.AuthUsername,
121+
AuthPassword: opts.AuthPassword,
122+
})
123+
if err != nil {
124+
return nil, err
125+
}
126+
127+
return newRepo, nil
128+
}

cmd/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log/slog"
77
"time"
88

9-
gsdk "code.gitea.io/sdk/gitea"
109
"github.com/spf13/cobra"
1110
)
1211

@@ -149,7 +148,7 @@ var repoCmd = &cobra.Command{
149148
}
150149

151150
slog.Info("start migrate repo", "name", targetRepo, "owner", targetOwner)
152-
newRepo, _, err := m.gitea.client.MigrateRepo(gsdk.MigrateRepoOption{
151+
newRepo, err := m.gitea.MigrateRepo(MigrateRepoOption{
153152
RepoName: targetRepo,
154153
RepoOwner: targetOwner,
155154
CloneAddr: repo.Links.Clone[1].Href,

0 commit comments

Comments
 (0)