Skip to content

Commit

Permalink
Fix --release-draft-only flag (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drarig29 committed Feb 7, 2021
1 parent 2b9a02b commit add5bd9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
29 changes: 26 additions & 3 deletions source/git-util.js
Expand Up @@ -34,8 +34,7 @@ const firstCommit = async () => {
};

exports.previousTagOrFirstCommit = async () => {
const {stdout} = await execa('git', ['tag']);
const tags = stdout.split('\n');
const tags = await exports.tagList();

if (tags.length === 0) {
return;
Expand All @@ -45,7 +44,15 @@ exports.previousTagOrFirstCommit = async () => {
return firstCommit();
}

return tags[tags.length - 2];
try {
// Return the tag before the latest one.
const latest = await exports.latestTag();
const index = tags.indexOf(latest);
return tags[index - 1];
} catch {
// Fallback to the first commit.
return firstCommit();
}
};

exports.latestTagOrFirstCommit = async () => {
Expand Down Expand Up @@ -80,6 +87,22 @@ exports.verifyCurrentBranchIsReleaseBranch = async releaseBranch => {
}
};

exports.tagList = async () => {
// Returns the list of tags, sorted by creation date in ascending order.
const {stdout} = await execa('git', ['tag', '--sort=creatordate']);
return stdout.split('\n');
};

exports.isHeadDetached = async () => {
try {
// Command will fail with code 1 if the HEAD is detached.
await execa('git', ['symbolic-ref', '--quiet', 'HEAD']);
return false;
} catch {
return true;
}
};

exports.isWorkingTreeClean = async () => {
try {
const {stdout: status} = await execa('git', ['status', '--porcelain']);
Expand Down
8 changes: 7 additions & 1 deletion source/ui.js
Expand Up @@ -41,14 +41,20 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag, releaseBranch

if (!fromLatestTag) {
const latestTag = await git.latestTag();
const versionBumpCommitName = latestTag.slice(1); // Name v1.0.1 becomes 1.0.1

// Version bump commit created by np, following the semver specification.
const versionBumpCommitName = latestTag.match(/v\d+\.\d+\.\d+/) && latestTag.slice(1); // Name v1.0.1 becomes 1.0.1
const versionBumpCommitIndex = commits.findIndex(commit => commit.message === versionBumpCommitName);

if (versionBumpCommitIndex > 0) {
commitRangeText = `${revision}...${latestTag}`;
hasUnreleasedCommits = true;
}

if (await git.isHeadDetached()) {
commitRangeText = `${revision}...${latestTag}`;
}

// Get rid of unreleased commits and of the version bump commit.
commits = commits.slice(versionBumpCommitIndex + 1);
}
Expand Down

0 comments on commit add5bd9

Please sign in to comment.