Skip to content

Commit

Permalink
Add configLoz method to Git class
Browse files Browse the repository at this point in the history
Add configLoz method to Git class for configuring loz settings based on
name and value parameters. This method allows setting and retrieving
configuration values for loz.

Generated by gpt-3.5-turbo
  • Loading branch information
joone committed Mar 18, 2024
1 parent a23188e commit d73678a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
26 changes: 26 additions & 0 deletions src/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,30 @@ export class Git {
);
});
}

public configLoz(name: string, value?: string): Promise<string> {
return new Promise((resolve, reject) => {
const gitCommand =
value === undefined
? `git config loz.${name}`
: `git config loz.${name} ${value}`;

exec(
gitCommand,
(error: Error | null, stdout: string, stderr: string) => {
if (error) {
console.error(`Error: ${error.message}`);
reject(error.message);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
reject(stderr);
return;
}
resolve(stdout);
},
);
});
}
}
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ async function handleCodeDiffFromPipe(): Promise<void> {
return;
}

process.stdout.write(
completion.content + "\n\nGenerated by " + completion.model + "\n",
);
if (loz.attribution) {
process.stdout.write(
completion.content + "\n\nGenerated by " + completion.model + "\n",
);
}
});
}

Expand Down
24 changes: 21 additions & 3 deletions src/loz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Loz {
configPath: string;
config: Config = new Config();
git: Git = new Git();
attribution: boolean = false;

constructor() {
this.defaultSettings = {
Expand All @@ -60,6 +61,18 @@ export class Loz {
if (!fs.existsSync(LOG_DEV_PATH)) {
fs.mkdirSync(LOG_DEV_PATH);
}

const attributionValue = await this.git.configLoz("attribution");
if (attributionValue === "") {
this.git.configLoz("attribution", "false");
this.attribution = false;
} else {
if (attributionValue.trimEnd() === "true") {
this.attribution = true;
} else {
this.attribution = false;
}
}
}

await this.initLLMfromConfig();
Expand Down Expand Up @@ -149,9 +162,14 @@ export class Loz {
}

try {
await this.git.commit(
complete.content + "\n\nGenerated by " + complete.model,
);
if (this.attribution) {
await this.git.commit(
complete.content + "\n\nGenerated by " + complete.model,
);
} else {
await this.git.commit(complete.content);
}

const commitHEAD = await this.git.showHEAD();
console.log("\n# Generated commit message: \n");
console.log(commitHEAD);
Expand Down

0 comments on commit d73678a

Please sign in to comment.