diff --git a/src/lib/generate.ts b/src/lib/generate.ts index 533b40f..00f3eed 100644 --- a/src/lib/generate.ts +++ b/src/lib/generate.ts @@ -131,7 +131,7 @@ async function handleCombine(context: GenerateStatusWithContext, options: Genera const combined = numbers.map(n => commitMessages[n - 1]); const resummarized = await combineSummaries({ openAIApiKey, summaries: combined, maxLength: length }); console.log(MessagesForCurrentLanguage.messages["summaries-combined-confirmation"] + "\n", resummarized); - return await getUserResponseToMessages({ status: "continue", diffs, summaries: [resummarized], commitMessages: [resummarized], openAIApiKey }, options); + return await getUserResponseToMessages({ status: "continue", diffs, summaries: combined, commitMessages: [resummarized], openAIApiKey }, options); } async function handleDefaultCase(answer: string, context: GenerateStatusWithContext, options: GenerateOptions): Promise { diff --git a/src/lib/packageJson.ts b/src/lib/packageJson.ts index 2d465fe..dbde607 100644 --- a/src/lib/packageJson.ts +++ b/src/lib/packageJson.ts @@ -1,6 +1,12 @@ import fs from 'fs'; import * as url from 'url'; +function loadPackageJsonFromProject() { + const __dirname = process.env.PWD; + const packageJson = fs.readFileSync(`${__dirname}/package.json`); + return JSON.parse(packageJson.toString()); +} + function loadPackageJson() { const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); const packageJson = fs.readFileSync(`${__dirname}../../package.json`); @@ -12,7 +18,14 @@ function packageVersion() { return packageJson.version; } +function packageVersionFromProject() { + const packageJson = loadPackageJsonFromProject(); + return packageJson.version; +} + export default { loadPackageJson, - packageVersion + loadPackageJsonFromProject, + packageVersion, + packageVersionFromProject }; \ No newline at end of file diff --git a/src/lib/promptTemplates.ts b/src/lib/promptTemplates.ts index a8ab282..8604d08 100644 --- a/src/lib/promptTemplates.ts +++ b/src/lib/promptTemplates.ts @@ -3,8 +3,16 @@ import { PromptTemplate } from "langchain/prompts"; const combineSummaries = new PromptTemplate({ inputVariables: ["summaries"], template: `Combine the following summaries into a single summary. - It should have a first line (no more than 100 chars) overall summary followed by bullets that expand on the summary. + It should have a first line (no more than 50 chars) overall summary followed by bullets that expand on the summary. + Example Output: + Makes a change to the UI allowing the user to cancel running jobs + - refactored JobsList.tsx to use the new API + - added a new button to the UI + - added a new API endpoint to cancel jobs + - something else in the diffs + - etc. + Do not remove any important information: -- summaries -- {summaries} diff --git a/src/lib/releaseNotes.ts b/src/lib/releaseNotes.ts index 733d3ef..edad22f 100644 --- a/src/lib/releaseNotes.ts +++ b/src/lib/releaseNotes.ts @@ -14,6 +14,7 @@ import chalk from "chalk"; import { input, select } from "@inquirer/prompts"; import { exec } from "./spawn.js"; import { fetchLatestNpmVersion } from "./environment.js"; +import Logger from "./logger.js"; var chalkAnimation: { rainbow: (text: string) => Animation; }; (async function () { @@ -28,7 +29,9 @@ export async function createReleaseNotes({ verbose }: { verbose?: boolean } = { return; } var { baseCompare, latest } = await resolveComparisonVersions(); - const diffs = await git.diff({ baseCompare, compare: "HEAD" }); + Logger.log(`Generating release notes between ${chalk.yellow(baseCompare)} and ${chalk.yellow(latest)}...`) + + const diffs = await git.diff({ baseCompare, compare: latest }); const summaries = await summarizeDiffs({ openAIApiKey: config.openAIApiKey, diffs, verbose }); const rainbow = chalkAnimation.rainbow(MessagesForCurrentLanguage.messages['ava-is-working']); const model = new OpenAIChat({ @@ -60,11 +63,26 @@ export async function createReleaseNotes({ verbose }: { verbose?: boolean } = { } async function resolveComparisonVersions() { - const latest = await getLatestTaggedGitVersion(); + let latest = await getLatestTaggedGitVersion(); if (latest) await resolveLocalPackageUpdate(latest); - const localPackageVersion = packageJson.packageVersion(); + if (!latest) { + latest = "HEAD"; + } + let localPackageVersion = packageJson.packageVersionFromProject(); + if (!localPackageVersion) { + localPackageVersion = "HEAD"; + } + + switch (true) { + case latest === "HEAD" && localPackageVersion === "HEAD": + console.log(`No versions to compare could be found. This is likely because you haven't set a package.json version. `) + process.exit(1); + break; + // More to come here + } + let baseCompare = latest; - if (compareVersions(localPackageVersion, latest!) === 0) { + if (latest !== "HEAD" && compareVersions(localPackageVersion, latest!) === 0) { // Versions are equal so we should use the previous version for the head // comparison const npmVersion = await fetchLatestNpmVersion(); @@ -86,12 +104,11 @@ async function resolveLocalPackageUpdate(latest: string) { const npmVersion = await fetchLatestNpmVersion(); // If the version on npm is less than the local or remote tagged version, // there is no reason to update so lets return - console.log(`NPM +++ ${npmVersion} Local +++ ${localPackageVersion} Remote +++ ${latest} ${compareVersions(npmVersion, localPackageVersion)}`); + console.log(`+++ NPM ${npmVersion} +++ Local ${localPackageVersion} +++ Remote ${latest}`); if (compareVersions(npmVersion, localPackageVersion) > 0) { return; } - console.log(`Remote +++ ${latest} Local +++ ${localPackageVersion}`); console.warn( `⚠️ ${chalk.yellow(MessagesForCurrentLanguage.messages['update-package-version'])}` ); diff --git a/src/lib/spawn.ts b/src/lib/spawn.ts index 813a184..6515d2e 100644 --- a/src/lib/spawn.ts +++ b/src/lib/spawn.ts @@ -8,12 +8,14 @@ export function spawn(command: string, args: string[]) { throw result.error; } if (result.status !== 0) { + console.log("Non-zero exit code from git:", result.stderr.toString()); throw new Error(`Command exited with status ${result.status}`); } if (result.signal !== null) { throw new Error(`Command exited with signal ${result.signal}`); } if (result.stderr && result.stderr.length > 0) { + console.log("[error]", result.stderr.toString()); throw new Error(result.stderr.toString()); } if (result.stdout && result.stdout.length > 0) {