Skip to content

Commit d1a9aef

Browse files
authored
fix: handle pagination (#164)
1 parent e91de27 commit d1a9aef

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

lib/index.js

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ let configSource!: 'list' | 'repo'
3434
}
3535
break
3636
case 'repo':
37-
labels = await fetchRepoLabels(
37+
startGroup('Fetching repo labels...')
38+
labels = await fetchAllRepoLabels(
3839
getInput('source-repo'),
3940
getInput('request-token')
4041
)
42+
endGroup()
4143
break
4244
}
4345

@@ -224,17 +226,39 @@ async function readRemoteConfigFile(fileURL: string): Promise<LabelInfo[]> {
224226
return parsed
225227
}
226228

229+
async function fetchAllRepoLabels(repo: string, token?: string) {
230+
const labels: LabelInfo[] = []
231+
232+
let page = 1
233+
log.info('Fetching page 1...')
234+
let curr = await fetchRepoLabels(repo, token, page)
235+
log.info(`${curr.length} labels found.`)
236+
237+
while (curr.length) {
238+
labels.push(...curr)
239+
page++
240+
241+
log.info(`Fetching page ${page}...`)
242+
curr = await fetchRepoLabels(repo, token, page)
243+
log.info(`${curr.length} labels found.`)
244+
}
245+
246+
return labels
247+
}
248+
227249
async function fetchRepoLabels(
228250
repo: string,
229-
token?: string
251+
token?: string,
252+
page = 1
230253
): Promise<LabelInfo[]> {
231254
startGroup('Getting repo labels...')
232255

233256
const url = `${process.env.GITHUB_API_URL}/repos/${repo}/labels`,
234-
headers = token ? { Authorization: `token ${token}` } : undefined
257+
headers = token ? { Authorization: `token ${token}` } : undefined,
258+
params = { page }
235259
log.info(`Using following URL: ${url}`)
236260

237-
const { data } = (await axios.get(url, { headers })) as any
261+
const { data } = (await axios.get(url, { headers, params })) as any
238262
if (!data || !(data instanceof Array))
239263
throw "Can't get label data from GitHub API"
240264

0 commit comments

Comments
 (0)