generated from ztimson/template
Added checks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
import {Ai} from '@ztimson/ai';
|
||||
import * as dotenv from 'dotenv';
|
||||
import {$} from '@ztimson/node-utils';
|
||||
|
||||
dotenv.config({quiet: true, debug: false});
|
||||
dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
||||
@@ -32,6 +33,10 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
||||
|
||||
// Get latest tag
|
||||
const latestTag = await $`git describe --tags --abbrev=0`.text();
|
||||
if(!latestTag) {
|
||||
console.error('At least one Git tag is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Build context
|
||||
let context = `Milestone: ${milestoneData.title}
|
||||
@@ -57,7 +62,11 @@ ${issues.filter(i => !i.pull_request).map(i => `- ${i.title}\n${i.body || ''}`).
|
||||
system: `You are a release notes writer. Format the provided milestone info, PRs, and issues into clean, organized release notes. Use markdown with sections like "Features", "Bug Fixes", "Breaking Changes", etc. Be concise but informative. Include issue/PR numbers in format #123.`
|
||||
});
|
||||
|
||||
const body = (await ai.chat(context)).pop().content;
|
||||
const body = (await ai.chat(context)).pop()?.content;
|
||||
if(!body) {
|
||||
console.error('No release notes were generated');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create release
|
||||
const name = latestTag.trim();
|
||||
@@ -72,7 +81,7 @@ ${issues.filter(i => !i.pull_request).map(i => `- ${i.title}\n${i.body || ''}`).
|
||||
tag_name: name,
|
||||
body
|
||||
})
|
||||
}).then(resp => resp.ok ? console.log('Release created! 🎉') : console.error('Failed to create release'));
|
||||
}).then(resp => { if(!resp.ok) throw new Error(resp.status + ' ' + resp.statusText) });
|
||||
|
||||
console.log(`Title: ${name}\nDescription:\n${body}`);
|
||||
})().catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user