- 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
+1647 -1618
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 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_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)
+40 -50
View File
@@ -211,66 +211,56 @@ export class GithubRepository extends BaseRepository {
const pageSize = maxTagsToFetch > 100 ? 100 : maxTagsToFetch // 100 max page size in graphql
const tagsInfo: TagInfo[] = []
const result: GraphQlQueryResponse<unknown> = await this.octokit.graphql(`
{
repository(owner: "${owner}", name: "${repo}") {
refs(refPrefix: "refs/tags/", first: ${pageSize}, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
edges {
node {
name
target {
oid
... on Tag {
message
commitUrl
tagger {
let hasNextPage = true
let cursor: string | null = null
while (hasNextPage && tagsInfo.length < maxTagsToFetch) {
const result: GraphQlQueryResponse<unknown> = await this.octokit.graphql(`
{
repository(owner: "${owner}", name: "${repo}") {
refs(refPrefix: "refs/tags/", first: ${pageSize}, after: ${cursor ? `"${cursor}"` : 'null'}, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
name
email
date
target {
oid
... on Tag {
message
commitUrl
tagger {
name
email
date
}
}
}
}
}
}
}
}
}
}
}
`)
`)
// @ts-expect-error graphql response
// eslint-disable-next-line github/array-foreach, @typescript-eslint/no-explicit-any
result.repository.refs.edges.forEach((edge: any) => {
tagsInfo.push({
name: edge.node.name,
commit: edge.node.target.oid
// @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
refs.edges.forEach((edge: any) => {
if (tagsInfo.length < maxTagsToFetch) {
tagsInfo.push({
name: edge.node.name,
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!!
if (tagsInfo.length >= maxTagsToFetch) {
break
}
}
core.info(`Found ${tagsInfo.length} (fetching max: ${maxTagsToFetch}) tags from the GitHub API for ${owner}/${repo}`)
core.info(`Retrieved ${tagsInfo.length} (fetching max: ${maxTagsToFetch}) tags from the GitHub API for ${owner}/${repo}`)
return tagsInfo
}