Skip to content

Commit b99178c

Browse files
committed
fix: improve tag detection
1 parent 59f2bf8 commit b99178c

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const args = minimist(process.argv.slice(2), {
66
boolean: [
77
'draft',
88
'prerelease',
9+
'dry',
910
],
1011
string: [
1112
'token',

src/git.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ export async function getGitHubRepo() {
99
return `${match[1]}/${match[2]}`
1010
}
1111

12+
export async function getCurrentGitBranch() {
13+
return await execCommand('git', ['tag', '--points-at', 'HEAD']) || await execCommand('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
14+
}
15+
16+
async function execCommand(cmd: string, args: string[]) {
17+
const { execa } = await import('execa')
18+
const res = await execa(cmd, args)
19+
return res.stdout
20+
}
21+

src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* eslint-disable no-console */
12
import { fetch } from 'ohmyfetch'
2-
import { getCurrentGitBranch, getGitDiff, getLastGitTag, parseCommits } from 'changelogen'
3+
import { getGitDiff, getLastGitTag, parseCommits } from 'changelogen'
34
import semver from 'semver'
45
import type { ChangelogOptions } from './types'
5-
import { getGitHubRepo } from './git'
6+
import { getCurrentGitBranch, getGitHubRepo } from './git'
67
import { generateMarkdown } from './markdown'
78

89
export default async function changelogithub(
@@ -24,9 +25,20 @@ export default async function changelogithub(
2425

2526
const rawCommits = await getGitDiff(config.from, config.to)
2627
const commits = parseCommits(rawCommits, config)
27-
const md = generateMarkdown(commits, config)
28+
const filtered = commits.filter(c => config.types[c.type])
2829

29-
await sendRelease(config, md)
30+
if (!commits.length) {
31+
console.log('No commits')
32+
process.exitCode = 1
33+
return
34+
}
35+
36+
const md = generateMarkdown(filtered, config)
37+
38+
if (config.dry)
39+
console.log(md)
40+
else
41+
await sendRelease(config, md)
3042
}
3143

3244
async function sendRelease(

src/markdown.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export function generateMarkdown(commits: GitCommit[], config: ChangelogenOption
3838

3939
const url = `https://github.com/${config.github}/compare/${config.from}...${config.to}`
4040

41-
markdown += '\n\n----\n\n'
42-
markdown += `[Changes on GitHub](${url})\n`
41+
markdown += `\n\n> [Changes on GitHub](${url})\n`
4342

4443
return markdown.trim()
4544
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ChangelogenOptions {
1919
export interface ChangelogOptions extends ChangelogenOptions {
2020
draft?: boolean
2121
prerelease?: boolean
22+
dry?: boolean
2223
name?: string
2324
token: string
2425
}

0 commit comments

Comments
 (0)