style: code formatting

This commit is contained in:
Ankio
2023-11-01 11:05:11 +08:00
parent 08cf89bc11
commit e08045ee77
13 changed files with 520 additions and 516 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import {Rule, Extractor, Regex, Transformer, Sort, PullConfiguration} from './pr-collector/types' import {Extractor, PullConfiguration, Regex, Rule, Sort, Transformer} from './pr-collector/types'
export interface Configuration extends PullConfiguration { export interface Configuration extends PullConfiguration {
max_tags_to_fetch: number max_tags_to_fetch: number
+2 -4
View File
@@ -1,10 +1,9 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import moment from 'moment' import moment from 'moment'
import {failOrError} from './utils' import {failOrError} from './utils'
import {PullRequestInfo} from './pullRequests' import {PullRequestInfo} from './pullRequests'
import {Options} from './prCollector' import {Options} from './prCollector'
import {BaseRepository} from "../repositories/BaseRepository"; import {BaseRepository} from '../repositories/BaseRepository'
export interface DiffInfo { export interface DiffInfo {
changedFiles: number changedFiles: number
@@ -35,8 +34,7 @@ export interface CommitInfo {
} }
export class Commits { export class Commits {
constructor(private repositoryUtils: BaseRepository) { constructor(private repositoryUtils: BaseRepository) {}
}
async getDiff(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> { async getDiff(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> {
const diff: DiffInfo = await this.getDiffRemote(owner, repo, base, head) const diff: DiffInfo = await this.getDiffRemote(owner, repo, base, head)
+2 -4
View File
@@ -1,12 +1,10 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {PullConfiguration} from './types' import {PullConfiguration} from './types'
import {Octokit} from '@octokit/rest'
import {TagInfo, Tags} from './tags' import {TagInfo, Tags} from './tags'
import {failOrError} from './utils' import {failOrError} from './utils'
import {HttpsProxyAgent} from 'https-proxy-agent'
import {PullRequestInfo, PullRequests} from './pullRequests' import {PullRequestInfo, PullRequests} from './pullRequests'
import {Commits, DiffInfo} from './commits' import {Commits, DiffInfo} from './commits'
import {BaseRepository} from "../repositories/BaseRepository"; import {BaseRepository} from '../repositories/BaseRepository'
export interface Options { export interface Options {
owner: string // the owner of the repository owner: string // the owner of the repository
@@ -47,7 +45,7 @@ export class PullRequestCollector {
private fetchReleaseInformation = false, private fetchReleaseInformation = false,
private fetchReviews = false, private fetchReviews = false,
private commitMode = false, private commitMode = false,
private configuration: PullConfiguration, private configuration: PullConfiguration
) {} ) {}
async build(): Promise<Data | null> { async build(): Promise<Data | null> {
+9 -8
View File
@@ -1,11 +1,10 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest' import {RestEndpointMethodTypes} from '@octokit/rest'
import {Unpacked} from './utils'
import moment from 'moment' import moment from 'moment'
import {Property, Sort} from './types' import {Property, Sort} from './types'
import {Commits, DiffInfo, filterCommits} from './commits' import {Commits, DiffInfo, filterCommits} from './commits'
import {Options} from './prCollector' import {Options} from './prCollector'
import {BaseRepository} from "../repositories/BaseRepository"; import {BaseRepository} from '../repositories/BaseRepository'
export interface PullRequestInfo { export interface PullRequestInfo {
number: number number: number
@@ -77,12 +76,17 @@ export class PullRequests {
private commits: Commits private commits: Commits
) {} ) {}
async getForCommitHash(owner: string, repo: string, commit_sha: string, maxPullRequests: number): Promise<PullRequestInfo[]> { async getForCommitHash(owner: string, repo: string, commit_sha: string, maxPullRequests: number): Promise<PullRequestInfo[]> {
return sortPrs(await this.repositoryUtils.getForCommitHash(owner, repo, commit_sha, maxPullRequests)) return sortPrs(await this.repositoryUtils.getForCommitHash(owner, repo, commit_sha, maxPullRequests))
} }
async getBetweenDates(owner: string, repo: string, fromDate: moment.Moment, toDate: moment.Moment, maxPullRequests: number): Promise<PullRequestInfo[]> { async getBetweenDates(
owner: string,
repo: string,
fromDate: moment.Moment,
toDate: moment.Moment,
maxPullRequests: number
): Promise<PullRequestInfo[]> {
return sortPrs(await this.repositoryUtils.getBetweenDates(owner, repo, fromDate, toDate, maxPullRequests)) return sortPrs(await this.repositoryUtils.getBetweenDates(owner, repo, fromDate, toDate, maxPullRequests))
} }
@@ -215,8 +219,6 @@ export class PullRequests {
} }
} }
function sortPrs(pullRequests: PullRequestInfo[]): PullRequestInfo[] { function sortPrs(pullRequests: PullRequestInfo[]): PullRequestInfo[] {
return sortPullRequests(pullRequests, { return sortPullRequests(pullRequests, {
order: 'ASC', order: 'ASC',
@@ -281,4 +283,3 @@ export function retrieveProperty(pr: PullRequestInfo, property: Property, useCas
} }
return value return value
} }
+1 -1
View File
@@ -6,7 +6,7 @@ import {RegexTransformer, TagResolver, Transformer} from './types'
import {createCommandManager} from './gitHelper' import {createCommandManager} from './gitHelper'
import moment from 'moment' import moment from 'moment'
import {validateTransformer} from './regexUtils' import {validateTransformer} from './regexUtils'
import {BaseRepository} from "../repositories/BaseRepository"; import {BaseRepository} from '../repositories/BaseRepository'
export interface TagResult { export interface TagResult {
from: TagInfo | null from: TagInfo | null
+1 -1
View File
@@ -1,5 +1,5 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Rule, RegexTransformer} from './pr-collector/types' import {RegexTransformer, Rule} from './pr-collector/types'
import {PullRequestInfo, retrieveProperty} from './pr-collector/pullRequests' import {PullRequestInfo, retrieveProperty} from './pr-collector/pullRequests'
import {validateTransformer} from './pr-collector/regexUtils' import {validateTransformer} from './pr-collector/regexUtils'
+1 -2
View File
@@ -1,13 +1,12 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Configuration} from './configuration' import {Configuration} from './configuration'
import {checkExportedData, writeCacheData} from './utils' import {checkExportedData, writeCacheData} from './utils'
import {PullRequestData, buildChangelog} from './transform' import {buildChangelog, PullRequestData} from './transform'
import {PullRequestCollector} from './pr-collector/prCollector' import {PullRequestCollector} from './pr-collector/prCollector'
import {failOrError} from './pr-collector/utils' import {failOrError} from './pr-collector/utils'
import {TagInfo} from './pr-collector/tags' import {TagInfo} from './pr-collector/tags'
import {DiffInfo} from './pr-collector/commits' import {DiffInfo} from './pr-collector/commits'
import {PullRequestInfo} from './pr-collector/pullRequests' import {PullRequestInfo} from './pr-collector/pullRequests'
import * as fs from 'fs'
import {BaseRepository} from './repositories/BaseRepository' import {BaseRepository} from './repositories/BaseRepository'
export interface ReleaseNotesOptions { export interface ReleaseNotesOptions {
+21 -15
View File
@@ -1,20 +1,23 @@
import {TagInfo} from "../pr-collector/tags"; import {TagInfo} from '../pr-collector/tags'
import {DiffInfo} from "../pr-collector/commits"; import {DiffInfo} from '../pr-collector/commits'
import {Options} from "../pr-collector/prCollector"; import moment from 'moment/moment'
import moment from "moment/moment"; import {PullRequestInfo} from '../pr-collector/pullRequests'
import {PullRequestInfo} from "../pr-collector/pullRequests"; import * as core from '@actions/core'
import * as core from "@actions/core"; import {createCommandManager} from '../pr-collector/gitHelper'
import {createCommandManager} from "../pr-collector/gitHelper";
export abstract class BaseRepository { export abstract class BaseRepository {
proxy?: string; proxy?: string
noProxyArray: string[] noProxyArray: string[]
// Define an abstract getter for the default URL // Define an abstract getter for the default URL
abstract get defaultUrl(): string; abstract get defaultUrl(): string
abstract get homeUrl():string; abstract get homeUrl(): string
protected constructor(protected token: string, protected url: string | undefined,protected repositoryPath:string) { protected constructor(
protected token: string,
protected url: string | undefined,
protected repositoryPath: string
) {
this.proxy = process.env.https_proxy || process.env.HTTPS_PROXY this.proxy = process.env.https_proxy || process.env.HTTPS_PROXY
const noProxy = process.env.no_proxy || process.env.NO_PROXY const noProxy = process.env.no_proxy || process.env.NO_PROXY
this.noProxyArray = [] this.noProxyArray = []
@@ -29,16 +32,20 @@ export abstract class BaseRepository {
abstract getDiffRemote(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> abstract getDiffRemote(owner: string, repo: string, base: string, head: string): Promise<DiffInfo>
abstract getForCommitHash(owner: string, repo: string, commit_sha: string, maxPullRequests: number): Promise<PullRequestInfo[]> abstract getForCommitHash(owner: string, repo: string, commit_sha: string, maxPullRequests: number): Promise<PullRequestInfo[]>
abstract getBetweenDates(owner: string, repo: string, fromDate: moment.Moment, toDate: moment.Moment, maxPullRequests: number): Promise<PullRequestInfo[]> abstract getBetweenDates(
owner: string,
repo: string,
fromDate: moment.Moment,
toDate: moment.Moment,
maxPullRequests: number
): Promise<PullRequestInfo[]>
abstract getOpen(owner: string, repo: string, maxPullRequests: number): Promise<PullRequestInfo[]> abstract getOpen(owner: string, repo: string, maxPullRequests: number): Promise<PullRequestInfo[]>
abstract getReviews(owner: string, repo: string, pr: PullRequestInfo): Promise<void> abstract getReviews(owner: string, repo: string, pr: PullRequestInfo): Promise<void>
protected async getTagByCreateTime(repositoryPath: string, tagInfo: TagInfo) { protected async getTagByCreateTime(repositoryPath: string, tagInfo: TagInfo) {
core.info(`⚠️ No release information found for ${tagInfo.name}, trying to retrieve tag creation time as fallback.`) core.info(`⚠️ No release information found for ${tagInfo.name}, trying to retrieve tag creation time as fallback.`)
const gitHelper = await createCommandManager(repositoryPath) const gitHelper = await createCommandManager(repositoryPath)
@@ -56,5 +63,4 @@ export abstract class BaseRepository {
} }
return tagInfo return tagInfo
} }
} }
+19 -18
View File
@@ -1,19 +1,14 @@
import {BaseRepository} from "./BaseRepository"; import {BaseRepository} from './BaseRepository'
import {Octokit, RestEndpointMethodTypes} from "@octokit/rest"; import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import {HttpsProxyAgent} from "https-proxy-agent"; import {HttpsProxyAgent} from 'https-proxy-agent'
import * as core from "@actions/core"; import * as core from '@actions/core'
import {TagInfo} from "../pr-collector/tags"; import {TagInfo} from '../pr-collector/tags'
import moment from "moment/moment"; import moment from 'moment/moment'
import {DiffInfo} from "../pr-collector/commits"; import {DiffInfo} from '../pr-collector/commits'
import { import {CommentInfo, PullData, PullRequestInfo, PullReviewsData, PullsListData} from '../pr-collector/pullRequests'
CommentInfo, PullData, import {Unpacked} from '../pr-collector/utils'
PullRequestInfo,
PullReviewsData, PullsListData
} from "../pr-collector/pullRequests";
import {Unpacked} from "../pr-collector/utils";
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> {
let changedFilesCount = 0 let changedFilesCount = 0
let additionCount = 0 let additionCount = 0
@@ -93,7 +88,13 @@ export class GithubRepository extends BaseRepository {
return mergedPRs return mergedPRs
} }
async getBetweenDates(owner: string, repo: string, fromDate: moment.Moment, toDate: moment.Moment, maxPullRequests: number): Promise<PullRequestInfo[]> { async getBetweenDates(
owner: string,
repo: string,
fromDate: moment.Moment,
toDate: moment.Moment,
maxPullRequests: number
): Promise<PullRequestInfo[]> {
const mergedPRs: PullRequestInfo[] = [] const mergedPRs: PullRequestInfo[] = []
const options = this.octokit.pulls.list.endpoint.merge({ const options = this.octokit.pulls.list.endpoint.merge({
owner, owner,
@@ -173,13 +174,13 @@ export class GithubRepository extends BaseRepository {
} }
get defaultUrl(): string { get defaultUrl(): string {
return "https://api.github.com"; return 'https://api.github.com'
} }
private octokit: Octokit private octokit: Octokit
constructor(token: string, url: string | undefined, repositoryPath: string) { constructor(token: string, url: string | undefined, repositoryPath: string) {
super(token, url,repositoryPath); super(token, url, repositoryPath)
this.url = url || this.defaultUrl this.url = url || this.defaultUrl
// load octokit instance // load octokit instance
@@ -297,6 +298,6 @@ export class GithubRepository extends BaseRepository {
return false return false
} }
get homeUrl(): string { get homeUrl(): string {
return "https://github.com"; return 'https://github.com'
} }
} }
+1 -1
View File
@@ -11,7 +11,7 @@ import {
} from './pr-collector/pullRequests' } from './pr-collector/pullRequests'
import {DiffInfo} from './pr-collector/commits' import {DiffInfo} from './pr-collector/commits'
import {validateTransformer} from './pr-collector/regexUtils' import {validateTransformer} from './pr-collector/regexUtils'
import {Transformer, RegexTransformer} from './pr-collector/types' import {RegexTransformer, Transformer} from './pr-collector/types'
import {ReleaseNotesOptions} from './releaseNotesBuilder' import {ReleaseNotesOptions} from './releaseNotesBuilder'
import {matchesRules} from './regexUtils' import {matchesRules} from './regexUtils'
+1
View File
@@ -7,6 +7,7 @@ import {DiffInfo} from './pr-collector/commits'
import {PullRequestInfo} from './pr-collector/pullRequests' import {PullRequestInfo} from './pr-collector/pullRequests'
import {Data, ReleaseNotesOptions} from './releaseNotesBuilder' import {Data, ReleaseNotesOptions} from './releaseNotesBuilder'
import {env} from 'process' import {env} from 'process'
/** /**
* Resolves the repository path, relatively to the GITHUB_WORKSPACE * Resolves the repository path, relatively to the GITHUB_WORKSPACE
*/ */