- if only a single tag is available resolve the initial commit as fallback. this is meant to support initial release scenarios

- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/276
This commit is contained in:
Mike Penz
2021-07-05 08:57:37 +02:00
parent 080a1286ce
commit 762538b445
5 changed files with 71 additions and 30 deletions
Generated Vendored
+34 -16
View File
@@ -250,6 +250,16 @@ class GitCommandManager {
return output.stdout.trim();
});
}
initialCommit() {
return __awaiter(this, void 0, void 0, function* () {
const revListOutput = yield this.execGit([
'rev-list',
'--max-parents=0',
'HEAD'
]);
return revListOutput.stdout.trim();
});
}
static createCommandManager(workingDirectory) {
return __awaiter(this, void 0, void 0, function* () {
const result = new GitCommandManager();
@@ -812,7 +822,7 @@ class ReleaseNotesBuilder {
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 ||
const previousTag = yield tagsApi.findPredecessorTag(this.repositoryPath, this.owner, this.repo, this.toTag, this.ignorePreReleases, this.configuration.max_tags_to_fetch ||
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
if (previousTag == null) {
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
@@ -888,6 +898,7 @@ exports.sortTags = exports.Tags = void 0;
const core = __importStar(__nccwpck_require__(2186));
const semver = __importStar(__nccwpck_require__(1383));
const semver_1 = __nccwpck_require__(1383);
const gitHelper_1 = __nccwpck_require__(353);
class Tags {
constructor(octokit) {
this.octokit = octokit;
@@ -929,31 +940,38 @@ class Tags {
return tagsInfo;
});
}
findPredecessorTag(owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) {
findPredecessorTag(repositoryPath, owner, repo, tag, ignorePreReleases, maxTagsToFetch, tagResolver) {
return __awaiter(this, void 0, void 0, function* () {
const tags = sortTags(yield this.getTags(owner, repo, maxTagsToFetch), tagResolver);
try {
const length = tags.length;
for (let i = 0; i < length; i++) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
if (ignorePreReleases) {
core.info(`️ Enabled 'ignorePreReleases', searching for the closest release`);
for (let ii = i + 1; ii < length; ii++) {
if (!tags[ii].name.includes('-')) {
return tags[ii];
if (tags.length > 1) {
for (let i = 0; i < length; i++) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
if (ignorePreReleases) {
core.info(`️ Enabled 'ignorePreReleases', searching for the closest release`);
for (let ii = i + 1; ii < length; ii++) {
if (!tags[ii].name.includes('-')) {
return tags[ii];
}
}
}
return tags[i + 1];
}
return tags[i + 1];
}
}
else {
core.info(`️ Only one tag found for the given repository. Usually this is the case for the initial release.`);
// if not specified try to retrieve tag from git
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath);
const initialCommit = yield gitHelper.initialCommit();
core.info(`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`);
return { name: 'initial', commit: initialCommit };
}
return tags[0];
}
catch (error) {
if (tags.length < 1) {
core.warning(`⚠️ Only one tag found for the given repository`);
}
else if (tags.length < 0) {
if (tags.length <= 0) {
core.warning(`⚠️ No tag found for the given repository`);
}
return null;
@@ -6142,7 +6160,7 @@ const Endpoints = {
}
};
const VERSION = "5.3.1";
const VERSION = "5.3.7";
function endpointsToMethods(octokit, endpointsMap) {
const newMethods = {};
@@ -6527,7 +6545,7 @@ var pluginRequestLog = __nccwpck_require__(8883);
var pluginPaginateRest = __nccwpck_require__(4193);
var pluginRestEndpointMethods = __nccwpck_require__(3044);
const VERSION = "18.6.0";
const VERSION = "18.6.6";
const Octokit = core.Octokit.plugin(pluginRequestLog.requestLog, pluginRestEndpointMethods.legacyRestEndpointMethods, pluginPaginateRest.paginateRest).defaults({
userAgent: `octokit-rest.js/${VERSION}`
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+9
View File
@@ -35,6 +35,15 @@ class GitCommandManager {
return output.stdout.trim()
}
async initialCommit(): Promise<string> {
const revListOutput = await this.execGit([
'rev-list',
'--max-parents=0',
'HEAD'
])
return revListOutput.stdout.trim()
}
static async createCommandManager(
workingDirectory: string
): Promise<GitCommandManager> {
+1
View File
@@ -79,6 +79,7 @@ export class ReleaseNotesBuilder {
const tagsApi = new Tags(octokit)
const previousTag = await tagsApi.findPredecessorTag(
this.repositoryPath,
this.owner,
this.repo,
this.toTag,
+26 -13
View File
@@ -3,6 +3,7 @@ import * as core from '@actions/core'
import * as semver from 'semver'
import {SemVer} from 'semver'
import {TagResolver} from './configuration'
import {createCommandManager} from './gitHelper'
export interface TagInfo {
name: string
@@ -50,6 +51,7 @@ export class Tags {
}
async findPredecessorTag(
repositoryPath: string,
owner: string,
repo: string,
tag: string,
@@ -64,26 +66,37 @@ export class Tags {
try {
const length = tags.length
for (let i = 0; i < length; i++) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
if (ignorePreReleases) {
core.info(
`️ Enabled 'ignorePreReleases', searching for the closest release`
)
for (let ii = i + 1; ii < length; ii++) {
if (!tags[ii].name.includes('-')) {
return tags[ii]
if (tags.length > 1) {
for (let i = 0; i < length; i++) {
if (tags[i].name.toLocaleLowerCase() === tag.toLocaleLowerCase()) {
if (ignorePreReleases) {
core.info(
`️ Enabled 'ignorePreReleases', searching for the closest release`
)
for (let ii = i + 1; ii < length; ii++) {
if (!tags[ii].name.includes('-')) {
return tags[ii]
}
}
}
return tags[i + 1]
}
return tags[i + 1]
}
} else {
core.info(
`️ Only one tag found for the given repository. Usually this is the case for the initial release.`
)
// if not specified try to retrieve tag from git
const gitHelper = await createCommandManager(repositoryPath)
const initialCommit = await gitHelper.initialCommit()
core.info(
`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`
)
return {name: 'initial', commit: initialCommit}
}
return tags[0]
} catch (error) {
if (tags.length < 1) {
core.warning(`⚠️ Only one tag found for the given repository`)
} else if (tags.length < 0) {
if (tags.length <= 0) {
core.warning(`⚠️ No tag found for the given repository`)
}
return null