- introduce experiment to fetch tags via graphQL (will offer the ability to fetch less tags, but ordered based on commit date)

This commit is contained in:
Mike Penz
2025-02-17 16:00:45 +01:00
parent c848d60dbb
commit b66fb5e3cc
3 changed files with 44 additions and 5 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export default [{
ignores: ["**/dist/", "**/lib/", "**/node_modules/"] ignores: ["**/dist/", "**/lib/", "**/node_modules/"]
}, ...compat.extends("plugin:github/recommended"), { }, ...compat.extends("plugin:github/recommended"), {
files: ["src/**.ts", "__tests__/**.ts"], files: ["**/*.ts", "__tests__/**.ts"],
plugins: { plugins: {
jest, jest,
+4 -4
View File
@@ -48,6 +48,8 @@
"semver": "^7.7.0" "semver": "^7.7.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/node": "^22.12.0", "@types/node": "^22.12.0",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
@@ -55,19 +57,17 @@
"@typescript-eslint/parser": "^8.22.0", "@typescript-eslint/parser": "^8.22.0",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint": "^9.19.0", "eslint": "^9.19.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-github": "^5.1.7", "eslint-plugin-github": "^5.1.7",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.11.0", "eslint-plugin-jest": "^28.11.0",
"eslint-plugin-prettier": "^5.2.3", "eslint-plugin-prettier": "^5.2.3",
"eslint-import-resolver-typescript": "^3.7.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-circus": "^29.7.0", "jest-circus": "^29.7.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "3.4.2", "prettier": "3.4.2",
"ts-jest": "^29.2.5", "ts-jest": "^29.2.5",
"typescript": "^5.7.3", "typescript": "^5.7.3"
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0"
}, },
"overrides": { "overrides": {
"glob": "11.0.1" "glob": "11.0.1"
+39
View File
@@ -7,6 +7,7 @@ import {DiffInfo} from '../pr-collector/commits.js'
import {CommentInfo, PullData, PullRequestInfo, PullReviewsData, PullsListData} from '../pr-collector/pullRequests.js' import {CommentInfo, PullData, PullRequestInfo, PullReviewsData, PullsListData} from '../pr-collector/pullRequests.js'
import {Unpacked} from '../pr-collector/utils.js' import {Unpacked} from '../pr-collector/utils.js'
import moment from 'moment' import moment from 'moment'
import {GraphQlQueryResponse} from '@octokit/graphql/types'
export class GithubRepository extends BaseRepository { export class GithubRepository extends BaseRepository {
async getDiffRemote(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> { async getDiffRemote(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> {
@@ -194,6 +195,7 @@ export class GithubRepository extends BaseRepository {
auth: `token ${this.token}`, auth: `token ${this.token}`,
baseUrl: this.url baseUrl: this.url
}) })
if (this.proxy) { if (this.proxy) {
const agent = new HttpsProxyAgent(this.proxy) const agent = new HttpsProxyAgent(this.proxy)
this.octokit.hook.before('request', options => { this.octokit.hook.before('request', options => {
@@ -206,7 +208,44 @@ export class GithubRepository extends BaseRepository {
} }
async getTags(owner: string, repo: string, maxTagsToFetch: number): Promise<TagInfo[]> { async getTags(owner: string, repo: string, maxTagsToFetch: number): Promise<TagInfo[]> {
const pageSize = maxTagsToFetch > 100 ? 100 : maxTagsToFetch // 100 max page size in graphql
const tagsInfo: TagInfo[] = [] 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 {
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
})
})
const options = this.octokit.repos.listTags.endpoint.merge({ const options = this.octokit.repos.listTags.endpoint.merge({
owner, owner,
repo, repo,