Skip to content

Commit

Permalink
release notes for next branch start from the first tag in next branch
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Apr 6, 2020
1 parent f022435 commit b9f9ee5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,9 @@ export default class Auto {
await this.setGitUser();

const lastRelease = await this.git.getLatestRelease();
const lastTag = await this.git.getLatestTagInBranch();
const lastTag = await this.git.getTagNotInBaseBranch(getCurrentBranch()!, {
first: true,
});
const commits = await this.release.getCommitsInRelease(lastTag);
const releaseNotes = await this.release.generateReleaseNotes(lastTag);
const labels = commits.map((commit) => commit.labels);
Expand All @@ -1198,8 +1200,9 @@ export default class Auto {

if (options.dryRun) {
this.logger.log.success(
`Would have created prerelease version with: ${bump}`
`Would have created prerelease version with: ${bump} from ${lastTag}`
);
this.logger.log.info(releaseNotes);

return { newVersion: "", commitsInRelease: commits, context: "next" };
}
Expand Down Expand Up @@ -1549,7 +1552,7 @@ export default class Auto {
const bump = await this.release.getSemverBump(lastRelease, to);
const releaseNotes = await this.release.generateReleaseNotes(
lastRelease,
to || undefined,
to,
this.versionBump
);

Expand Down
25 changes: 20 additions & 5 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ILabelDefinition } from "./release";
import verifyAuth from "./utils/verify-auth";
import execPromise from "./utils/exec-promise";
import { dummyLog, ILogger } from "./utils/logger";
import { gt } from "semver";
import { gt, lt } from "semver";
import { ICommit } from "./log-parse";
import { buildSearchQuery, ISearchResult } from "./match-sha-to-pr";

Expand Down Expand Up @@ -822,14 +822,21 @@ export default class Git {
.filter(Boolean);
}

/** Get the last tag that isn't in the base branch */
async getLastTagNotInBaseBranch(branch: string) {
/** Get the a tag that isn't in the base branch */
async getTagNotInBaseBranch(
branch: string,
options: {
/** Return the first tag not in baseBrach, defaults to last tag. */
first?: boolean;
} = {}
) {
const baseTags = (
await this.getTags(`origin/${this.options.baseBranch}`)
).reverse();
const branchTags = (await this.getTags(`heads/${branch}`)).reverse();
const comparator = options.first ? lt : gt;
const firstGreatestUnique = branchTags.reduce((result, tag) => {
if (!baseTags.includes(tag) && (!result || gt(tag, result))) {
if (!baseTags.includes(tag) && (!result || comparator(tag, result))) {
return tag;
}

Expand All @@ -838,11 +845,19 @@ export default class Git {

this.logger.verbose.info("Tags found in base branch:", baseTags);
this.logger.verbose.info("Tags found in branch:", branchTags);
this.logger.verbose.info("Latest tag in branch:", firstGreatestUnique);
this.logger.verbose.info(
`${options.first ? "First" : "Latest"} tag in branch:`,
firstGreatestUnique
);

return firstGreatestUnique;
}

/** Get the last tag that isn't in the base branch */
async getLastTagNotInBaseBranch(branch: string) {
return this.getTagNotInBaseBranch(branch);
}

/** Determine the pull request for a commit hash */
async matchCommitToPr(sha: string) {
const query = buildSearchQuery(this.options.owner, this.options.repo, [
Expand Down

0 comments on commit b9f9ee5

Please sign in to comment.