Skip to content
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
61 changes: 40 additions & 21 deletions apps/mobile/src/features/tasks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,34 +460,53 @@ export async function getIntegrations(): Promise<Integration[]> {
return data.results ?? data ?? [];
}

const GITHUB_REPOS_PAGE_SIZE = 500;

export async function getGithubRepositories(
integrationId: number,
): Promise<string[]> {
const baseUrl = getBaseUrl();
const projectId = getProjectId();
const headers = getHeaders();

const response = await fetch(
`${baseUrl}/api/environments/${projectId}/integrations/${integrationId}/github_repos/`,
{ headers },
);

if (!response.ok) {
throw new HttpError(
response.status,
response.statusText,
"Failed to fetch repositories",
const allRepos: string[] = [];
let offset = 0;

while (true) {
const params = new URLSearchParams({
limit: String(GITHUB_REPOS_PAGE_SIZE),
offset: String(offset),
});
const response = await fetch(
`${baseUrl}/api/environments/${projectId}/integrations/${integrationId}/github_repos/?${params}`,
{ headers },
);
}

const data = await response.json();
const repos: Array<string | { full_name?: string; name?: string }> =
data.repositories ?? data.results ?? data ?? [];

return repos
.map((repo) => {
if (typeof repo === "string") return repo.toLowerCase();
return (repo.full_name ?? repo.name ?? "").toLowerCase();
})
.filter((name) => name.length > 0);
if (!response.ok) {
throw new HttpError(
response.status,
response.statusText,
"Failed to fetch repositories",
);
}

const data = await response.json();
const repos: Array<string | { full_name?: string; name?: string }> =
data.repositories ?? data.results ?? data ?? [];

const normalized = repos
.map((repo) => {
if (typeof repo === "string") return repo.toLowerCase();
return (repo.full_name ?? repo.name ?? "").toLowerCase();
})
.filter((name) => name.length > 0);

allRepos.push(...normalized);

if (!data.has_more || repos.length === 0) {
return allRepos;
}

offset += repos.length;
}
}
Loading