Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitlab: support nested repos #2981

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions server/forge/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,16 @@ 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, owner, name string) (*gitlab.Project, error) {
repo, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
func (g *GitLab) getProject(ctx context.Context, client *gitlab.Client, mr *model.Repo, 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 err != nil {
return nil, err
}
Expand All @@ -254,7 +262,7 @@ func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.Forg
return g.convertGitLabRepo(_repo)
}

_repo, err := g.getProject(ctx, client, owner, name)
_repo, err := g.getProject(ctx, client, nil, owner, name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -309,7 +317,7 @@ func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
return nil, err
}

_repo, err := g.getProject(ctx, client, r.Owner, r.Name)
_repo, err := g.getProject(ctx, client, r, r.Owner, r.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -339,7 +347,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.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return nil, err
}
Expand All @@ -355,10 +363,11 @@ 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.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return nil, err
}

opts := &gitlab.ListTreeOptions{
ListOptions: gitlab.ListOptions{PerPage: perPage},
Path: &path,
Expand Down Expand Up @@ -402,7 +411,7 @@ func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo,
return err
}

_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -459,7 +468,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
return err
}

_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -494,7 +503,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
return err
}

_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -548,7 +557,7 @@ func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Rep
return nil, err
}

_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return nil, err
}
Expand All @@ -575,7 +584,7 @@ func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, b
return "", err
}

_repo, err := g.getProject(ctx, client, r.Owner, r.Name)
_repo, err := g.getProject(ctx, client, r, r.Owner, r.Name)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -744,7 +753,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
return nil, err
}

_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
_repo, err := g.getProject(ctx, client, repo, repo.Owner, repo.Name)
if err != nil {
return nil, err
}
Expand Down