mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-25 05:38:42 +08:00
fix: 修复 gitlab token 未刷新的问题
This commit is contained in:
1 parent
da5e5eb9f1
commit
e8c51636b8
2 files changed
+19
-4
No files matched your search
@@ -57,6 +57,7 @@ func (u *GitIdentityUsecase) List(ctx context.Context, uid uuid.UUID) ([]*domain
|
||||
repos, err := client.Repositories(ctx, &domain.RepositoryOptions{
|
||||
Token: token,
|
||||
InstallID: identity.InstallationID,
|
||||
IsOAuth: identity.OauthRefreshToken != "",
|
||||
})
|
||||
if err != nil {
|
||||
u.logger.WarnContext(ctx, "failed to get authorized repositories", "error", err, "platform", identity.Platform, "identity_id", identity.ID)
|
||||
@@ -73,7 +74,7 @@ func (u *GitIdentityUsecase) gitClienter(identity *db.GitIdentity) domain.GitCli
|
||||
case consts.GitPlatformGithub:
|
||||
return github.NewGithub(u.logger, u.cfg)
|
||||
case consts.GitPlatformGitLab:
|
||||
return gitlab.NewGitlab(identity.BaseURL, identity.AccessToken, u.logger)
|
||||
return gitlab.NewGitlabForBaseURL(identity.BaseURL, u.logger)
|
||||
case consts.GitPlatformGitea:
|
||||
return gitea.NewGitea(u.logger, identity.BaseURL)
|
||||
case consts.GitPlatformGitee:
|
||||
@@ -104,6 +105,7 @@ func (u *GitIdentityUsecase) Get(ctx context.Context, uid uuid.UUID, id uuid.UUI
|
||||
repos, err := client.Repositories(ctx, &domain.RepositoryOptions{
|
||||
Token: token,
|
||||
InstallID: identity.InstallationID,
|
||||
IsOAuth: identity.OauthRefreshToken != "",
|
||||
})
|
||||
if err != nil {
|
||||
u.logger.WarnContext(ctx, "failed to get authorized repositories", "error", err, "platform", identity.Platform, "identity_id", id)
|
||||
@@ -209,8 +211,13 @@ func (u *GitIdentityUsecase) ListBranches(ctx context.Context, uid uuid.UUID, id
|
||||
return nil, errcode.ErrInvalidPlatform
|
||||
}
|
||||
|
||||
token, err := u.tokenProvider.GetToken(ctx, identity.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get token: %w", err)
|
||||
}
|
||||
|
||||
branches, err := client.Branches(ctx, &domain.BranchesOptions{
|
||||
Token: identity.AccessToken, Owner: owner, Repo: repo,
|
||||
Token: token, Owner: owner, Repo: repo,
|
||||
Page: page, PerPage: perPage,
|
||||
InstallID: identity.InstallationID, IsOAuth: identity.OauthRefreshToken != "",
|
||||
})
|
||||
|
||||
@@ -369,7 +369,11 @@ func (g *Gitlab) UserInfo(ctx context.Context, token string) (*domain.PlatformUs
|
||||
|
||||
// Repositories 实现 GitPlatformClient 接口
|
||||
func (g *Gitlab) Repositories(ctx context.Context, opts *domain.RepositoryOptions) ([]domain.AuthRepository, error) {
|
||||
return g.GetAuthorizedRepositories(ctx, opts.Token)
|
||||
client, err := g.newClientWithToken(opts.Token, opts.IsOAuth)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("new client: %w", err)
|
||||
}
|
||||
return g.listProjects(ctx, client)
|
||||
}
|
||||
|
||||
// Tree 实现 GitPlatformClient 接口
|
||||
@@ -433,7 +437,11 @@ func (g *Gitlab) Archive(ctx context.Context, opts *domain.ArchiveOptions) (*dom
|
||||
|
||||
// Branches 实现 GitPlatformClient 接口
|
||||
func (g *Gitlab) Branches(ctx context.Context, opts *domain.BranchesOptions) ([]*domain.BranchInfo, error) {
|
||||
resp, err := g.ListBranches(ctx, opts.Token, opts.Owner, opts.IsOAuth, opts.Page, opts.PerPage)
|
||||
projectPath := opts.Owner
|
||||
if opts.Repo != "" {
|
||||
projectPath = opts.Owner + "/" + opts.Repo
|
||||
}
|
||||
resp, err := g.ListBranches(ctx, opts.Token, projectPath, opts.IsOAuth, opts.Page, opts.PerPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user