@d5render/cli 0.0.83 → 0.0.88

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 (2) hide show
  1. package/bin/copilot.js +88 -50
  2. package/package.json +1 -1
package/bin/copilot.js CHANGED
@@ -18544,10 +18544,13 @@ 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) return Promise.resolve({ content: [{
18548
- type: "text",
18549
- text: "✅ GitLab MCP Report 执行完成,无问题"
18550
- }] });
18547
+ if (severityIssues.length === 0) {
18548
+ console.log(`[GitLab] 无问题,跳过提交`);
18549
+ return Promise.resolve({ content: [{
18550
+ type: "text",
18551
+ text: "✅ GitLab MCP Report 执行完成,无问题"
18552
+ }] });
18553
+ }
18551
18554
  let message = `## 📖 ${title}\n`;
18552
18555
  if (summary) message += `> ${summary}\n\n`;
18553
18556
  const commitTasks = [];
@@ -18599,27 +18602,40 @@ const postComments = (report$1) => {
18599
18602
  }
18600
18603
  }
18601
18604
  if (nextActions.length > 0) message += "\n\n### 📈 其他建议\n\n-----\n - " + nextActions.join("\n - ");
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) => {
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) => {
18611
18623
  lastComment.value = res;
18624
+ console.log(`[GitLab] 总结报告已发布 - MR: ${url}`);
18612
18625
  return { content: [{
18613
18626
  type: "text",
18614
18627
  text: "✅ GitLab 代码审查报告已发布。"
18615
18628
  }] };
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
- }));
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
+ });
18623
18639
  };
18624
18640
  function toCode(code) {
18625
18641
  const ct = code.trim();
@@ -18736,15 +18752,21 @@ function commonURL() {
18736
18752
  //#region packages/builtin/dingding.ts
18737
18753
  const postComments$1 = (report$1) => {
18738
18754
  const { CI_PROJECT_NAME = "", CI_COMMIT_SHA = "", CI_COMMIT_AUTHOR = "", CI_COMMIT_AUTHOR_EMAIL = "", JIRA_BASE_URL, CI_MERGE_REQUEST_IID, DINGTALK_WEBHOOK } = envUsed;
18739
- if (!DINGTALK_WEBHOOK) return { content: [{
18740
- type: "text",
18741
- text: "✅ DingDing Webhook 配置,跳过推送。"
18742
- }] };
18755
+ if (!DINGTALK_WEBHOOK) {
18756
+ console.log(`[钉钉] 跳过推送 - 无 Webhook 配置`);
18757
+ return { content: [{
18758
+ type: "text",
18759
+ text: "✅ 无 DingDing Webhook 配置,跳过推送。"
18760
+ }] };
18761
+ }
18743
18762
  const { title = "代码审查报告", mainRisks = [], relatedJIRAs = [], severityIssues = [] } = report$1;
18744
- if (severityIssues.length === 0) return { content: [{
18745
- type: "text",
18746
- text: "✅ 无问题,跳过DingDing推送。"
18747
- }] };
18763
+ if (severityIssues.length === 0) {
18764
+ console.log(`[钉钉] 跳过推送 - 无问题`);
18765
+ return { content: [{
18766
+ type: "text",
18767
+ text: "✅ 无问题,跳过DingDing推送。"
18768
+ }] };
18769
+ }
18748
18770
  let { url, type } = commonURL();
18749
18771
  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}>` : ""}`;
18750
18772
  if (type) {
@@ -18798,6 +18820,7 @@ const postComments$1 = (report$1) => {
18798
18820
  hashLength++;
18799
18821
  }
18800
18822
  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}`);
18801
18824
  return fetch(DINGTALK_WEBHOOK, {
18802
18825
  method: "POST",
18803
18826
  headers: { "Content-Type": "application/json" },
@@ -18816,22 +18839,31 @@ const postComments$1 = (report$1) => {
18816
18839
  if (!response.ok) throw new Error("");
18817
18840
  return response.json();
18818
18841
  }).then((res) => {
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
- }] };
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
+ }
18827
18856
  throw new Error("Post comments to DingTalk with error code:" + res.errcode + ", message: " + res.errmsg);
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
- }));
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
+ });
18835
18867
  };
18836
18868
 
18837
18869
  //#endregion
@@ -18886,15 +18918,21 @@ function install(server$1) {
18886
18918
  description: noMandatory,
18887
18919
  inputSchema: reportSchema
18888
18920
  }, async (...args) => {
18921
+ const issueCount = args[0]?.severityIssues?.length || 0;
18922
+ console.log(`[报告提交] 开始提交代码审查报告,共 ${issueCount} 个问题`);
18889
18923
  const git = await postComments(...args);
18890
18924
  const ding = await postComments$1(...args);
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
- };
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: 已发布, 钉钉: 已推送`);
18898
18936
  return { content: [{
18899
18937
  type: "text",
18900
18938
  text: args[0]?.summary || ""
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.83",
7
+ "version": "0.0.88",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.24.3",
10
10
  "@types/node": "22.18.1",