Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Reese Schultz committed Mar 16, 2020
1 parent cbc29e9 commit e2af616
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/git.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
const execa = require('execa')
const error = require('./error')

const getChangelog = async () => {
const getLatestTag = async () => {
let latestTag
try {
latestTag = (await execa('git', ['describe', '--abbrev=0'])).stdout
} catch { }

if (latestTag) return (await execa('git', ['log', '--oneline', `${latestTag}..HEAD`])).stdout
return latestTag
}

const getCommitMessageFromId = async id =>
(await execa('git', ['log', '--format=%B', '-n', '1', id])).stdout

const getCommitFromMessage = async message =>
execa.sync('git', ['log', '--format=%H', `--grep=${message.replace('\n', '')}`]).stdout

const getChangelog = async from => {
if (from) return (await execa('git', ['log', '--oneline', `${from}..HEAD`])).stdout
return (await execa('git', ['log', '--pretty=oneline'])).stdout
}

Expand Down Expand Up @@ -114,6 +124,9 @@ const tag = async (name, message) => {
}

module.exports = {
getCommitMessageFromId,
getCommitFromMessage,
getLatestTag,
getChangelog,
forcePushUpstream,
checkout,
Expand Down
12 changes: 9 additions & 3 deletions src/inquiry.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const pushInquiry = async (bumpedProjectVersion, setUpstream, skipTagging, tagPr
const spinner = ora({ text: chalk.bold('Tagging.'), spinner: 'line' }).start()

let changelog = `Release ${tagPrefix}${bumpedProjectVersion}\n`
if (!skipTaggingChangelog) changelog += await git.getChangelog()
if (!skipTaggingChangelog) changelog += await git.getChangelog(await git.getLatestTag)

await git.tag(`${tagPrefix}${bumpedProjectVersion}`, changelog)
tagged = true
Expand Down Expand Up @@ -434,17 +434,23 @@ const subtreeSplitInquiry = async (bumpedPackages, skipTagging, tagPrefix, skipT
const spinner = ora({ text: chalk.bold(`Splitting ${bumpedPackage.name} with ${bumpedPackage.unfriendlyName} as the branch name.`), spinner: 'line' }).start()

await git.deleteBranch(bumpedPackage.unfriendlyName)

await git.subtreeSplit(bumpedPackage.unfriendlyName, bumpedPackage.dir.replace(`${process.cwd()}/`, ''))
await git.checkout(bumpedPackage.unfriendlyName)

await git.checkout(bumpedPackage.unfriendlyName)
const latestTagCommitMessage = await git.getCommitMessageFromId(await git.getLatestTag())
await git.checkout(originalBranch)
const latestTagCommit = await git.getCommitFromMessage(latestTagCommitMessage)
let changelog = `${bumpedPackage.name} Release ${bumpedPackage.unfriendlyName}/${tagPrefix}${bumpedPackage.version}\n`
if (!skipTaggingChangelog) changelog += await git.getChangelog()
if (!skipTaggingChangelog) changelog += await git.getChangelog(latestTagCommit)
await git.checkout(bumpedPackage.unfriendlyName)

if (!skipTagging) await git.tag(`${bumpedPackage.unfriendlyName}/${tagPrefix}${bumpedPackage.version}`, changelog)

await git.forcePushUpstream(bumpedPackage.unfriendlyName)

await git.checkout(originalBranch)

spinner.stop()
}
})
Expand Down

0 comments on commit e2af616

Please sign in to comment.