@d5render/cli 0.0.88 → 0.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin/copilot.js +50 -88
  2. package/bin/d5cli +20 -2
  3. package/package.json +1 -1
package/bin/copilot.js CHANGED
@@ -18544,13 +18544,10 @@ const lastComment = { value: {} };
18544
18544
  const postComments = (report$1) => {
18545
18545
  const url = commonMergeURL();
18546
18546
  const { title = "代码审查报告", summary, severityIssues = [], mainRisks = [], nextActions = [] } = report$1;
18547
- if (severityIssues.length === 0) {
18548
- console.log(`[GitLab] 无问题,跳过提交`);
18549
- return Promise.resolve({ content: [{
18550
- type: "text",
18551
- text: "✅ GitLab MCP Report 执行完成,无问题"
18552
- }] });
18553
- }
18547
+ if (severityIssues.length === 0) return Promise.resolve({ content: [{
18548
+ type: "text",
18549
+ text: "✅ GitLab MCP Report 执行完成,无问题"
18550
+ }] });
18554
18551
  let message = `## 📖 ${title}\n`;
18555
18552
  if (summary) message += `> ${summary}\n\n`;
18556
18553
  const commitTasks = [];
@@ -18602,40 +18599,27 @@ const postComments = (report$1) => {
18602
18599
  }
18603
18600
  }
18604
18601
  if (nextActions.length > 0) message += "\n\n### 📈 其他建议\n\n-----\n - " + nextActions.join("\n - ");
18605
- if (!url) {
18606
- console.log(`[GitLab] 跳过提交 - push 事件,无合并请求`);
18607
- return Promise.resolve({ content: [{
18608
- type: "text",
18609
- text: "⚠️ 当前为 push 事件,无合并请求,无法在 GitLab 中发布报告。报告内容已生成但未发布。"
18610
- }] });
18611
- }
18612
- console.log(`[GitLab] 开始提交 - 行内评论: ${commitTasks.length} 条, 总结报告: 1 条`);
18613
- return Promise.allSettled(commitTasks.map((task) => task())).then((results) => {
18614
- const successCount = results.filter((r) => r.status === "fulfilled").length;
18615
- const failCount = results.filter((r) => r.status === "rejected").length;
18616
- if (commitTasks.length > 0) console.log(`[GitLab] 行内评论提交完成 - 成功: ${successCount}, 失败: ${failCount}`);
18617
- return fetch(url + `/notes`, {
18618
- method: "POST",
18619
- headers: commonHeaders$1(),
18620
- body: JSON.stringify({ body: message })
18621
- });
18622
- }).then((res) => res.json()).then((res) => {
18602
+ if (!url) return Promise.resolve({ content: [{
18603
+ type: "text",
18604
+ text: "⚠️ 当前为 push 事件,无合并请求,无法在 GitLab 中发布报告。报告内容已生成但未发布。"
18605
+ }] });
18606
+ return Promise.allSettled(commitTasks.map((task) => task())).then(() => fetch(url + `/notes`, {
18607
+ method: "POST",
18608
+ headers: commonHeaders$1(),
18609
+ body: JSON.stringify({ body: message })
18610
+ })).then((res) => res.json()).then((res) => {
18623
18611
  lastComment.value = res;
18624
- console.log(`[GitLab] 总结报告已发布 - MR: ${url}`);
18625
18612
  return { content: [{
18626
18613
  type: "text",
18627
18614
  text: "✅ GitLab 代码审查报告已发布。"
18628
18615
  }] };
18629
- }).catch((error$1) => {
18630
- console.error(`[GitLab] 提交失败 - ${error$1.message || error$1.reason || "未知错误"}`);
18631
- return {
18632
- content: [{
18633
- type: "text",
18634
- text: errorMessage + `-report, reason: ${error$1.message || error$1.reason || "未知错误"}`
18635
- }],
18636
- isError: true
18637
- };
18638
- });
18616
+ }).catch((error$1) => ({
18617
+ content: [{
18618
+ type: "text",
18619
+ text: errorMessage + `-report, reason: ${error$1.message || error$1.reason || "未知错误"}`
18620
+ }],
18621
+ isError: true
18622
+ }));
18639
18623
  };
18640
18624
  function toCode(code) {
18641
18625
  const ct = code.trim();
@@ -18752,21 +18736,15 @@ function commonURL() {
18752
18736
  //#region packages/builtin/dingding.ts
18753
18737
  const postComments$1 = (report$1) => {
18754
18738
  const { CI_PROJECT_NAME = "", CI_COMMIT_SHA = "", CI_COMMIT_AUTHOR = "", CI_COMMIT_AUTHOR_EMAIL = "", JIRA_BASE_URL, CI_MERGE_REQUEST_IID, DINGTALK_WEBHOOK } = envUsed;
18755
- if (!DINGTALK_WEBHOOK) {
18756
- console.log(`[钉钉] 跳过推送 - 无 Webhook 配置`);
18757
- return { content: [{
18758
- type: "text",
18759
- text: "✅ 无 DingDing Webhook 配置,跳过推送。"
18760
- }] };
18761
- }
18739
+ if (!DINGTALK_WEBHOOK) return { content: [{
18740
+ type: "text",
18741
+ text: "✅ DingDing Webhook 配置,跳过推送。"
18742
+ }] };
18762
18743
  const { title = "代码审查报告", mainRisks = [], relatedJIRAs = [], severityIssues = [] } = report$1;
18763
- if (severityIssues.length === 0) {
18764
- console.log(`[钉钉] 跳过推送 - 无问题`);
18765
- return { content: [{
18766
- type: "text",
18767
- text: "✅ 无问题,跳过DingDing推送。"
18768
- }] };
18769
- }
18744
+ if (severityIssues.length === 0) return { content: [{
18745
+ type: "text",
18746
+ text: "✅ 无问题,跳过DingDing推送。"
18747
+ }] };
18770
18748
  let { url, type } = commonURL();
18771
18749
  let message = `### 📖 ${title}\n\n**共计**:${severityIssues.length}个问题\n\n${mainRisks.length >= 0 ? "**主要风险**:\n\n" + mainRisks.join("\n\n") + "\n\n" : "\n\n"}-----\n\n**项目名**:${CI_PROJECT_NAME}\n\n**作者**:${CI_COMMIT_AUTHOR}${CI_COMMIT_AUTHOR_EMAIL ? ` <${CI_COMMIT_AUTHOR_EMAIL}>` : ""}`;
18772
18750
  if (type) {
@@ -18820,7 +18798,6 @@ const postComments$1 = (report$1) => {
18820
18798
  hashLength++;
18821
18799
  }
18822
18800
  if (relatedJIRAs.length > 0) message += `\n\n\n\n#### 🔗 关联 JIRA\n ${relatedJIRAs.map((v) => `[${v.key}](${JIRA_BASE_URL}/browse/${v.key}): ${v.summary}`).join("\n\n")}`;
18823
- console.log(`[钉钉] 开始推送 - 问题数: ${severityIssues.length}, 项目: ${CI_PROJECT_NAME}`);
18824
18801
  return fetch(DINGTALK_WEBHOOK, {
18825
18802
  method: "POST",
18826
18803
  headers: { "Content-Type": "application/json" },
@@ -18839,31 +18816,22 @@ const postComments$1 = (report$1) => {
18839
18816
  if (!response.ok) throw new Error("");
18840
18817
  return response.json();
18841
18818
  }).then((res) => {
18842
- if (res.errcode === 0) {
18843
- console.log(`[钉钉] 推送成功`);
18844
- return { content: [{
18845
- type: "text",
18846
- text: "✅ DingDing 代码审查报告已推送。"
18847
- }] };
18848
- }
18849
- if (res.errcode === 31e4) {
18850
- console.log(`[钉钉] 推送成功,但被关键词拦截`);
18851
- return { content: [{
18852
- type: "text",
18853
- text: "✅ DingDing 代码审查报告已推送,但被屏蔽关键词拦截。"
18854
- }] };
18855
- }
18819
+ if (res.errcode === 0) return { content: [{
18820
+ type: "text",
18821
+ text: "✅ DingDing 代码审查报告已推送。"
18822
+ }] };
18823
+ if (res.errcode === 31e4) return { content: [{
18824
+ type: "text",
18825
+ text: "✅ DingDing 代码审查报告已推送,但被屏蔽关键词拦截。"
18826
+ }] };
18856
18827
  throw new Error("Post comments to DingTalk with error code:" + res.errcode + ", message: " + res.errmsg);
18857
- }).catch((error$1) => {
18858
- console.error(`[钉钉] 推送失败 - ${error$1.message || "Post comments to DingTalk failed"}`);
18859
- return {
18860
- content: [{
18861
- type: "text",
18862
- text: errorMessage + "-dingding, reason: " + (error$1.message || "Post comments to DingTalk failed")
18863
- }],
18864
- isError: true
18865
- };
18866
- });
18828
+ }).catch((error$1) => ({
18829
+ content: [{
18830
+ type: "text",
18831
+ text: errorMessage + "-dingding, reason: " + (error$1.message || "Post comments to DingTalk failed")
18832
+ }],
18833
+ isError: true
18834
+ }));
18867
18835
  };
18868
18836
 
18869
18837
  //#endregion
@@ -18918,21 +18886,15 @@ function install(server$1) {
18918
18886
  description: noMandatory,
18919
18887
  inputSchema: reportSchema
18920
18888
  }, async (...args) => {
18921
- const issueCount = args[0]?.severityIssues?.length || 0;
18922
- console.log(`[报告提交] 开始提交代码审查报告,共 ${issueCount} 个问题`);
18923
18889
  const git = await postComments(...args);
18924
18890
  const ding = await postComments$1(...args);
18925
- if (git.isError || ding.isError) {
18926
- console.error(`[报告提交] 提交失败 - GitLab: ${git.isError ? "失败" : "成功"}, 钉钉: ${ding.isError ? "失败" : "成功"}`);
18927
- return {
18928
- content: [{
18929
- type: "text",
18930
- text: [...git.isError ? git.content : [], ...ding.isError ? ding.content : []].map((c) => c.text).join(", ")
18931
- }],
18932
- isError: true
18933
- };
18934
- }
18935
- console.log(`[报告提交] 提交成功 - GitLab: 已发布, 钉钉: 已推送`);
18891
+ if (git.isError || ding.isError) return {
18892
+ content: [{
18893
+ type: "text",
18894
+ text: [...git.isError ? git.content : [], ...ding.isError ? ding.content : []].map((c) => c.text).join(", ")
18895
+ }],
18896
+ isError: true
18897
+ };
18936
18898
  return { content: [{
18937
18899
  type: "text",
18938
18900
  text: args[0]?.summary || ""
package/bin/d5cli CHANGED
@@ -2,10 +2,13 @@
2
2
 
3
3
  import { execSync, spawn } from "node:child_process";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
- import { join } from "node:path";
5
+ import { dirname, join } from "node:path";
6
6
  import { env, exit, platform } from "node:process";
7
+ import { fileURLToPath } from "node:url";
7
8
  import { errorMessage, getHash, name, report, tools } from "../copilot.config.js";
8
9
 
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+
9
12
  const prompt = `call the mcp tool '${name}-${getHash}' to load review commits, if the task encounters an error, throw that, otherwise, you can decide for yourself which tools to use to enrich context and determine whether a specific commit needs to be reviewed.
10
13
  Then, use chinese as default language to organize the report into JSON format and call the mcp tool '${name}-${report}', please ignore error encountered when calling this and report title should not contain words such as MCP or "中文".`;
11
14
 
@@ -76,6 +79,21 @@ function findCopilopt() {
76
79
  ? copilotPackage.bin
77
80
  : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
78
81
  if (!binPath) throw new Error("找不到 copilot 可执行文件路径");
79
- console.log(join(copilot, binPath), "copilot 已经被发现");
82
+ const copilotVersion = copilotPackage.version || "未知版本";
83
+
84
+ // 读取 d5cli 的版本
85
+ const d5cliPkg = join(__dirname, "..", "package.json");
86
+ let d5cliVersion = "未知版本";
87
+ if (existsSync(d5cliPkg)) {
88
+ try {
89
+ const d5cliPackage = JSON.parse(readFileSync(d5cliPkg, "utf8"));
90
+ d5cliVersion = d5cliPackage.version || "未知版本";
91
+ } catch {}
92
+ }
93
+
94
+ console.log(
95
+ join(copilot, binPath),
96
+ `copilot 已经被发现,copilot 版本: ${copilotVersion}, d5cli 版本: ${d5cliVersion}`
97
+ );
80
98
  return join(copilot, binPath);
81
99
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
6
  "main": "./bin/d5cli",
7
- "version": "0.0.88",
7
+ "version": "0.0.91",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.24.3",
10
10
  "@types/node": "22.18.1",