From 82350e1ed75639f554dd1a1b056dc266dfe5184f Mon Sep 17 00:00:00 2001 From: Ankio Date: Wed, 1 Nov 2023 08:11:04 +0800 Subject: [PATCH] fix: removed github url --- src/pr-collector/tags.ts | 2 +- src/releaseNotesBuilder.ts | 7 ++-- src/repositories/BaseRepository.ts | 1 + src/repositories/GiteaRepository.ts | 48 ++++++++++++++++++++-------- src/repositories/GithubRepository.ts | 5 ++- src/transform.ts | 2 +- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/pr-collector/tags.ts b/src/pr-collector/tags.ts index 305b5b2..03635c7 100644 --- a/src/pr-collector/tags.ts +++ b/src/pr-collector/tags.ts @@ -194,7 +194,7 @@ export class Tags { /* * Uses the provided filter (if available) to filter out any tags not currently relevant. - * https://github.com/mikepenz/release-changelog-builder-action/issues/566 + * https://tagTransformers/mikepenz/release-changelog-builder-action/issues/566 */ export function filterTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[] { const filter = tagResolver.filter diff --git a/src/releaseNotesBuilder.ts b/src/releaseNotesBuilder.ts index 535608c..176aace 100644 --- a/src/releaseNotesBuilder.ts +++ b/src/releaseNotesBuilder.ts @@ -22,6 +22,7 @@ export interface ReleaseNotesOptions { fetchReviews: boolean // defines if the action should fetch the reviews for the PR. commitMode: boolean // defines if we use the alternative commit based mode. note: this is only partially supported configuration: Configuration // the configuration as defined in `configuration.ts` + repositoryUtils: BaseRepository } export interface Data { @@ -111,7 +112,8 @@ export class ReleaseNotesBuilder { fetchReleaseInformation: this.fetchReleaseInformation, fetchReviews: this.fetchReviews, commitMode: this.commitMode, - configuration: this.configuration + configuration: this.configuration, + repositoryUtils: this.repositoryUtils } const mergedPullRequests = prData.mergedPullRequests const diffInfo = prData.diffInfo @@ -164,7 +166,8 @@ export class ReleaseNotesBuilder { fetchReleaseInformation: this.fetchReleaseInformation || orgOptions.fetchReleaseInformation, fetchReviews: this.fetchReviews || orgOptions.fetchReviews, commitMode: this.commitMode || orgOptions.commitMode, - configuration: this.configuration || orgOptions.configuration + configuration: this.configuration || orgOptions.configuration, + repositoryUtils: this.repositoryUtils || orgOptions.repositoryUtils } this.setOutputs(options, diffInfo, mergedPullRequests) diff --git a/src/repositories/BaseRepository.ts b/src/repositories/BaseRepository.ts index 7ad1c5f..f31dd35 100644 --- a/src/repositories/BaseRepository.ts +++ b/src/repositories/BaseRepository.ts @@ -13,6 +13,7 @@ export abstract class BaseRepository { // Define an abstract getter for the default URL abstract get defaultUrl(): string; + abstract get homeUrl():string; protected constructor(protected token: string, protected url: string | undefined,protected repositoryPath:string) { this.proxy = process.env.https_proxy || process.env.HTTPS_PROXY const noProxy = process.env.no_proxy || process.env.NO_PROXY diff --git a/src/repositories/GiteaRepository.ts b/src/repositories/GiteaRepository.ts index 7cda424..fcb7522 100644 --- a/src/repositories/GiteaRepository.ts +++ b/src/repositories/GiteaRepository.ts @@ -6,9 +6,11 @@ import { } from "../pr-collector/pullRequests"; import {DiffInfo} from "../pr-collector/commits"; import {Api, PullRequest, PullReview} from "gitea-js"; -import moment from "moment"; +import moment, {min} from "moment"; import * as core from "@actions/core"; import {createCommandManager} from "../pr-collector/gitHelper"; +import {match} from "assert"; +import {log} from "util"; export class GiteaRepository extends BaseRepository { private api: Api @@ -150,27 +152,43 @@ export class GiteaRepository extends BaseRepository { }; } + static pulls:PullRequest[] = []; async getForCommitHash(owner: string, repo: string, commit_sha: string, maxPullRequests: number): Promise { const mergedPRs: PullRequestInfo[] = [] - const response = await this.api.repos.repoListPullRequests(owner, repo, { - sort: 'recentupdate', - state: 'closed', - limit: 1000, - }) + if(GiteaRepository.pulls.length===0){ + let page = 1 + let count = 0 + while (count < maxPullRequests){ + let limit = Math.min(50, maxPullRequests) + const response = await this.api.repos.repoListPullRequests(owner, repo, { + sort: 'recentupdate', + state: 'closed', + limit: limit, + page + }) + if (response.error === null) { + GiteaRepository.pulls.push(...response.data) - - - if (response.error === null) { - - for (const pr of response.data) { - if (pr.merge_commit_sha === commit_sha) { - mergedPRs.push(this.mapPullRequest(pr, pr.merged_at ? 'merged' : 'open')) } + page++; + count+= response.data.length + if(response.data.length===0)break; + } + + } + + for (const pr of GiteaRepository.pulls) { + if (pr.merge_commit_sha === commit_sha) { + mergedPRs.push(this.mapPullRequest(pr, pr.merged_at ? 'merged' : 'open')) } } + + + core.debug(`⚠️ No more PRs retrieved from API. Fetched so far: ${mergedPRs.length}`) + return mergedPRs @@ -233,4 +251,8 @@ export class GiteaRepository extends BaseRepository { return tagsInfo } + get homeUrl(): string { + return "https://gitea.com"; + } + } \ No newline at end of file diff --git a/src/repositories/GithubRepository.ts b/src/repositories/GithubRepository.ts index 289da05..8b4303f 100644 --- a/src/repositories/GithubRepository.ts +++ b/src/repositories/GithubRepository.ts @@ -287,7 +287,7 @@ export class GithubRepository extends BaseRepository { for (let i = 0; i < Math.min(pullRequests.length, 3); i++) { const firstPR = pullRequests[i] if (!firstPR.merged_at) { - continue // no merged_at timestamp -> look for the next + // no merged_at timestamp -> look for the next } else if (fromDate.isAfter(moment(firstPR.merged_at))) { return true } else { @@ -296,4 +296,7 @@ export class GithubRepository extends BaseRepository { } return false } + get homeUrl(): string { + return "https://github.com"; + } } \ No newline at end of file diff --git a/src/transform.ts b/src/transform.ts index f852f53..13ab199 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -388,7 +388,7 @@ function fillAdditionalPlaceholders( } placeholderMap.set( 'RELEASE_DIFF', - `https://github.com/${options.owner}/${options.repo}/compare/${options.fromTag.name}...${options.toTag.name}` + `${options.repositoryUtils.homeUrl}/${options.owner}/${options.repo}/compare/${options.fromTag.name}...${options.toTag.name}` ) }