Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat source #836

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
Expand Down
44 changes: 10 additions & 34 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 5 additions & 21 deletions src/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,13 @@ export interface CommitInfo {
export class Commits {
constructor(private octokit: Octokit) {}

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)
diff.commitInfo = this.sortCommits(diff.commitInfo)
return diff
}

private async getDiffRemote(
owner: string,
repo: string,
base: string,
head: string
): Promise<DiffInfo> {
private async getDiffRemote(owner: string, repo: string, base: string, head: string): Promise<DiffInfo> {
let changedFilesCount = 0
let additionCount = 0
let deletionCount = 0
Expand All @@ -56,8 +46,7 @@ export class Commits {

// Fetch comparisons recursively until we don't find any commits
// This is because the GitHub API limits the number of commits returned in a single response.
let commits: RestEndpointMethodTypes['repos']['compareCommits']['response']['data']['commits'] =
[]
let commits: RestEndpointMethodTypes['repos']['compareCommits']['response']['data']['commits'] = []
let compareHead = head
// eslint-disable-next-line no-constant-condition
while (true) {
Expand All @@ -84,9 +73,7 @@ export class Commits {
compareHead = `${commits[0].sha}^`
}

core.info(
`ℹ️ Found ${commits.length} commits from the GitHub API for ${owner}/${repo}`
)
core.info(`ℹ️ Found ${commits.length} commits from the GitHub API for ${owner}/${repo}`)

return {
changedFiles: changedFilesCount,
Expand Down Expand Up @@ -135,10 +122,7 @@ export class Commits {
/**
* Filters out all commits which match the exclude pattern
*/
export function filterCommits(
commits: CommitInfo[],
excludeMergeBranches: string[]
): CommitInfo[] {
export function filterCommits(commits: CommitInfo[], excludeMergeBranches: string[]): CommitInfo[] {
const filteredCommits = []

for (const commit of commits) {
Expand Down
44 changes: 8 additions & 36 deletions src/gitHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import * as exec from '@actions/exec'
import * as io from '@actions/io'
import {directoryExistsSync} from './utils'

export async function createCommandManager(
workingDirectory: string
): Promise<GitCommandManager> {
export async function createCommandManager(workingDirectory: string): Promise<GitCommandManager> {
return await GitCommandManager.createCommandManager(workingDirectory)
}

Expand All @@ -20,52 +18,28 @@ class GitCommandManager {
}

async latestTag(): Promise<string> {
const revListOutput = await this.execGit([
'rev-list',
'--tags',
'--skip=0',
'--max-count=1'
])
const output = await this.execGit([
'describe',
'--abbrev=0',
'--tags',
revListOutput.stdout.trim()
])
const revListOutput = await this.execGit(['rev-list', '--tags', '--skip=0', '--max-count=1'])
const output = await this.execGit(['describe', '--abbrev=0', '--tags', revListOutput.stdout.trim()])
return output.stdout.trim()
}

async initialCommit(): Promise<string> {
const revListOutput = await this.execGit([
'rev-list',
'--max-parents=0',
'HEAD'
])
const revListOutput = await this.execGit(['rev-list', '--max-parents=0', 'HEAD'])
return revListOutput.stdout.trim()
}

async tagCreation(tagName: string): Promise<string> {
const creationDate = await this.execGit([
'for-each-ref',
'--format="%(creatordate:rfc)"',
`refs/tags/${tagName}`
])
const creationDate = await this.execGit(['for-each-ref', '--format="%(creatordate:rfc)"', `refs/tags/${tagName}`])
return creationDate.stdout.trim().replace(/"/g, '')
}

static async createCommandManager(
workingDirectory: string
): Promise<GitCommandManager> {
static async createCommandManager(workingDirectory: string): Promise<GitCommandManager> {
const result = new GitCommandManager()
await result.initializeCommandManager(workingDirectory)
return result
}

private async execGit(
args: string[],
allowAllExitCodes = false,
silent = false
): Promise<GitOutput> {
private async execGit(args: string[], allowAllExitCodes = false, silent = false): Promise<GitOutput> {
directoryExistsSync(this.workingDirectory, true)

const result = new GitOutput()
Expand All @@ -88,9 +62,7 @@ class GitCommandManager {
return result
}

private async initializeCommandManager(
workingDirectory: string
): Promise<void> {
private async initializeCommandManager(workingDirectory: string): Promise<void> {
this.workingDirectory = workingDirectory
this.gitPath = await io.which('git', true)
}
Expand Down
10 changes: 2 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {
parseConfiguration,
resolveConfiguration,
retrieveRepositoryPath,
writeOutput
} from './utils'
import {parseConfiguration, resolveConfiguration, retrieveRepositoryPath, writeOutput} from './utils'
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
import {Configuration} from './configuration'

Expand Down Expand Up @@ -44,8 +39,7 @@ async function run(): Promise<void> {
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true'
const failOnError = core.getInput('failOnError') === 'true'
const fetchReviewers = core.getInput('fetchReviewers') === 'true'
const fetchReleaseInformation =
core.getInput('fetchReleaseInformation') === 'true'
const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true'
const commitMode = core.getInput('commitMode') === 'true'

const result = await new ReleaseNotesBuilder(
Expand Down
54 changes: 11 additions & 43 deletions src/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@ export interface PullRequestInfo {

type PullData = RestEndpointMethodTypes['pulls']['get']['response']['data']

type PullsListData =
RestEndpointMethodTypes['pulls']['list']['response']['data']
type PullsListData = RestEndpointMethodTypes['pulls']['list']['response']['data']

type PullReviewData =
RestEndpointMethodTypes['pulls']['listReviews']['response']['data']
type PullReviewData = RestEndpointMethodTypes['pulls']['listReviews']['response']['data']

export class PullRequests {
constructor(private octokit: Octokit) {}

async getSingle(
owner: string,
repo: string,
prNumber: number
): Promise<PullRequestInfo | null> {
async getSingle(owner: string, repo: string, prNumber: number): Promise<PullRequestInfo | null> {
try {
const {data} = await this.octokit.pulls.get({
owner,
Expand All @@ -49,9 +43,7 @@ export class PullRequests {

return mapPullRequest(data)
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.warning(
`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`
)
core.warning(`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`)
return null
}
}
Expand Down Expand Up @@ -98,11 +90,7 @@ export class PullRequests {
return sortPrs(mergedPRs)
}

async getOpen(
owner: string,
repo: string,
maxPullRequests: number
): Promise<PullRequestInfo[]> {
async getOpen(owner: string, repo: string, maxPullRequests: number): Promise<PullRequestInfo[]> {
const openPrs: PullRequestInfo[] = []
const options = this.octokit.pulls.list.endpoint.merge({
owner,
Expand Down Expand Up @@ -134,11 +122,7 @@ export class PullRequests {
return sortPrs(openPrs)
}

async getReviewers(
owner: string,
repo: string,
pr: PullRequestInfo
): Promise<PullReviewData[]> {
async getReviewers(owner: string, repo: string, pr: PullRequestInfo): Promise<PullReviewData[]> {
const options = this.octokit.pulls.listReviews.endpoint.merge({
owner,
repo,
Expand All @@ -164,10 +148,7 @@ function sortPrs(pullRequests: PullRequestInfo[]): PullRequestInfo[] {
})
}

export function sortPullRequests(
pullRequests: PullRequestInfo[],
sort: Sort | string
): PullRequestInfo[] {
export function sortPullRequests(pullRequests: PullRequestInfo[], sort: Sort | string): PullRequestInfo[] {
let sortConfig: Sort

// legacy handling to support string sort config
Expand All @@ -191,11 +172,7 @@ export function sortPullRequests(
return pullRequests
}

export function compare(
a: PullRequestInfo,
b: PullRequestInfo,
sort: Sort
): number {
export function compare(a: PullRequestInfo, b: PullRequestInfo, sort: Sort): number {
if (sort.on_property === 'mergedAt') {
const aa = a.mergedAt || a.createdAt
const bb = b.mergedAt || b.createdAt
Expand All @@ -212,10 +189,7 @@ export function compare(
}

// helper function to add a special open label to prs not merged.
function attachSpeciaLabels(
status: 'open' | 'merged',
labels: Set<string>
): Set<string> {
function attachSpeciaLabels(status: 'open' | 'merged', labels: Set<string>): Set<string> {
labels.add(`--rcba-${status}`)
return labels
}
Expand All @@ -234,17 +208,11 @@ const mapPullRequest = (
mergeCommitSha: pr.merge_commit_sha || '',
author: pr.user?.login || '',
repoName: pr.base.repo.full_name,
labels: attachSpeciaLabels(
status,
new Set(
pr.labels?.map(lbl => lbl.name?.toLocaleLowerCase('en') || '') || []
)
),
labels: attachSpeciaLabels(status, new Set(pr.labels?.map(lbl => lbl.name?.toLocaleLowerCase('en') || '') || [])),
milestone: pr.milestone?.title || '',
body: pr.body || '',
assignees: pr.assignees?.map(asignee => asignee?.login || '') || [],
requestedReviewers:
pr.requested_reviewers?.map(reviewer => reviewer?.login || '') || [],
requestedReviewers: pr.requested_reviewers?.map(reviewer => reviewer?.login || '') || [],
approvedReviewers: [],
status
})
Loading