Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --release-draft-only flag #594

Merged
merged 5 commits into from Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions source/git-util.js
Expand Up @@ -30,7 +30,7 @@ const firstCommit = async () => {
};

exports.previousTagOrFirstCommit = async () => {
const {stdout} = await execa('git', ['tag']);
const {stdout} = await execa('git', ['for-each-ref', '--sort=creatordate', '--format', '%(refname:strip=2)', 'refs/tags']);
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
const tags = stdout.split('\n');

if (tags.length === 0) {
Expand All @@ -41,7 +41,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);
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
return tags[index - 1];
} catch {
// Fallback to the first commit.
return firstCommit();
}
};

exports.latestTagOrFirstCommit = async () => {
Expand Down Expand Up @@ -77,6 +85,15 @@ exports.verifyCurrentBranchIsReleaseBranch = async releaseBranch => {
}
};

exports.isHeadDetached = async () => {
try {
await execa('git', ['symbolic-ref', '-q', 'HEAD']);
Drarig29 marked this conversation as resolved.
Show resolved Hide resolved
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) => {

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