forked from slopus/happy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.release-it.notes.js
More file actions
executable file
·109 lines (90 loc) · 2.99 KB
/
.release-it.notes.js
File metadata and controls
executable file
·109 lines (90 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
import { execFileSync, execSync } from "child_process";
/**
* Generate release notes using Claude Code by analyzing git commits
* Usage: node .release-it.notes.js <to-version>
*/
/**
* @returns {string | null}
*/
function getLatestStableTag() {
const tagsRaw = execSync(`git tag --list "v*" --sort=-v:refname`, {
encoding: "utf8",
});
const tags = tagsRaw
.split("\n")
.map((t) => t.trim())
.filter((t) => t.length > 0);
// Only accept stable semver tags like v1.2.3 (no hyphen prerelease suffix).
const stableTag = tags.find((t) => /^v\d+\.\d+\.\d+$/.test(t));
return stableTag ?? null;
}
const [, , toVersion] = process.argv;
if (!toVersion) {
console.error("Usage: node .release-it.notes.js <to-version>");
process.exit(1);
}
async function generateReleaseNotes() {
try {
const fromTag = getLatestStableTag();
// Get commit range for the release
const commitRange = fromTag ? `${fromTag}..HEAD` : "--all";
// Get git log for the commits
let gitLog;
try {
gitLog = execSync(
`git log ${commitRange} --pretty=format:"%h - %s (%an, %ar)" --no-merges`,
{ encoding: "utf8" }
);
} catch (error) {
// Fallback to recent commits if tag doesn't exist
console.error(
`Tag ${fromTag ?? "(none)"} not found, using recent commits instead`
);
gitLog = execSync(
`git log -10 --pretty=format:"%h - %s (%an, %ar)" --no-merges`,
{ encoding: "utf8" }
);
}
if (!gitLog.trim()) {
console.error("No commits found for release notes generation");
process.exit(1);
}
// Create a prompt for Claude to analyze commits and generate release notes
const prompt = `Please analyze these git commits and generate professional release notes for version ${toVersion} of the Happy CLI tool (a Claude Code session sharing CLI).
The release should cover commits since the latest stable tag (vX.Y.Z): ${
fromTag ?? "(none)"
}.
Git commits:
${gitLog}
Please format the output as markdown with:
- A brief summary of the release
- Organized sections for:
- 🚀 New Features
- 🐛 Bug Fixes
- ♻️ Refactoring
- 🔧 Other Changes
- Use bullet points for each change
- Keep descriptions concise but informative
- Focus on user-facing changes
- New line after each section
Do not include any preamble or explanations, just return the markdown release notes.`;
// Call Claude Code to generate release notes
console.error("Generating release notes with Claude Code...");
const releaseNotes = execFileSync(
"claude",
["--add-dir", ".", "--print", prompt],
{
encoding: "utf8",
stdio: ["pipe", "pipe", "inherit"],
maxBuffer: 1024 * 1024 * 10, // 10MB buffer
}
);
// Output release notes to stdout for release-it to use
console.log(releaseNotes.trim());
} catch (error) {
console.error("Error generating release notes:", error.message);
process.exit(1);
}
}
generateReleaseNotes();