Commit ec4a7fc

Anton Golub <antongolub@antongolub.com>
2024-12-06 22:57:53
fix: exclude empty repos (#100)
closes #67
1 parent 1a9a71d
Changed files (3)
src/task/commits/commits.ts
@@ -5,18 +5,17 @@ import { CommitsQuery } from './commits.graphql.js'
 export default task({
   name: 'commits' as const,
   run: async ({ octokit, data }, { id }: { id: string }) => {
+    const repo = data.repos.find((repo) => repo.id == id)
+    if (!repo) throw new Error(`Repo not found: ${id}`)
+
+    repo.commits = []
+    if (repo.isEmpty) return
+
     const commits = paginate(octokit, CommitsQuery, {
       id,
       author: data.user.id,
     })
 
-    const repo = data.repos.find((repo) => repo.id == id)
-    if (!repo) {
-      throw new Error(`Repo not found: ${id}`)
-    }
-
-    repo.commits = []
-
     for await (const resp of commits) {
       if (!resp.node?.defaultBranchRef?.target?.history) {
         throw new Error('Failed to load commits')
src/task/repos/repos.graphql
@@ -30,6 +30,7 @@ fragment Repository on Repository {
       }
     }
   }
+  isEmpty
 }
 
 query ReposQuery(
src/task/repos/repos.graphql.ts
@@ -33,6 +33,7 @@ fragment Repository on Repository {
       }
     }
   }
+  isEmpty
 }`
 
 export type Repository = {
@@ -68,6 +69,7 @@ export type Repository = {
       | null
       | null
   } | null
+  isEmpty: boolean
 }
 
 export const ReposQuery = `#graphql