(extraArgs2 = [], context = "", isStageAllFlag = false, fullGitMojiSpec = false, skipCommitConfirmation = false)
| 85925 | const provider = errorConfig.OCO_AI_PROVIDER || "openai"; |
| 85926 | const formatted = formatUserFriendlyError(error, provider, { |
| 85927 | baseURL: errorConfig.OCO_API_URL |
| 85928 | }); |
| 85929 | ce(printFormattedError(formatted)); |
| 85930 | process.exit(1); |
| 85931 | } |
| 85932 | }; |
| 85933 | async function commit(extraArgs2 = [], context = "", isStageAllFlag = false, fullGitMojiSpec = false, skipCommitConfirmation = false) { |
| 85934 | if (isStageAllFlag) { |
| 85935 | const changedFiles2 = await getChangedFiles(); |
| 85936 | if (changedFiles2) await gitAdd({ files: changedFiles2 }); |
| 85937 | else { |
| 85938 | ce("No changes detected, write some code and run `oco` again"); |
| 85939 | process.exit(1); |
| 85940 | } |
| 85941 | } |
| 85942 | const [stagedFiles, errorStagedFiles] = await trytm(getStagedFiles()); |
| 85943 | const [changedFiles, errorChangedFiles] = await trytm(getChangedFiles()); |
| 85944 | if (!changedFiles?.length && !stagedFiles?.length) { |
| 85945 | ce(source_default.red("No changes detected")); |
| 85946 | process.exit(1); |
| 85947 | } |
| 85948 | ae("open-commit"); |
| 85949 | if (errorChangedFiles ?? errorStagedFiles) { |
| 85950 | ce(`${source_default.red("\u2716")} ${errorChangedFiles ?? errorStagedFiles}`); |
| 85951 | process.exit(1); |
| 85952 | } |
| 85953 | const stagedFilesSpinner = le(); |
| 85954 | stagedFilesSpinner.start("Counting staged files"); |
| 85955 | if (stagedFiles.length === 0) { |
| 85956 | stagedFilesSpinner.stop("No files are staged"); |
| 85957 | const isStageAllAndCommitConfirmedByUser = await Q3({ |
| 85958 | message: "Do you want to stage all files and generate commit message?" |
| 85959 | }); |
| 85960 | if (hD2(isStageAllAndCommitConfirmedByUser)) process.exit(1); |
| 85961 | if (isStageAllAndCommitConfirmedByUser) { |
| 85962 | await commit(extraArgs2, context, true, fullGitMojiSpec); |
| 85963 | process.exit(0); |
| 85964 | } |
| 85965 | if (stagedFiles.length === 0 && changedFiles.length > 0) { |
| 85966 | const files = await re({ |
| 85967 | message: source_default.cyan("Select the files you want to add to the commit:"), |
| 85968 | options: changedFiles.map((file) => ({ |
| 85969 | value: file, |
| 85970 | label: file |
| 85971 | })) |
| 85972 | }); |
| 85973 | if (hD2(files)) process.exit(0); |
| 85974 | await gitAdd({ files }); |
| 85975 | } |
| 85976 | await commit(extraArgs2, context, false, fullGitMojiSpec); |
| 85977 | process.exit(0); |
| 85978 | } |
| 85979 | stagedFilesSpinner.stop( |
| 85980 | `${stagedFiles.length} staged files: |
| 85981 | ${stagedFiles.map((file) => ` ${file}`).join("\n")}` |
| 85982 | ); |
| 85983 | const [, generateCommitError] = await trytm( |
| 85984 | generateCommitMessageFromGitDiff({ |
no test coverage detected
searching dependent graphs…