From 361dad1a64159562b497f00c08a09e9c9e01fba2 Mon Sep 17 00:00:00 2001 From: shenmo Date: Fri, 17 Jul 2026 23:12:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(submitter):=20=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=8E=B7=E5=8F=96git=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E5=B9=B6=E5=A1=AB=E5=85=85=E6=8F=90=E4=BA=A4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 扩展了提交器的自动填充能力,新增通过git config获取本地git用户名的能力,和原有邮箱获取逻辑结合,自动按照格式填充贡献者字段,优化用户提交体验 --- electron/main/backend/submitter.ts | 18 ++++++++++++ src/components/SubmitterWindow.vue | 44 ++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/electron/main/backend/submitter.ts b/electron/main/backend/submitter.ts index 0bfd8e66..6397f9d1 100644 --- a/electron/main/backend/submitter.ts +++ b/electron/main/backend/submitter.ts @@ -972,6 +972,24 @@ export function registerSubmitterHandlers( } }); + ipcMain.handle("get-git-name", async () => { + try { + const { exec } = await import("node:child_process"); + const util = await import("util"); + const execAsync = util.promisify(exec); + const { stdout } = await execAsync("git config user.name"); + const name = stdout.trim(); + logger.info({ name }, "[Submitter] Git name retrieved"); + return { success: true, data: name || "" }; + } catch (err) { + logger.warn( + { err }, + "[Submitter] Failed to get git name, not a git repo or git not installed", + ); + return { success: false, data: "" }; + } + }); + ipcMain.handle("get-tags-list", async () => { try { const apiUrl = "https://upload.deepinos.org.cn/api/index/get_tags_list"; diff --git a/src/components/SubmitterWindow.vue b/src/components/SubmitterWindow.vue index bd3ceebe..8313b803 100644 --- a/src/components/SubmitterWindow.vue +++ b/src/components/SubmitterWindow.vue @@ -1728,15 +1728,43 @@ const closeWindow = () => { import { onMounted, nextTick } from "vue"; -const getGitEmail = async () => { +const getGitInfo = async () => { try { - const result = await window.ipcRenderer.invoke("get-git-email"); - if (result?.success && result.data) { - formData.mail = result.data; - console.log("[Submitter] Git email auto-filled:", result.data); + const [nameResult, emailResult] = await Promise.all([ + window.ipcRenderer.invoke("get-git-name"), + window.ipcRenderer.invoke("get-git-email"), + ]); + + let gitName = ""; + let gitEmail = ""; + + if (nameResult?.success && nameResult.data) { + gitName = nameResult.data; + console.log("[Submitter] Git name auto-filled:", gitName); + } + + if (emailResult?.success && emailResult.data) { + gitEmail = emailResult.data; + console.log("[Submitter] Git email auto-filled:", gitEmail); + } + + // 将 git name 和 email 合并填入 contributor 字段,格式: Name + if (gitName || gitEmail) { + if (gitName && gitEmail) { + formData.contributor = `${gitName} <${gitEmail}>`; + } else if (gitName) { + formData.contributor = gitName; + } else if (gitEmail) { + formData.contributor = gitEmail; + } + } + + // 单独填入邮箱 + if (gitEmail) { + formData.mail = gitEmail; } } catch (err) { - console.warn("[Submitter] Failed to get git email:", err); + console.warn("[Submitter] Failed to get git info:", err); } }; @@ -1744,8 +1772,8 @@ onMounted(async () => { console.log("[Submitter] Component mounted, loading categories and tags"); // 先等待分类列表加载完成,避免后续竞态 await Promise.all([loadCategoriesList(), loadTagsList()]); - // 尝试从 git 配置读取邮箱 - await getGitEmail(); + // 尝试从 git 配置读取 name 和 email,填入 contributor 和 mail + await getGitInfo(); });