Skip to content

Commit

Permalink
Updates the UI to allow canceling running jobs, adds functions to acc…
Browse files Browse the repository at this point in the history
…ess package.json file and its version from the project directory, modifies the combineSummaries PromptTemplate to specify the first line limit, and updates error handling in the spawn function to provide more detailed information for troubleshooting.

- Refactors JobsList.tsx to use the new API
- Adds a new button to the UI
- Adds a new API endpoint to cancel jobs
- Updates handleCombine function in generate.ts to use the combined array
- Adds loadPackageJsonFromProject() and packageVersionFromProject() functions
- Allows accessing package.json file and its version from the project directory
- Specifies that the first line of the overall summary should not exceed 50 characters in combineSummaries PromptTemplate
- Adds example output to demonstrate expected format of combined summary
- Updates error handling in spawn function
- Logs specific error message received from command execution
- Provides more detailed information for troubleshooting
- Logs error message in stderr output for better error tracking and debugging
  • Loading branch information
sethwebster committed Aug 6, 2023
1 parent dd78135 commit 6e6235d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenerateStatusWithContext> {
Expand Down
15 changes: 14 additions & 1 deletion src/lib/packageJson.ts
Original file line number Diff line number Diff line change
@@ -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`);
Expand All @@ -12,7 +18,14 @@ function packageVersion() {
return packageJson.version;
}

function packageVersionFromProject() {
const packageJson = loadPackageJsonFromProject();
return packageJson.version;
}

export default {
loadPackageJson,
packageVersion
loadPackageJsonFromProject,
packageVersion,
packageVersionFromProject
};
10 changes: 9 additions & 1 deletion src/lib/promptTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
29 changes: 23 additions & 6 deletions src/lib/releaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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({
Expand Down Expand Up @@ -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();
Expand All @@ -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'])}`
);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6e6235d

Please sign in to comment.