- introduce paging to graphQL logic

This commit is contained in:
Mike Penz
2025-02-17 21:22:26 +01:00
parent b66fb5e3cc
commit 6636c4cd91
4 changed files with 1689 additions and 1670 deletions
Generated Vendored
+1646 -1617
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -61,7 +61,7 @@ export interface Placeholder {
export class PlaceholderGroup extends Map<string, Placeholder[]> {} export class PlaceholderGroup extends Map<string, Placeholder[]> {}
export const DefaultConfiguration: Configuration = { export const DefaultConfiguration: Configuration = {
max_tags_to_fetch: 200, // the amount of tags to fetch from the github API max_tags_to_fetch: 100, // the amount of tags to fetch from the github API
max_pull_requests: 200, // the amount of pull requests to process max_pull_requests: 200, // the amount of pull requests to process
max_back_track_time_days: 365, // allow max of 365 days back to check up on pull requests max_back_track_time_days: 365, // allow max of 365 days back to check up on pull requests
exclude_merge_branches: [], // branches to exclude from counting as PRs (e.g. YourOrg/qa, YourOrg/main) exclude_merge_branches: [], // branches to exclude from counting as PRs (e.g. YourOrg/qa, YourOrg/main)
+18 -28
View File
@@ -211,10 +211,17 @@ export class GithubRepository extends BaseRepository {
const pageSize = maxTagsToFetch > 100 ? 100 : maxTagsToFetch // 100 max page size in graphql const pageSize = maxTagsToFetch > 100 ? 100 : maxTagsToFetch // 100 max page size in graphql
const tagsInfo: TagInfo[] = [] const tagsInfo: TagInfo[] = []
let hasNextPage = true
let cursor: string | null = null
while (hasNextPage && tagsInfo.length < maxTagsToFetch) {
const result: GraphQlQueryResponse<unknown> = await this.octokit.graphql(` const result: GraphQlQueryResponse<unknown> = await this.octokit.graphql(`
{ {
repository(owner: "${owner}", name: "${repo}") { repository(owner: "${owner}", name: "${repo}") {
refs(refPrefix: "refs/tags/", first: ${pageSize}, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) { refs(refPrefix: "refs/tags/", first: ${pageSize}, after: ${cursor ? `"${cursor}"` : 'null'}, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
pageInfo {
hasNextPage
endCursor
}
edges { edges {
node { node {
name name
@@ -234,43 +241,26 @@ export class GithubRepository extends BaseRepository {
} }
} }
} }
} }
`) `)
// @ts-expect-error graphql response // @ts-expect-error graphql response
const refs = result.repository.refs
hasNextPage = refs.pageInfo.hasNextPage && tagsInfo.length < maxTagsToFetch
cursor = refs.pageInfo.endCursor
// eslint-disable-next-line github/array-foreach, @typescript-eslint/no-explicit-any // eslint-disable-next-line github/array-foreach, @typescript-eslint/no-explicit-any
result.repository.refs.edges.forEach((edge: any) => { refs.edges.forEach((edge: any) => {
if (tagsInfo.length < maxTagsToFetch) {
tagsInfo.push({ tagsInfo.push({
name: edge.node.name, name: edge.node.name,
commit: edge.node.target.oid commit: edge.node.target.oid
}) })
}) }
const options = this.octokit.repos.listTags.endpoint.merge({
owner,
repo,
direction: 'desc',
per_page: 100
})
for await (const response of this.octokit.paginate.iterator(options)) {
type TagsListData = RestEndpointMethodTypes['repos']['listTags']['response']['data']
const tags: TagsListData = response.data as TagsListData
for (const tag of tags) {
tagsInfo.push({
name: tag.name,
commit: tag.commit.sha
}) })
} }
// for performance only fetch newest maxTagsToFetch tags!! core.info(`️ Retrieved ${tagsInfo.length} (fetching max: ${maxTagsToFetch}) tags from the GitHub API for ${owner}/${repo}`)
if (tagsInfo.length >= maxTagsToFetch) {
break
}
}
core.info(`️ Found ${tagsInfo.length} (fetching max: ${maxTagsToFetch}) tags from the GitHub API for ${owner}/${repo}`)
return tagsInfo return tagsInfo
} }