Skip to content

Commit

Permalink
feat(platform/github): Skip archived repos at earliest point when ret…
Browse files Browse the repository at this point in the history
…rieving repo listings (#22057)
  • Loading branch information
marcus-crane committed May 10, 2023
1 parent 2e2570c commit 06b8dcd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/modules/platform/github/index.spec.ts
Expand Up @@ -174,9 +174,15 @@ describe('modules/platform/github/index', () => {
.reply(200, [
{
full_name: 'a/b',
archived: false,
},
{
full_name: 'c/d',
archived: false,
},
{
full_name: 'e/f',
archived: true,
},
null,
]);
Expand Down Expand Up @@ -227,9 +233,15 @@ describe('modules/platform/github/index', () => {
repositories: [
{
full_name: 'a/b',
archived: false,
},
{
full_name: 'c/d',
archived: false,
},
{
full_name: 'e/f',
archived: true,
},
null,
],
Expand Down
10 changes: 7 additions & 3 deletions lib/modules/platform/github/index.ts
Expand Up @@ -191,20 +191,24 @@ export async function getRepos(): Promise<string[]> {
try {
if (platformConfig.isGHApp) {
const res = await githubApi.getJson<{
repositories: { full_name: string }[];
repositories: GhRestRepo[];
}>(`installation/repositories?per_page=100`, {
paginationField: 'repositories',
paginate: 'all',
});
return res.body.repositories
.filter(is.nonEmptyObject)
.filter((repo) => !repo.archived)
.map((repo) => repo.full_name);
} else {
const res = await githubApi.getJson<{ full_name: string }[]>(
const res = await githubApi.getJson<GhRestRepo[]>(
`user/repos?per_page=100`,
{ paginate: 'all' }
);
return res.body.filter(is.nonEmptyObject).map((repo) => repo.full_name);
return res.body
.filter(is.nonEmptyObject)
.filter((repo) => !repo.archived)
.map((repo) => repo.full_name);
}
} catch (err) /* istanbul ignore next */ {
logger.error({ err }, `GitHub getRepos error`);
Expand Down
1 change: 1 addition & 0 deletions lib/modules/platform/github/types.ts
Expand Up @@ -26,6 +26,7 @@ export interface GhRestRepo {
owner: {
login: string;
};
archived: boolean;
}

export interface GhRestPr {
Expand Down

0 comments on commit 06b8dcd

Please sign in to comment.