| 180 | } |
| 181 | |
| 182 | void Copilot::commits() |
| 183 | { |
| 184 | QProcess process; |
| 185 | process.setProgram("git"); |
| 186 | process.setArguments(QStringList() << "diff"); |
| 187 | auto &ctx = dpfInstance.serviceContext(); |
| 188 | ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name()); |
| 189 | auto prjInfo = projectService->getActiveProjectInfo(); |
| 190 | auto workingDirectory = prjInfo.workspaceFolder(); |
| 191 | process.setWorkingDirectory(workingDirectory); |
| 192 | |
| 193 | connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this, &process](int exitCode, QProcess::ExitStatus exitStatus) { |
| 194 | Q_UNUSED(exitStatus) |
| 195 | if (exitCode != 0) |
| 196 | return; |
| 197 | |
| 198 | auto diff = QString::fromUtf8(process.read(20000)); |
| 199 | QString prompt = "diff: ```%1```\n\n" |
| 200 | "You always analyze the git diff provided, detect changes, and generate succinct yet comprehensive commit messages. for the user step-by-step:\n1. You first parse the git diff to understand the changes made: additions, deletions, modifications, or renaming.\n2. Identify the components or modules that the changes are relating to.\n3. Understand the nature of changes: bug fixes, functionality enhancements, code optimization, documentation, etc.\n4. You highlight the primary updates without neglecting any minor alterations.\n5. Choose a commit type according to the primary updates.\n6. Organize these changes into an accurate, concise and informative commit message less than 20 words.\nYou should only reply a one-line commit message less than 20 words!!!"; |
| 201 | if (commitsLocale == Zh) |
| 202 | prompt.append("\nPlease answer by Chineses"); |
| 203 | ChatManager::instance()->requestAsync(prompt.arg(diff)); |
| 204 | switchToChatPage(); |
| 205 | }); |
| 206 | |
| 207 | process.start(); |
| 208 | process.waitForFinished(); |
| 209 | } |
| 210 | |
| 211 | void Copilot::switchToChatPage() |
| 212 | { |
nothing calls this directly
no test coverage detected