From b66fb5e3ccb2e4c89b6146f321054986fdab38b0 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 17 Feb 2025 16:00:45 +0100 Subject: [PATCH] - introduce experiment to fetch tags via graphQL (will offer the ability to fetch less tags, but ordered based on commit date) --- eslint.config.mjs | 2 +- package.json | 8 +++--- src/repositories/GithubRepository.ts | 39 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 0eb8e71..3018dba 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -19,7 +19,7 @@ export default [{ ignores: ["**/dist/", "**/lib/", "**/node_modules/"] }, ...compat.extends("plugin:github/recommended"), { - files: ["src/**.ts", "__tests__/**.ts"], + files: ["**/*.ts", "__tests__/**.ts"], plugins: { jest, diff --git a/package.json b/package.json index d63dfba..e230a2e 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,8 @@ "semver": "^7.7.0" }, "devDependencies": { + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "^9.19.0", "@types/jest": "^29.5.14", "@types/node": "^22.12.0", "@types/semver": "^7.5.8", @@ -55,19 +57,17 @@ "@typescript-eslint/parser": "^8.22.0", "@vercel/ncc": "^0.38.3", "eslint": "^9.19.0", + "eslint-import-resolver-typescript": "^3.7.0", "eslint-plugin-github": "^5.1.7", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jest": "^28.11.0", "eslint-plugin-prettier": "^5.2.3", - "eslint-import-resolver-typescript": "^3.7.0", "jest": "^29.7.0", "jest-circus": "^29.7.0", "js-yaml": "^4.1.0", "prettier": "3.4.2", "ts-jest": "^29.2.5", - "typescript": "^5.7.3", - "@eslint/eslintrc": "^3.2.0", - "@eslint/js": "^9.19.0" + "typescript": "^5.7.3" }, "overrides": { "glob": "11.0.1" diff --git a/src/repositories/GithubRepository.ts b/src/repositories/GithubRepository.ts index a5dd3e0..424d857 100644 --- a/src/repositories/GithubRepository.ts +++ b/src/repositories/GithubRepository.ts @@ -7,6 +7,7 @@ import {DiffInfo} from '../pr-collector/commits.js' import {CommentInfo, PullData, PullRequestInfo, PullReviewsData, PullsListData} from '../pr-collector/pullRequests.js' import {Unpacked} from '../pr-collector/utils.js' import moment from 'moment' +import {GraphQlQueryResponse} from '@octokit/graphql/types' export class GithubRepository extends BaseRepository { async getDiffRemote(owner: string, repo: string, base: string, head: string): Promise { @@ -194,6 +195,7 @@ export class GithubRepository extends BaseRepository { auth: `token ${this.token}`, baseUrl: this.url }) + if (this.proxy) { const agent = new HttpsProxyAgent(this.proxy) this.octokit.hook.before('request', options => { @@ -206,7 +208,44 @@ export class GithubRepository extends BaseRepository { } async getTags(owner: string, repo: string, maxTagsToFetch: number): Promise { + const pageSize = maxTagsToFetch > 100 ? 100 : maxTagsToFetch // 100 max page size in graphql const tagsInfo: TagInfo[] = [] + + const result: GraphQlQueryResponse = 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({ owner, repo,