GitLab: include nested subgroup projects when enumerating group repositories

This commit is contained in:
Mick Grove 2025-08-08 18:08:17 -07:00
commit 2c7b0f7705

View file

@ -88,27 +88,9 @@ pub async fn enumerate_repo_urls(
hits.into_iter().next().context(format!("GitLab user `{}` not found", username))?;
let user_id = user.id;
// b) List that user's projects applying the requested filter
let mut builder = UserProjects::builder();
builder.user(user_id);
match repo_specifiers.repo_filter {
RepoType::Owner => {
builder.owned(true);
}
RepoType::Member => {
builder.membership(true);
}
RepoType::All => {
// this doesnt set any owned() or membership() flags on the builder, which in GitLabs API defaults to "all visible repos"
}
}
// Extract the builder to a separate variable to avoid borrowing a temporary,
// allowing us to modify its fields before building the endpoint.
let projects_ep = builder.build()?;
// b) List that users projects by ID
let projects_ep = UserProjects::builder().user(user_id).build()?;
let projects: Vec<SimpleProject> = projects_ep.query(&client)?;
for proj in projects {
repo_urls.push(proj.http_url_to_repo);
}
@ -120,31 +102,19 @@ pub async fn enumerate_repo_urls(
// all groups
let groups: Vec<SimpleGroup> = if repo_specifiers.all_groups {
gitlab::api::groups::Groups::builder()
.all_available(true)
.build()?
.query(&client.clone())?
gitlab::api::groups::Groups::builder().build()?.query(&client.clone())?
} else {
let mut found: Vec<SimpleGroup> = Vec::new();
for grp in &repo_specifiers.group {
let ep = gitlab::api::groups::Group::builder().group(grp).build()?;
let group: SimpleGroup = ep.query(&client.clone())?;
found.push(group);
let ep = gitlab::api::groups::Groups::builder().search(grp).build()?;
let page: Vec<SimpleGroup> = ep.query(&client.clone())?;
found.extend(page);
}
found
};
for group in groups {
let mut gp_builder = GroupProjects::builder();
gp_builder.group(group.id);
// Ensure projects from nested subgroups are also enumerated
gp_builder.include_subgroups(true);
if matches!(repo_specifiers.repo_filter, RepoType::Owner) {
gp_builder.owned(true);
}
let gp_ep = gp_builder.build()?;
let gp_ep = GroupProjects::builder().group(group.id).build()?;
let projects: Vec<SimpleProject> = gp_ep.query(&client)?;
for proj in projects {
repo_urls.push(proj.http_url_to_repo);