- split logic to validate and read in additional details for changelog generation into new releaseNotesBuilder
- construct main class to be as simple as possible
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {ReleaseNotes} from '../src/releaseNotes'
|
import { ReleaseNotes } from '../src/releaseNotes'
|
||||||
import { resolveConfiguration } from '../src/utils';
|
import { resolveConfiguration } from '../src/utils';
|
||||||
import { Octokit } from '@octokit/rest';
|
import { Octokit } from '@octokit/rest';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { resolveConfiguration } from '../src/utils';
|
||||||
|
import { ReleaseNotesBuilder } from '../src/releaseNotesBuilder';
|
||||||
|
|
||||||
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
|
/*
|
||||||
|
test('test runs', () => {
|
||||||
|
jest.setTimeout(180000);
|
||||||
|
|
||||||
|
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
|
||||||
|
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
||||||
|
const options: cp.ExecSyncOptions = {
|
||||||
|
env: process.env
|
||||||
|
}
|
||||||
|
console.log(cp.execSync(`node ${ip}`, options).toString())
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
it('Should match generated changelog (unspecified fromTag)', async () => {
|
||||||
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
|
const configuration = resolveConfiguration('', 'configs/configuration.json')
|
||||||
|
const releaseNotesBuilder = new ReleaseNotesBuilder(
|
||||||
|
null,
|
||||||
|
'.',
|
||||||
|
'mikepenz',
|
||||||
|
'release-changelog-builder-action',
|
||||||
|
null,
|
||||||
|
'v0.0.3',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
configuration
|
||||||
|
)
|
||||||
|
|
||||||
|
const changeLog = await releaseNotesBuilder.build()
|
||||||
|
console.log(changeLog)
|
||||||
|
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||||
|
|
||||||
|
- [CI] Specify Test Case
|
||||||
|
- PR: #10
|
||||||
|
|
||||||
|
`)
|
||||||
|
})
|
||||||
+140
-77
@@ -296,12 +296,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const core = __importStar(__webpack_require__(2186));
|
const core = __importStar(__webpack_require__(2186));
|
||||||
const utils_1 = __webpack_require__(918);
|
const utils_1 = __webpack_require__(918);
|
||||||
const releaseNotes_1 = __webpack_require__(5882);
|
|
||||||
const gitHelper_1 = __webpack_require__(353);
|
|
||||||
const github = __importStar(__webpack_require__(5438));
|
const github = __importStar(__webpack_require__(5438));
|
||||||
const configuration_1 = __webpack_require__(5527);
|
const releaseNotesBuilder_1 = __webpack_require__(4883);
|
||||||
const rest_1 = __webpack_require__(5375);
|
|
||||||
const tags_1 = __webpack_require__(7532);
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.setOutput('failed', false); // mark the action not failed by default
|
core.setOutput('failed', false); // mark the action not failed by default
|
||||||
@@ -318,81 +314,13 @@ function run() {
|
|||||||
const owner = core.getInput('owner') || github.context.repo.owner;
|
const owner = core.getInput('owner') || github.context.repo.owner;
|
||||||
const repo = core.getInput('repo') || github.context.repo.repo;
|
const repo = core.getInput('repo') || github.context.repo.repo;
|
||||||
// read in from, to tag inputs
|
// read in from, to tag inputs
|
||||||
let fromTag = core.getInput('fromTag');
|
const fromTag = core.getInput('fromTag');
|
||||||
let toTag = core.getInput('toTag');
|
const toTag = core.getInput('toTag');
|
||||||
// read in flags
|
// read in flags
|
||||||
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true';
|
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true';
|
||||||
const failOnError = core.getInput('failOnError') === 'true';
|
const failOnError = core.getInput('failOnError') === 'true';
|
||||||
// ensure to resolve the toTag if it was not provided
|
const result = yield new releaseNotesBuilder_1.ReleaseNotesBuilder(token, repositoryPath, owner, repo, fromTag, toTag, failOnError, ignorePreReleases, configuration).build();
|
||||||
if (!toTag) {
|
core.setOutput('changelog', result);
|
||||||
// if not specified try to retrieve tag from github.context.ref
|
|
||||||
if (github.context.ref.startsWith('refs/tags/')) {
|
|
||||||
toTag = github.context.ref.replace('refs/tags/', '');
|
|
||||||
core.info(`🔖 Resolved current tag (${toTag}) from the 'github.context.ref'`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// if not specified try to retrieve tag from git
|
|
||||||
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath);
|
|
||||||
const latestTag = yield gitHelper.latestTag();
|
|
||||||
toTag = latestTag;
|
|
||||||
core.info(`🔖 Resolved current tag (${toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!owner) {
|
|
||||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setOutput('owner', owner);
|
|
||||||
core.debug(`Resolved 'owner' as ${owner}`);
|
|
||||||
}
|
|
||||||
if (!repo) {
|
|
||||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setOutput('repo', repo);
|
|
||||||
core.debug(`Resolved 'repo' as ${repo}`);
|
|
||||||
}
|
|
||||||
if (!toTag) {
|
|
||||||
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, failOnError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setOutput('toTag', toTag);
|
|
||||||
core.debug(`Resolved 'toTag' as ${toTag}`);
|
|
||||||
}
|
|
||||||
core.endGroup();
|
|
||||||
// load octokit instance
|
|
||||||
const octokit = new rest_1.Octokit({
|
|
||||||
auth: `token ${token || process.env.GITHUB_TOKEN}`
|
|
||||||
});
|
|
||||||
// ensure to resolve the fromTag if it was not provided specifically
|
|
||||||
if (!fromTag) {
|
|
||||||
core.startGroup(`🔖 Resolve previous tag`);
|
|
||||||
core.debug(`fromTag undefined, trying to resolve via API`);
|
|
||||||
const tagsApi = new tags_1.Tags(octokit);
|
|
||||||
const previousTag = yield tagsApi.findPredecessorTag(owner, repo, toTag, ignorePreReleases, configuration.max_tags_to_fetch ||
|
|
||||||
configuration_1.DefaultConfiguration.max_tags_to_fetch);
|
|
||||||
if (previousTag == null) {
|
|
||||||
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${toTag}`, failOnError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fromTag = previousTag.name;
|
|
||||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`);
|
|
||||||
core.endGroup();
|
|
||||||
}
|
|
||||||
const releaseNotes = new releaseNotes_1.ReleaseNotes(octokit, {
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
fromTag,
|
|
||||||
toTag,
|
|
||||||
failOnError,
|
|
||||||
configuration
|
|
||||||
});
|
|
||||||
core.setOutput('changelog', (yield releaseNotes.pull()) ||
|
|
||||||
configuration.empty_template ||
|
|
||||||
configuration_1.DefaultConfiguration.empty_template);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
@@ -735,6 +663,141 @@ class ReleaseNotes {
|
|||||||
exports.ReleaseNotes = ReleaseNotes;
|
exports.ReleaseNotes = ReleaseNotes;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 4883:
|
||||||
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.ReleaseNotesBuilder = void 0;
|
||||||
|
const configuration_1 = __webpack_require__(5527);
|
||||||
|
const github = __importStar(__webpack_require__(5438));
|
||||||
|
const core = __importStar(__webpack_require__(2186));
|
||||||
|
const gitHelper_1 = __webpack_require__(353);
|
||||||
|
const utils_1 = __webpack_require__(918);
|
||||||
|
const rest_1 = __webpack_require__(5375);
|
||||||
|
const tags_1 = __webpack_require__(7532);
|
||||||
|
const releaseNotes_1 = __webpack_require__(5882);
|
||||||
|
class ReleaseNotesBuilder {
|
||||||
|
constructor(token, repositoryPath, owner, repo, fromTag, toTag, failOnError, ignorePreReleases, configuration) {
|
||||||
|
this.token = token;
|
||||||
|
this.repositoryPath = repositoryPath;
|
||||||
|
this.owner = owner;
|
||||||
|
this.repo = repo;
|
||||||
|
this.fromTag = fromTag;
|
||||||
|
this.toTag = toTag;
|
||||||
|
this.failOnError = failOnError;
|
||||||
|
this.ignorePreReleases = ignorePreReleases;
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
build() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// ensure to resolve the toTag if it was not provided
|
||||||
|
if (!this.toTag) {
|
||||||
|
// if not specified try to retrieve tag from github.context.ref
|
||||||
|
if (github.context.ref.startsWith('refs/tags/')) {
|
||||||
|
this.toTag = github.context.ref.replace('refs/tags/', '');
|
||||||
|
core.info(`🔖 Resolved current tag (${this.toTag}) from the 'github.context.ref'`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// if not specified try to retrieve tag from git
|
||||||
|
const gitHelper = yield gitHelper_1.createCommandManager(this.repositoryPath);
|
||||||
|
const latestTag = yield gitHelper.latestTag();
|
||||||
|
this.toTag = latestTag;
|
||||||
|
core.info(`🔖 Resolved current tag (${this.toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.owner) {
|
||||||
|
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput('owner', this.owner);
|
||||||
|
core.debug(`Resolved 'owner' as ${this.owner}`);
|
||||||
|
}
|
||||||
|
if (!this.repo) {
|
||||||
|
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput('repo', this.repo);
|
||||||
|
core.debug(`Resolved 'repo' as ${this.repo}`);
|
||||||
|
}
|
||||||
|
if (!this.toTag) {
|
||||||
|
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput('toTag', this.toTag);
|
||||||
|
core.debug(`Resolved 'toTag' as ${this.toTag}`);
|
||||||
|
}
|
||||||
|
core.endGroup();
|
||||||
|
// load octokit instance
|
||||||
|
const octokit = new rest_1.Octokit({
|
||||||
|
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||||
|
});
|
||||||
|
// ensure to resolve the fromTag if it was not provided specifically
|
||||||
|
if (!this.fromTag) {
|
||||||
|
core.startGroup(`🔖 Resolve previous tag`);
|
||||||
|
core.debug(`fromTag undefined, trying to resolve via API`);
|
||||||
|
const tagsApi = new tags_1.Tags(octokit);
|
||||||
|
const previousTag = yield tagsApi.findPredecessorTag(this.owner, this.repo, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
|
||||||
|
configuration_1.DefaultConfiguration.max_tags_to_fetch);
|
||||||
|
if (previousTag == null) {
|
||||||
|
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this.fromTag = previousTag.name;
|
||||||
|
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`);
|
||||||
|
core.endGroup();
|
||||||
|
}
|
||||||
|
const releaseNotes = new releaseNotes_1.ReleaseNotes(octokit, {
|
||||||
|
owner: this.owner,
|
||||||
|
repo: this.repo,
|
||||||
|
fromTag: this.fromTag,
|
||||||
|
toTag: this.toTag,
|
||||||
|
failOnError: this.failOnError,
|
||||||
|
configuration: this.configuration
|
||||||
|
});
|
||||||
|
return ((yield releaseNotes.pull()) ||
|
||||||
|
this.configuration.empty_template ||
|
||||||
|
configuration_1.DefaultConfiguration.empty_template);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.ReleaseNotesBuilder = ReleaseNotesBuilder;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 7532:
|
/***/ 7532:
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+10
-95
@@ -1,15 +1,7 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {
|
import {retrieveRepositoryPath, resolveConfiguration} from './utils'
|
||||||
failOrError,
|
|
||||||
retrieveRepositoryPath,
|
|
||||||
resolveConfiguration
|
|
||||||
} from './utils'
|
|
||||||
import {ReleaseNotes} from './releaseNotes'
|
|
||||||
import {createCommandManager} from './gitHelper'
|
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {DefaultConfiguration} from './configuration'
|
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
|
||||||
import {Octokit} from '@octokit/rest'
|
|
||||||
import {Tags} from './tags'
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
core.setOutput('failed', false) // mark the action not failed by default
|
core.setOutput('failed', false) // mark the action not failed by default
|
||||||
@@ -32,102 +24,25 @@ async function run(): Promise<void> {
|
|||||||
const owner = core.getInput('owner') || github.context.repo.owner
|
const owner = core.getInput('owner') || github.context.repo.owner
|
||||||
const repo = core.getInput('repo') || github.context.repo.repo
|
const repo = core.getInput('repo') || github.context.repo.repo
|
||||||
// read in from, to tag inputs
|
// read in from, to tag inputs
|
||||||
let fromTag = core.getInput('fromTag')
|
const fromTag = core.getInput('fromTag')
|
||||||
let toTag = core.getInput('toTag')
|
const toTag = core.getInput('toTag')
|
||||||
// read in flags
|
// read in flags
|
||||||
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true'
|
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true'
|
||||||
const failOnError = core.getInput('failOnError') === 'true'
|
const failOnError = core.getInput('failOnError') === 'true'
|
||||||
|
|
||||||
// ensure to resolve the toTag if it was not provided
|
const result = await new ReleaseNotesBuilder(
|
||||||
if (!toTag) {
|
token,
|
||||||
// if not specified try to retrieve tag from github.context.ref
|
repositoryPath,
|
||||||
if (github.context.ref.startsWith('refs/tags/')) {
|
|
||||||
toTag = github.context.ref.replace('refs/tags/', '')
|
|
||||||
core.info(
|
|
||||||
`🔖 Resolved current tag (${toTag}) from the 'github.context.ref'`
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// if not specified try to retrieve tag from git
|
|
||||||
const gitHelper = await createCommandManager(repositoryPath)
|
|
||||||
const latestTag = await gitHelper.latestTag()
|
|
||||||
toTag = latestTag
|
|
||||||
core.info(
|
|
||||||
`🔖 Resolved current tag (${toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!owner) {
|
|
||||||
failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
core.setOutput('owner', owner)
|
|
||||||
core.debug(`Resolved 'owner' as ${owner}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!repo) {
|
|
||||||
failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
core.setOutput('repo', repo)
|
|
||||||
core.debug(`Resolved 'repo' as ${repo}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!toTag) {
|
|
||||||
failOrError(`💥 Missing or couldn't resolve 'toTag'`, failOnError)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
core.setOutput('toTag', toTag)
|
|
||||||
core.debug(`Resolved 'toTag' as ${toTag}`)
|
|
||||||
}
|
|
||||||
core.endGroup()
|
|
||||||
|
|
||||||
// load octokit instance
|
|
||||||
const octokit = new Octokit({
|
|
||||||
auth: `token ${token || process.env.GITHUB_TOKEN}`
|
|
||||||
})
|
|
||||||
|
|
||||||
// ensure to resolve the fromTag if it was not provided specifically
|
|
||||||
if (!fromTag) {
|
|
||||||
core.startGroup(`🔖 Resolve previous tag`)
|
|
||||||
core.debug(`fromTag undefined, trying to resolve via API`)
|
|
||||||
const tagsApi = new Tags(octokit)
|
|
||||||
|
|
||||||
const previousTag = await tagsApi.findPredecessorTag(
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
toTag,
|
|
||||||
ignorePreReleases,
|
|
||||||
configuration.max_tags_to_fetch ||
|
|
||||||
DefaultConfiguration.max_tags_to_fetch
|
|
||||||
)
|
|
||||||
if (previousTag == null) {
|
|
||||||
failOrError(
|
|
||||||
`💥 Unable to retrieve previous tag given ${toTag}`,
|
|
||||||
failOnError
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fromTag = previousTag.name
|
|
||||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`)
|
|
||||||
core.endGroup()
|
|
||||||
}
|
|
||||||
|
|
||||||
const releaseNotes = new ReleaseNotes(octokit, {
|
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
fromTag,
|
fromTag,
|
||||||
toTag,
|
toTag,
|
||||||
failOnError,
|
failOnError,
|
||||||
|
ignorePreReleases,
|
||||||
configuration
|
configuration
|
||||||
})
|
).build()
|
||||||
|
|
||||||
core.setOutput(
|
core.setOutput('changelog', result)
|
||||||
'changelog',
|
|
||||||
(await releaseNotes.pull()) ||
|
|
||||||
configuration.empty_template ||
|
|
||||||
DefaultConfiguration.empty_template
|
|
||||||
)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import {Configuration, DefaultConfiguration} from './configuration'
|
||||||
|
import * as github from '@actions/github'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import {createCommandManager} from './gitHelper'
|
||||||
|
import {failOrError} from './utils'
|
||||||
|
import {Octokit} from '@octokit/rest'
|
||||||
|
import {Tags} from './tags'
|
||||||
|
import {ReleaseNotes} from './releaseNotes'
|
||||||
|
|
||||||
|
export class ReleaseNotesBuilder {
|
||||||
|
constructor(
|
||||||
|
private token: string | null,
|
||||||
|
private repositoryPath: string,
|
||||||
|
private owner: string | null,
|
||||||
|
private repo: string | null,
|
||||||
|
private fromTag: string | null,
|
||||||
|
private toTag: string | null,
|
||||||
|
private failOnError: boolean,
|
||||||
|
private ignorePreReleases: boolean,
|
||||||
|
private configuration: Configuration
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async build(): Promise<string | null> {
|
||||||
|
// ensure to resolve the toTag if it was not provided
|
||||||
|
if (!this.toTag) {
|
||||||
|
// if not specified try to retrieve tag from github.context.ref
|
||||||
|
if (github.context.ref.startsWith('refs/tags/')) {
|
||||||
|
this.toTag = github.context.ref.replace('refs/tags/', '')
|
||||||
|
core.info(
|
||||||
|
`🔖 Resolved current tag (${this.toTag}) from the 'github.context.ref'`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// if not specified try to retrieve tag from git
|
||||||
|
const gitHelper = await createCommandManager(this.repositoryPath)
|
||||||
|
const latestTag = await gitHelper.latestTag()
|
||||||
|
this.toTag = latestTag
|
||||||
|
core.info(
|
||||||
|
`🔖 Resolved current tag (${this.toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.owner) {
|
||||||
|
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
core.setOutput('owner', this.owner)
|
||||||
|
core.debug(`Resolved 'owner' as ${this.owner}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.repo) {
|
||||||
|
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
core.setOutput('repo', this.repo)
|
||||||
|
core.debug(`Resolved 'repo' as ${this.repo}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.toTag) {
|
||||||
|
failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError)
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
core.setOutput('toTag', this.toTag)
|
||||||
|
core.debug(`Resolved 'toTag' as ${this.toTag}`)
|
||||||
|
}
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
|
// load octokit instance
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: `token ${this.token || process.env.GITHUB_TOKEN}`
|
||||||
|
})
|
||||||
|
|
||||||
|
// ensure to resolve the fromTag if it was not provided specifically
|
||||||
|
if (!this.fromTag) {
|
||||||
|
core.startGroup(`🔖 Resolve previous tag`)
|
||||||
|
core.debug(`fromTag undefined, trying to resolve via API`)
|
||||||
|
const tagsApi = new Tags(octokit)
|
||||||
|
|
||||||
|
const previousTag = await tagsApi.findPredecessorTag(
|
||||||
|
this.owner,
|
||||||
|
this.repo,
|
||||||
|
this.toTag,
|
||||||
|
this.ignorePreReleases,
|
||||||
|
this.configuration.max_tags_to_fetch ||
|
||||||
|
DefaultConfiguration.max_tags_to_fetch
|
||||||
|
)
|
||||||
|
if (previousTag == null) {
|
||||||
|
failOrError(
|
||||||
|
`💥 Unable to retrieve previous tag given ${this.toTag}`,
|
||||||
|
this.failOnError
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
this.fromTag = previousTag.name
|
||||||
|
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`)
|
||||||
|
core.endGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
const releaseNotes = new ReleaseNotes(octokit, {
|
||||||
|
owner: this.owner,
|
||||||
|
repo: this.repo,
|
||||||
|
fromTag: this.fromTag,
|
||||||
|
toTag: this.toTag,
|
||||||
|
failOnError: this.failOnError,
|
||||||
|
configuration: this.configuration
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
(await releaseNotes.pull()) ||
|
||||||
|
this.configuration.empty_template ||
|
||||||
|
DefaultConfiguration.empty_template
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user