Browse Source

Fetch commits by pages

Igor Demin 7 months ago
parent
commit
02f9fcb721
  1. 17
      tools/changelog.main.kts

17
tools/changelog.main.kts

@ -134,9 +134,10 @@ fun entriesForRepo(repo: String): List<ChangelogEntry> {
} }
} }
return request<GitHubCompareResponse>("https://api.github.com/repos/$repo/compare/$firstCommit...$lastCommit") return fetchPagedUntilEmpty { page ->
.commits request<GitHubCompareResponse>("https://api.github.com/repos/$repo/compare/$firstCommit...$lastCommit?per_page=1000&page=$page")
.map { changelogEntryFor(it, prForCommit(it)) } .commits
}.map { changelogEntryFor(it, prForCommit(it)) }
} }
/** /**
@ -265,4 +266,14 @@ fun <T> exponentialRetry(block: () -> T): T {
throw exception throw exception
} }
inline fun <T> fetchPagedUntilEmpty(fetch: (page: Int) -> List<T>): MutableList<T> {
val all = mutableListOf<T>()
var page = 1
do {
val result = fetch(page++)
all.addAll(result)
} while (result.isEmpty())
return all
}
//endregion //endregion
Loading…
Cancel
Save