- introduce new additional placeholders useable for building the changelog
| **Placeholder** | **Description** | **Empty** |
|----------------------------|----------------------------------------------------------------------------------------------------|:---------:|
| `${{CHANGED_FILES}}` | The count of changed files. | |
| `${{ADDITIONS}}` | The count of code additions (lines). | |
| `${{DELETIONS}}` | The count of code deletions (lines). | |
| `${{CHANGES}}` | The count of total changes (lines). | |
| `${{COMMITS}}` | The count of commits in this release. | |
- restructure project to return additional diff related information along the individual commits
- update testcases to verify functionality of new placeholders
This commit is contained in:
+45
-22
@@ -1,9 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import {CommitInfo, Commits, filterCommits} from './commits'
|
||||
import {Commits, filterCommits, DiffInfo, DefaultDiffInfo} from './commits'
|
||||
import {Configuration, DefaultConfiguration} from './configuration'
|
||||
import {PullRequestInfo, PullRequests} from './pullRequests'
|
||||
import {Octokit} from '@octokit/rest'
|
||||
import {buildChangelog} from './transform'
|
||||
import {buildChangelog, fillAdditionalPlaceholders} from './transform'
|
||||
import {failOrError} from './utils'
|
||||
|
||||
export interface ReleaseNotesOptions {
|
||||
@@ -21,11 +21,15 @@ export interface ReleaseNotesOptions {
|
||||
export class ReleaseNotes {
|
||||
constructor(private octokit: Octokit, private options: ReleaseNotesOptions) {}
|
||||
|
||||
async pull(): Promise<string | null> {
|
||||
async pull(): Promise<string> {
|
||||
let mergedPullRequests: PullRequestInfo[]
|
||||
let diffInfo: DiffInfo
|
||||
if (!this.options.commitMode) {
|
||||
core.startGroup(`🚀 Load pull requests`)
|
||||
mergedPullRequests = await this.getMergedPullRequests(this.octokit)
|
||||
|
||||
const [info, prs] = await this.getMergedPullRequests(this.octokit)
|
||||
mergedPullRequests = prs
|
||||
diffInfo = info
|
||||
|
||||
// define the included PRs within this release as output
|
||||
core.setOutput(
|
||||
@@ -37,57 +41,74 @@ export class ReleaseNotes {
|
||||
.join(',')
|
||||
)
|
||||
|
||||
core.setOutput('changed_files', diffInfo.changedFiles)
|
||||
core.setOutput('additions', diffInfo.additions)
|
||||
core.setOutput('deletions', diffInfo.deletions)
|
||||
core.setOutput('changes', diffInfo.changes)
|
||||
core.setOutput('commits', diffInfo.commits)
|
||||
|
||||
core.endGroup()
|
||||
} else {
|
||||
core.startGroup(`🚀 Load commit history`)
|
||||
core.info(`⚠️ Executing experimental commit mode`)
|
||||
mergedPullRequests = await this.generateCommitPRs(this.octokit)
|
||||
const [info, prs] = await this.generateCommitPRs(this.octokit)
|
||||
mergedPullRequests = prs
|
||||
diffInfo = info
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
if (mergedPullRequests.length === 0) {
|
||||
core.warning(`⚠️ No pull requests found`)
|
||||
return null
|
||||
return fillAdditionalPlaceholders(
|
||||
this.options.configuration.empty_template ||
|
||||
DefaultConfiguration.empty_template,
|
||||
this.options
|
||||
)
|
||||
}
|
||||
|
||||
core.startGroup('📦 Build changelog')
|
||||
const resultChangelog = buildChangelog(mergedPullRequests, this.options)
|
||||
const resultChangelog = buildChangelog(
|
||||
diffInfo,
|
||||
mergedPullRequests,
|
||||
this.options
|
||||
)
|
||||
core.endGroup()
|
||||
return resultChangelog
|
||||
}
|
||||
|
||||
private async getCommitHistory(octokit: Octokit): Promise<CommitInfo[]> {
|
||||
private async getCommitHistory(octokit: Octokit): Promise<DiffInfo> {
|
||||
const {owner, repo, fromTag, toTag, failOnError} = this.options
|
||||
core.info(`ℹ️ Comparing ${owner}/${repo} - '${fromTag}...${toTag}'`)
|
||||
|
||||
const commitsApi = new Commits(octokit)
|
||||
let commits: CommitInfo[]
|
||||
let diffInfo: DiffInfo
|
||||
try {
|
||||
commits = await commitsApi.getDiff(owner, repo, fromTag, toTag)
|
||||
diffInfo = await commitsApi.getDiff(owner, repo, fromTag, toTag)
|
||||
} catch (error) {
|
||||
failOrError(
|
||||
`💥 Failed to retrieve - Invalid tag? - Because of: ${error}`,
|
||||
failOnError
|
||||
)
|
||||
return []
|
||||
return DefaultDiffInfo
|
||||
}
|
||||
if (commits.length === 0) {
|
||||
if (diffInfo.commitInfo.length === 0) {
|
||||
core.warning(`⚠️ No commits found between - ${fromTag}...${toTag}`)
|
||||
return []
|
||||
return DefaultDiffInfo
|
||||
}
|
||||
|
||||
return commits
|
||||
return diffInfo
|
||||
}
|
||||
|
||||
private async getMergedPullRequests(
|
||||
octokit: Octokit
|
||||
): Promise<PullRequestInfo[]> {
|
||||
): Promise<[DiffInfo, PullRequestInfo[]]> {
|
||||
const {owner, repo, includeOpen, fetchReviewers, configuration} =
|
||||
this.options
|
||||
|
||||
const commits = await this.getCommitHistory(octokit)
|
||||
const diffInfo = await this.getCommitHistory(octokit)
|
||||
const commits = diffInfo.commitInfo
|
||||
if (commits.length === 0) {
|
||||
return []
|
||||
return [diffInfo, []]
|
||||
}
|
||||
|
||||
const firstCommit = commits[0]
|
||||
@@ -193,17 +214,18 @@ export class ReleaseNotes {
|
||||
}
|
||||
}
|
||||
|
||||
return finalPrs
|
||||
return [diffInfo, finalPrs]
|
||||
}
|
||||
|
||||
private async generateCommitPRs(
|
||||
octokit: Octokit
|
||||
): Promise<PullRequestInfo[]> {
|
||||
): Promise<[DiffInfo, PullRequestInfo[]]> {
|
||||
const {owner, repo, configuration} = this.options
|
||||
|
||||
const commits = await this.getCommitHistory(octokit)
|
||||
const diffInfo = await this.getCommitHistory(octokit)
|
||||
const commits = diffInfo.commitInfo
|
||||
if (commits.length === 0) {
|
||||
return []
|
||||
return [diffInfo, []]
|
||||
}
|
||||
|
||||
const prCommits = filterCommits(
|
||||
@@ -214,7 +236,7 @@ export class ReleaseNotes {
|
||||
|
||||
core.info(`ℹ️ Retrieved ${prCommits.length} commits for ${owner}/${repo}`)
|
||||
|
||||
return prCommits.map(function (commit): PullRequestInfo {
|
||||
const prs = prCommits.map(function (commit): PullRequestInfo {
|
||||
return {
|
||||
number: 0,
|
||||
title: commit.summary,
|
||||
@@ -234,5 +256,6 @@ export class ReleaseNotes {
|
||||
status: 'merged'
|
||||
}
|
||||
})
|
||||
return [diffInfo, prs]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user