- introduce paging to graphQL logic
This commit is contained in:
+1646
-1617
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -238,39 +245,22 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user