Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/commands/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@ module.exports = async function (args) {
releaseBuilder.setCurrentVersion(pkg.version)
logger.debug('Found %s version: %s', releaseBuilder.getName(), releaseBuilder.getCurrentVersion())

let { toCommit } = args
let { toCommit, fromCommit } = args
if (!args.toCommit) {
const tagPattern = args.tag || `v${releaseBuilder.getCurrentVersionInfo().major}\\.[0-9]*\\.[0-9]*`
logger.debug('Searching for tag pattern %s', tagPattern)

toCommit = await git.getLastTagCommit(tagPattern)
if (!toCommit) { toCommit = 'HEAD' }
if (!toCommit) {
toCommit = 'HEAD'
if (fromCommit === 'HEAD') {
fromCommit = undefined
}
}
}

const commits = await git.getLogs(args.fromCommit, toCommit)
logger.debug('Found %d commits from %s to %s', commits.length, args.fromCommit, toCommit)
const commits = await git.getLogs(fromCommit, toCommit)
logger.debug('Found %d commits from %s to %s', commits.length, fromCommit, toCommit)

const commitsPR = commits.map(addPullRequestId)

Expand Down
12 changes: 7 additions & 5 deletions lib/git-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ module.exports = function gitDirectory (path) {
* Execute the command:
* git log --pretty=oneline HEAD...`git tag --format='%(objectname)' --sort=-version:refname -l v1* | head -n1`
*
* @param {string} fromCommit
* @param {string|undefined} fromCommit
* @param {string} toCommit
* @return {Array<ListLogLine>} commits
*/
async function getLogs (fromCommit, toCommit) {
const logs = await gitLog({
from: fromCommit,
to: toCommit
})
const options = {}
if (fromCommit) {
options.from = fromCommit
options.to = toCommit
}
const logs = await gitLog(options)
return logs.all
}

Expand Down
50 changes: 50 additions & 0 deletions test/command-draft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,56 @@ test('draft the first release', async t => {
t.assert.deepStrictEqual(build.oldVersion, '11.14.42')
})

test('draft the first release includes all commits when no tags exist', async t => {
t.plan(4)

const { execFileSync } = require('node:child_process')
const { mkdtempSync, rmSync, writeFileSync } = require('node:fs')
const { tmpdir } = require('node:os')
const realCmd = require('../lib/commands/draft')
const projectPath = mkdtempSync(join(tmpdir(), 'releasify-first-release-'))
const packagePath = join(projectPath, 'package.json')
const runGit = args => execFileSync('git', args, { cwd: projectPath })

t.after(() => rmSync(projectPath, { recursive: true, force: true }))
runGit(['init', '--quiet'])
runGit(['config', 'user.name', 'Test User'])
runGit(['config', 'user.email', 'test@example.com'])
runGit(['config', 'commit.gpgsign', 'false'])

writeFileSync(packagePath, JSON.stringify({
name: 'first-release',
version: '1.0.0',
repository: { url: 'https://github.com/example/first-release' }
}))
runGit(['add', 'package.json'])
runGit(['commit', '--quiet', '-m', 'initial commit'])

writeFileSync(packagePath, JSON.stringify({
name: 'first-release',
version: '1.0.0',
description: 'Second commit',
repository: { url: 'https://github.com/example/first-release' }
}))
runGit(['add', 'package.json'])
runGit(['commit', '--quiet', '-m', 'second commit'])

const build = await realCmd({
path: projectPath,
tag: 'no-matching-tags',
verbose: 'error',
fromCommit: 'HEAD',
semver: 'patch',
ghGroupByLabel: [],
ghReleaseBody: false
})

t.assert.equal(build.lines, 2)
t.assert.equal(build.version, '1.0.1')
t.assert.match(build.message, /initial commit/)
t.assert.match(build.message, /second commit/)
})

test('error management getting PR: works but won\' apply labels', async t => {
t.plan(3)

Expand Down