Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for commit prefix #160

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(api.ts): replace child_process.execSync with execaCommandSyn…
…c to improve security and reliability

refactor(api.ts): simplify prefix generation logic by checking if prefix is defined and not empty before using it
fix(api.ts): fix conditional statement in generatePrefixFromRegex to return undefined when no match is found
fix(api.ts): catch error in getCurrentGitBranch and log it to console instead of throwing it
  • Loading branch information
amitayk committed May 7, 2023
commit 4f6e95a572b171f73d83a7f95842dd25a18e5d30
7 changes: 4 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { intro, outro } from '@clack/prompts';
import { execSync } from 'child_process';
import axios from 'axios';
import chalk from 'chalk';
import {
@@ -9,6 +8,7 @@ import {
} from 'openai';

import { CONFIG_MODES, getConfig } from './commands/config';
import { execaCommandSync } from 'execa';

const config = getConfig();

@@ -61,8 +61,9 @@ class OpenAi {
const message = data.choices[0].message;

const prefix = generatePrefix();
const usePrefix = prefix != undefined && prefix?.trim() != ""

const finalMessage = (prefix != "undefined" ? prefix + ' ' : '') + (message?.content || '')
const finalMessage = (usePrefix ? prefix + ' ' : '') + (message?.content || '')

return finalMessage;
} catch (error: unknown) {
@@ -146,7 +147,7 @@ function generatePrefixFromRegex(regex: string): string | undefined {

function getCurrentGitBranch(): string | undefined {
try {
const branchName = execSync('git symbolic-ref --short HEAD', { encoding: 'utf8' }).trim();
const branchName = execaCommandSync('git symbolic-ref --short HEAD').stdout.trim()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to add the full branch name in the commit like: #234-some-branch-name commit message text goes here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it will take a regex out of the name. See my first commit on this PR.
Very cool to hear about the hackathon!

return branchName;
} catch (error) {
console.error(`Failed to get current git branch: ${error}`);