From 06b8dcdca118d8af372b3107d96089f10410b652 Mon Sep 17 00:00:00 2001
From: Marcus Crane <marcus@utf9k.net>
Date: Wed, 10 May 2023 17:39:20 +1200
Subject: [PATCH] feat(platform/github): Skip archived repos at earliest point
 when retrieving repo listings (#22057)

---
 lib/modules/platform/github/index.spec.ts | 12 ++++++++++++
 lib/modules/platform/github/index.ts      | 10 +++++++---
 lib/modules/platform/github/types.ts      |  1 +
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts
index 51b25a6d95..0789f597bc 100644
--- a/lib/modules/platform/github/index.spec.ts
+++ b/lib/modules/platform/github/index.spec.ts
@@ -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,
         ]);
@@ -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,
           ],
diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts
index 8f5bdab301..1fb1e521a0 100644
--- a/lib/modules/platform/github/index.ts
+++ b/lib/modules/platform/github/index.ts
@@ -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`);
diff --git a/lib/modules/platform/github/types.ts b/lib/modules/platform/github/types.ts
index fd06dcf31b..ef01406661 100644
--- a/lib/modules/platform/github/types.ts
+++ b/lib/modules/platform/github/types.ts
@@ -26,6 +26,7 @@ export interface GhRestRepo {
   owner: {
     login: string;
   };
+  archived: boolean;
 }
 
 export interface GhRestPr {
-- 
GitLab