mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 21:31:02 +00:00
Fix gitlab project fetching (#3000)
This commit is contained in:
parent
ee038a74e1
commit
e5dbbd92c7
1 changed files with 21 additions and 31 deletions
|
@ -228,21 +228,23 @@ func (g *GitLab) Teams(ctx context.Context, user *model.User) ([]*model.Team, er
|
|||
}
|
||||
|
||||
// getProject fetches the named repository from the forge.
|
||||
func (g *GitLab) getProject(ctx context.Context, client *gitlab.Client, mr *model.Repo, owner, name string) (*gitlab.Project, error) {
|
||||
func (g *GitLab) getProject(ctx context.Context, client *gitlab.Client, forgeRemoteID model.ForgeRemoteID, owner, name string) (*gitlab.Project, error) {
|
||||
var (
|
||||
repo *gitlab.Project
|
||||
err error
|
||||
)
|
||||
if mr != nil && mr.ForgeRemoteID.IsValid() {
|
||||
repo, _, err = client.Projects.GetProject(mr.ForgeRemoteID, nil, gitlab.WithContext(ctx))
|
||||
} else {
|
||||
repo, _, err = client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
|
||||
}
|
||||
|
||||
if forgeRemoteID.IsValid() {
|
||||
intID, err := strconv.Atoi(string(forgeRemoteID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo, _, err = client.Projects.GetProject(intID, nil, gitlab.WithContext(ctx))
|
||||
return repo, err
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
repo, _, err = client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
|
||||
return repo, err
|
||||
}
|
||||
|
||||
// Repo fetches the repository from the forge.
|
||||
|
@ -252,19 +254,7 @@ func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.Forg
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if remoteID.IsValid() {
|
||||
intID, err := strconv.ParseInt(string(remoteID), 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_repo, _, err := client.Projects.GetProject(int(intID), nil, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return g.convertGitLabRepo(_repo)
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, nil, owner, name)
|
||||
_repo, err := g.getProject(ctx, client, remoteID, owner, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -319,7 +309,7 @@ func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, r, r.Owner, r.Name)
|
||||
_repo, err := g.getProject(ctx, client, r.ForgeRemoteID, r.Owner, r.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -349,7 +339,7 @@ func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, p
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -368,7 +358,7 @@ func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
|
|||
}
|
||||
|
||||
files := make([]*forge_types.FileMeta, 0, perPage)
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -419,7 +409,7 @@ func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo,
|
|||
return err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -476,7 +466,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
|
|||
return err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -511,7 +501,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
|||
return err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -565,7 +555,7 @@ func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Rep
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -592,7 +582,7 @@ func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, b
|
|||
return "", err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, r, r.Owner, r.Name)
|
||||
_repo, err := g.getProject(ctx, client, r.ForgeRemoteID, r.Owner, r.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -761,7 +751,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
|
||||
_repo, err := g.getProject(ctx, client, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue