diff --git a/package.json b/package.json index 95d1dc2..2f6d1b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-repository-distributor", - "version": "1.0.1", + "version": "1.1.0", "description": "github-repository-distributor", "main": "dist/index.js", "types": "dist/types/index.d.ts", diff --git a/scripts/raw.js b/scripts/raw.js index 9b9abc5..d34fb98 100644 --- a/scripts/raw.js +++ b/scripts/raw.js @@ -8,4 +8,5 @@ main({ title: 'Hello world', includeFork: 'true', includeArchived: 'true' + // onlyPrivate: true }) diff --git a/src/type.ts b/src/type.ts index 5682ab1..589732c 100644 --- a/src/type.ts +++ b/src/type.ts @@ -2,7 +2,8 @@ import type { RestEndpointMethodTypes } from '@octokit/rest' export type { Root, Content, Paragraph, ListItem, Link } from 'mdast' export type { Dictionary } from 'lodash' export type Repository = - RestEndpointMethodTypes['repos']['listForUser']['response']['data'][number] + | RestEndpointMethodTypes['repos']['listForUser']['response']['data'][number] + | RestEndpointMethodTypes['repos']['listForAuthenticatedUser']['response']['data'][number] export interface RawUserDefinedOptions { token: string diff --git a/src/util.ts b/src/util.ts index 55ae9f1..bf05d44 100644 --- a/src/util.ts +++ b/src/util.ts @@ -9,7 +9,7 @@ export { dayjs } declare var __isAction__: boolean export async function getAllRepos (options: UserDefinedOptions) { - const { token, username, includeFork, includeArchived } = options + const { token, username, includeFork, includeArchived, onlyPrivate } = options let octokit if (__isAction__) { const { github } = await import('./action') @@ -27,12 +27,23 @@ export async function getAllRepos (options: UserDefinedOptions) { let allRepos: Repository[] = [] while (l === perPage) { - const res = await octokit.rest.repos.listForUser({ - username, - per_page: perPage, - page, - sort: 'updated' - }) + let res + if (!onlyPrivate) { + res = await octokit.rest.repos.listForUser({ + username, + per_page: perPage, + page, + sort: 'updated' + }) + } else { + res = await octokit.rest.repos.listForAuthenticatedUser({ + // username, + per_page: perPage, + page, + sort: 'updated', + visibility: 'private' + }) + } page++ l = res.data.length allRepos = allRepos.concat(res.data)