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
Merge with master
  • Loading branch information
amitayk committed May 23, 2023
commit 52122de8e67bf2dffe36ea36ab673894bcba74af
128 changes: 127 additions & 1 deletion out/cli.cjs
Original file line number Diff line number Diff line change
@@ -17680,6 +17680,14 @@ var configValidators = {
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
},
["OCO_PREFIX" /* OCO_PREFIX */](value) {
validateConfig(
"OCO_PREFIX" /* OCO_PREFIX */,
true,
"Cannot be empty"
);
return value;
}
};
var configPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
@@ -18518,6 +18526,11 @@ var getSpawnedResult = async ({ stdout, stderr, all: all3 }, { encoding, buffer,
]);
}
};
var validateInputSync = ({ input }) => {
if (isStream(input)) {
throw new TypeError("The `input` option cannot be a stream in sync mode");
}
};

// node_modules/execa/lib/promise.js
var nativePromisePrototype = (async () => {
@@ -18564,6 +18577,19 @@ var escapeArg = (arg) => {
};
var joinCommand = (file, args) => normalizeArgs(file, args).join(" ");
var getEscapedCommand = (file, args) => normalizeArgs(file, args).map((arg) => escapeArg(arg)).join(" ");
var SPACES_REGEXP = / +/g;
var parseCommand = (command2) => {
const tokens = [];
for (const token of command2.trim().split(SPACES_REGEXP)) {
const previousToken = tokens[tokens.length - 1];
if (previousToken && previousToken.endsWith("\\")) {
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
} else {
tokens.push(token);
}
}
return tokens;
};

// node_modules/execa/index.js
var DEFAULT_MAX_BUFFER = 1e3 * 1e3 * 100;
@@ -18683,6 +18709,65 @@ function execa(file, args, options) {
spawned.all = makeAllStream(spawned, parsed.options);
return mergePromise(spawned, handlePromiseOnce);
}
function execaSync(file, args, options) {
const parsed = handleArguments(file, args, options);
const command2 = joinCommand(file, args);
const escapedCommand = getEscapedCommand(file, args);
validateInputSync(parsed.options);
let result;
try {
result = import_node_child_process.default.spawnSync(parsed.file, parsed.args, parsed.options);
} catch (error) {
throw makeError({
error,
stdout: "",
stderr: "",
all: "",
command: command2,
escapedCommand,
parsed,
timedOut: false,
isCanceled: false,
killed: false
});
}
const stdout = handleOutput(parsed.options, result.stdout, result.error);
const stderr = handleOutput(parsed.options, result.stderr, result.error);
if (result.error || result.status !== 0 || result.signal !== null) {
const error = makeError({
stdout,
stderr,
error: result.error,
signal: result.signal,
exitCode: result.status,
command: command2,
escapedCommand,
parsed,
timedOut: result.error && result.error.code === "ETIMEDOUT",
isCanceled: false,
killed: result.signal !== null
});
if (!parsed.options.reject) {
return error;
}
throw error;
}
return {
command: command2,
escapedCommand,
exitCode: 0,
stdout,
stderr,
failed: false,
timedOut: false,
isCanceled: false,
killed: false
};
}
function execaCommandSync(command2, options) {
const [file, ...args] = parseCommand(command2);
return execaSync(file, args, options);
}

// src/utils/git.ts
var import_fs2 = require("fs");
@@ -21716,7 +21801,10 @@ var OpenAi = class {
try {
const { data } = await this.openAI.createChatCompletion(params);
const message = data.choices[0].message;
return message?.content;
const prefix = generatePrefix();
const usePrefix = prefix != void 0 && prefix?.trim() != "";
const finalMessage = (usePrefix ? prefix + " " : "") + (message?.content || "");
return finalMessage;
} catch (error) {
ce(`${source_default.red("\u2716")} ${JSON.stringify(params)}`);
const err = error;
@@ -21733,7 +21821,45 @@ var OpenAi = class {
}
};
};
function generatePrefix() {
const prefix = config2?.OCO_PREFIX;
if (prefix === void 0) {
return void 0;
}
const prefixIsRegexString = prefix.startsWith("/") && prefix.endsWith("/");
if (prefixIsRegexString) {
try {
return generatePrefixFromRegex(prefix);
} catch (error) {
console.error(`Failed to generate prefix from regex: ${error}`);
return void 0;
}
}
return prefix;
}
var api = new OpenAi();
function generatePrefixFromRegex(regex) {
const branch = getCurrentGitBranch();
if (branch === void 0) {
return void 0;
}
const regexWithoutSlashes = regex.slice(1, -1);
const regexObject = new RegExp(regexWithoutSlashes);
const match = branch.match(regexObject);
if (match === null) {
return void 0;
}
return match.length > 1 ? match[1] : match[0];
}
function getCurrentGitBranch() {
try {
const branchName = execaCommandSync("git symbolic-ref --short HEAD").stdout.trim();
return branchName;
} catch (error) {
console.error(`Failed to get current git branch: ${error}`);
return void 0;
}
}

// src/utils/tokenCount.ts
var import_lite = __toESM(require_tiktoken(), 1);
Loading
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.