@d5render/cli 0.0.83 → 0.0.90
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.
- package/bin/copilot.js +136 -96
- package/package.json +1 -1
package/bin/copilot.js
CHANGED
|
@@ -14797,10 +14797,10 @@ var require_core$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14797
14797
|
Ajv$2.ValidationError = validation_error_1$1.default;
|
|
14798
14798
|
Ajv$2.MissingRefError = ref_error_1$3.default;
|
|
14799
14799
|
exports.default = Ajv$2;
|
|
14800
|
-
function checkOptions(checkOpts, options, msg, log = "error") {
|
|
14800
|
+
function checkOptions(checkOpts, options, msg, log$1 = "error") {
|
|
14801
14801
|
for (const key in checkOpts) {
|
|
14802
14802
|
const opt = key;
|
|
14803
|
-
if (opt in options) this.logger[log](`${msg}: option ${key}. ${checkOpts[opt]}`);
|
|
14803
|
+
if (opt in options) this.logger[log$1](`${msg}: option ${key}. ${checkOpts[opt]}`);
|
|
14804
14804
|
}
|
|
14805
14805
|
}
|
|
14806
14806
|
function getSchEnv(keyRef) {
|
|
@@ -18510,6 +18510,53 @@ const config = JSON.stringify({ mcpServers: { [name]: {
|
|
|
18510
18510
|
tools: ["*"]
|
|
18511
18511
|
} } });
|
|
18512
18512
|
|
|
18513
|
+
//#endregion
|
|
18514
|
+
//#region packages/builtin/config.ts
|
|
18515
|
+
function log(message) {
|
|
18516
|
+
process.stderr.write(`[LOG] ${message}\n`);
|
|
18517
|
+
}
|
|
18518
|
+
const reportSchema = {
|
|
18519
|
+
title: string().optional().describe("The title of the report"),
|
|
18520
|
+
summary: string().optional().describe("Overall summary of the changes"),
|
|
18521
|
+
relatedJIRAs: array(object({
|
|
18522
|
+
key: string().describe("JIRA issue key, e.g., 'FUS-123'"),
|
|
18523
|
+
summary: string().describe("Summary of the JIRA issue")
|
|
18524
|
+
}).describe("Related JIRA issues")).optional().describe("List of related JIRA issues"),
|
|
18525
|
+
severityIssues: array(object({
|
|
18526
|
+
severity: string().optional().describe("Bug severity levels, such as CRITICAL, HIGH, MEDIUM, LOW."),
|
|
18527
|
+
commitSha: string().optional().describe("The commit SHA associated with the issue"),
|
|
18528
|
+
commitTitle: string().optional().describe("The commit title associated with the issue"),
|
|
18529
|
+
file: string().optional().describe("The file path where the issue is found"),
|
|
18530
|
+
line: string().optional().describe("Line number, e.g., '1-345' pr '205' or '17,35', **must** provide the line of final file"),
|
|
18531
|
+
title: string().optional().describe("A short title for the issue"),
|
|
18532
|
+
details: array(string()).optional().describe("Details about the issue"),
|
|
18533
|
+
suggestions: array(string()).optional().describe("Improvement suggestion"),
|
|
18534
|
+
codeExample: string().optional().describe(`Code modification suggestions, recommended to use code in diff format, like: \`\`\`
|
|
18535
|
+
while (condition) {
|
|
18536
|
+
unchanged line;
|
|
18537
|
+
- remove this;
|
|
18538
|
+
+ replace it with this;
|
|
18539
|
+
+ and this;
|
|
18540
|
+
but keep this the same;
|
|
18541
|
+
}\`\`\`.`)
|
|
18542
|
+
})).optional().describe("List all bugs, Please order by 'severity' sort them from heaviest to lightest."),
|
|
18543
|
+
mainRisks: array(string().describe("Main risk item")).optional().describe("List of main risks"),
|
|
18544
|
+
nextActions: array(string().describe("Description of the action item")).optional().describe("List suggestions for improvement")
|
|
18545
|
+
};
|
|
18546
|
+
function commonURL() {
|
|
18547
|
+
const { CI_SERVER_URL, CI_PROJECT_PATH, CI_MERGE_REQUEST_IID, CI_COMMIT_SHA } = envUsed;
|
|
18548
|
+
if (!CI_SERVER_URL || !CI_PROJECT_PATH) return {};
|
|
18549
|
+
if (CI_MERGE_REQUEST_IID) return {
|
|
18550
|
+
url: `${CI_SERVER_URL}/${CI_PROJECT_PATH}/-/merge_requests/${CI_MERGE_REQUEST_IID}`,
|
|
18551
|
+
type: "merge_request"
|
|
18552
|
+
};
|
|
18553
|
+
if (CI_COMMIT_SHA) return {
|
|
18554
|
+
url: `${CI_SERVER_URL}/${CI_PROJECT_PATH}/-/commit/${CI_COMMIT_SHA}`,
|
|
18555
|
+
type: "commit"
|
|
18556
|
+
};
|
|
18557
|
+
return {};
|
|
18558
|
+
}
|
|
18559
|
+
|
|
18513
18560
|
//#endregion
|
|
18514
18561
|
//#region packages/gitlab/config.ts
|
|
18515
18562
|
const canireview = "can-i-review";
|
|
@@ -18544,10 +18591,13 @@ const lastComment = { value: {} };
|
|
|
18544
18591
|
const postComments = (report$1) => {
|
|
18545
18592
|
const url = commonMergeURL();
|
|
18546
18593
|
const { title = "代码审查报告", summary, severityIssues = [], mainRisks = [], nextActions = [] } = report$1;
|
|
18547
|
-
if (severityIssues.length === 0)
|
|
18548
|
-
|
|
18549
|
-
|
|
18550
|
-
|
|
18594
|
+
if (severityIssues.length === 0) {
|
|
18595
|
+
log("GitLab: 无问题,跳过提交");
|
|
18596
|
+
return Promise.resolve({ content: [{
|
|
18597
|
+
type: "text",
|
|
18598
|
+
text: "✅ GitLab MCP Report 执行完成,无问题"
|
|
18599
|
+
}] });
|
|
18600
|
+
}
|
|
18551
18601
|
let message = `## 📖 ${title}\n`;
|
|
18552
18602
|
if (summary) message += `> ${summary}\n\n`;
|
|
18553
18603
|
const commitTasks = [];
|
|
@@ -18599,27 +18649,40 @@ const postComments = (report$1) => {
|
|
|
18599
18649
|
}
|
|
18600
18650
|
}
|
|
18601
18651
|
if (nextActions.length > 0) message += "\n\n### 📈 其他建议\n\n-----\n - " + nextActions.join("\n - ");
|
|
18602
|
-
if (!url)
|
|
18603
|
-
|
|
18604
|
-
|
|
18605
|
-
|
|
18606
|
-
|
|
18607
|
-
|
|
18608
|
-
|
|
18609
|
-
|
|
18610
|
-
|
|
18652
|
+
if (!url) {
|
|
18653
|
+
log("GitLab: 跳过提交 - push 事件,无合并请求");
|
|
18654
|
+
return Promise.resolve({ content: [{
|
|
18655
|
+
type: "text",
|
|
18656
|
+
text: "⚠️ 当前为 push 事件,无合并请求,无法在 GitLab 中发布报告。报告内容已生成但未发布。"
|
|
18657
|
+
}] });
|
|
18658
|
+
}
|
|
18659
|
+
log(`GitLab: 开始提交 - 行内评论: ${commitTasks.length} 条, 总结报告: 1 条`);
|
|
18660
|
+
return Promise.allSettled(commitTasks.map((task) => task())).then((results) => {
|
|
18661
|
+
const successCount = results.filter((r) => r.status === "fulfilled").length;
|
|
18662
|
+
const failCount = results.filter((r) => r.status === "rejected").length;
|
|
18663
|
+
if (commitTasks.length > 0) log(`GitLab: 行内评论完成 - 成功: ${successCount}, 失败: ${failCount}`);
|
|
18664
|
+
return fetch(url + `/notes`, {
|
|
18665
|
+
method: "POST",
|
|
18666
|
+
headers: commonHeaders$1(),
|
|
18667
|
+
body: JSON.stringify({ body: message })
|
|
18668
|
+
});
|
|
18669
|
+
}).then((res) => res.json()).then((res) => {
|
|
18611
18670
|
lastComment.value = res;
|
|
18671
|
+
log(`GitLab: 总结报告已发布`);
|
|
18612
18672
|
return { content: [{
|
|
18613
18673
|
type: "text",
|
|
18614
18674
|
text: "✅ GitLab 代码审查报告已发布。"
|
|
18615
18675
|
}] };
|
|
18616
|
-
}).catch((error$1) =>
|
|
18617
|
-
|
|
18618
|
-
|
|
18619
|
-
|
|
18620
|
-
|
|
18621
|
-
|
|
18622
|
-
|
|
18676
|
+
}).catch((error$1) => {
|
|
18677
|
+
log(`GitLab: 提交失败 - ${error$1.message || error$1.reason || "未知错误"}`);
|
|
18678
|
+
return {
|
|
18679
|
+
content: [{
|
|
18680
|
+
type: "text",
|
|
18681
|
+
text: errorMessage + `-report, reason: ${error$1.message || error$1.reason || "未知错误"}`
|
|
18682
|
+
}],
|
|
18683
|
+
isError: true
|
|
18684
|
+
};
|
|
18685
|
+
});
|
|
18623
18686
|
};
|
|
18624
18687
|
function toCode(code) {
|
|
18625
18688
|
const ct = code.trim();
|
|
@@ -18688,63 +18751,25 @@ function installGitlab(server$1) {
|
|
|
18688
18751
|
}, getMergeInfomation);
|
|
18689
18752
|
}
|
|
18690
18753
|
|
|
18691
|
-
//#endregion
|
|
18692
|
-
//#region packages/builtin/config.ts
|
|
18693
|
-
const reportSchema = {
|
|
18694
|
-
title: string().optional().describe("The title of the report"),
|
|
18695
|
-
summary: string().optional().describe("Overall summary of the changes"),
|
|
18696
|
-
relatedJIRAs: array(object({
|
|
18697
|
-
key: string().describe("JIRA issue key, e.g., 'FUS-123'"),
|
|
18698
|
-
summary: string().describe("Summary of the JIRA issue")
|
|
18699
|
-
}).describe("Related JIRA issues")).optional().describe("List of related JIRA issues"),
|
|
18700
|
-
severityIssues: array(object({
|
|
18701
|
-
severity: string().optional().describe("Bug severity levels, such as CRITICAL, HIGH, MEDIUM, LOW."),
|
|
18702
|
-
commitSha: string().optional().describe("The commit SHA associated with the issue"),
|
|
18703
|
-
commitTitle: string().optional().describe("The commit title associated with the issue"),
|
|
18704
|
-
file: string().optional().describe("The file path where the issue is found"),
|
|
18705
|
-
line: string().optional().describe("Line number, e.g., '1-345' pr '205' or '17,35', **must** provide the line of final file"),
|
|
18706
|
-
title: string().optional().describe("A short title for the issue"),
|
|
18707
|
-
details: array(string()).optional().describe("Details about the issue"),
|
|
18708
|
-
suggestions: array(string()).optional().describe("Improvement suggestion"),
|
|
18709
|
-
codeExample: string().optional().describe(`Code modification suggestions, recommended to use code in diff format, like: \`\`\`
|
|
18710
|
-
while (condition) {
|
|
18711
|
-
unchanged line;
|
|
18712
|
-
- remove this;
|
|
18713
|
-
+ replace it with this;
|
|
18714
|
-
+ and this;
|
|
18715
|
-
but keep this the same;
|
|
18716
|
-
}\`\`\`.`)
|
|
18717
|
-
})).optional().describe("List all bugs, Please order by 'severity' sort them from heaviest to lightest."),
|
|
18718
|
-
mainRisks: array(string().describe("Main risk item")).optional().describe("List of main risks"),
|
|
18719
|
-
nextActions: array(string().describe("Description of the action item")).optional().describe("List suggestions for improvement")
|
|
18720
|
-
};
|
|
18721
|
-
function commonURL() {
|
|
18722
|
-
const { CI_SERVER_URL, CI_PROJECT_PATH, CI_MERGE_REQUEST_IID, CI_COMMIT_SHA } = envUsed;
|
|
18723
|
-
if (!CI_SERVER_URL || !CI_PROJECT_PATH) return {};
|
|
18724
|
-
if (CI_MERGE_REQUEST_IID) return {
|
|
18725
|
-
url: `${CI_SERVER_URL}/${CI_PROJECT_PATH}/-/merge_requests/${CI_MERGE_REQUEST_IID}`,
|
|
18726
|
-
type: "merge_request"
|
|
18727
|
-
};
|
|
18728
|
-
if (CI_COMMIT_SHA) return {
|
|
18729
|
-
url: `${CI_SERVER_URL}/${CI_PROJECT_PATH}/-/commit/${CI_COMMIT_SHA}`,
|
|
18730
|
-
type: "commit"
|
|
18731
|
-
};
|
|
18732
|
-
return {};
|
|
18733
|
-
}
|
|
18734
|
-
|
|
18735
18754
|
//#endregion
|
|
18736
18755
|
//#region packages/builtin/dingding.ts
|
|
18737
18756
|
const postComments$1 = (report$1) => {
|
|
18738
18757
|
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)
|
|
18740
|
-
|
|
18741
|
-
|
|
18742
|
-
|
|
18758
|
+
if (!DINGTALK_WEBHOOK) {
|
|
18759
|
+
log("钉钉: 跳过推送 - 无 Webhook 配置");
|
|
18760
|
+
return { content: [{
|
|
18761
|
+
type: "text",
|
|
18762
|
+
text: "✅ 无 DingDing Webhook 配置,跳过推送。"
|
|
18763
|
+
}] };
|
|
18764
|
+
}
|
|
18743
18765
|
const { title = "代码审查报告", mainRisks = [], relatedJIRAs = [], severityIssues = [] } = report$1;
|
|
18744
|
-
if (severityIssues.length === 0)
|
|
18745
|
-
|
|
18746
|
-
|
|
18747
|
-
|
|
18766
|
+
if (severityIssues.length === 0) {
|
|
18767
|
+
log("钉钉: 跳过推送 - 无问题");
|
|
18768
|
+
return { content: [{
|
|
18769
|
+
type: "text",
|
|
18770
|
+
text: "✅ 无问题,跳过DingDing推送。"
|
|
18771
|
+
}] };
|
|
18772
|
+
}
|
|
18748
18773
|
let { url, type } = commonURL();
|
|
18749
18774
|
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
18775
|
if (type) {
|
|
@@ -18798,6 +18823,7 @@ const postComments$1 = (report$1) => {
|
|
|
18798
18823
|
hashLength++;
|
|
18799
18824
|
}
|
|
18800
18825
|
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")}`;
|
|
18826
|
+
log(`钉钉: 开始推送 - 问题数: ${severityIssues.length}, 项目: ${CI_PROJECT_NAME}`);
|
|
18801
18827
|
return fetch(DINGTALK_WEBHOOK, {
|
|
18802
18828
|
method: "POST",
|
|
18803
18829
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18816,22 +18842,31 @@ const postComments$1 = (report$1) => {
|
|
|
18816
18842
|
if (!response.ok) throw new Error("");
|
|
18817
18843
|
return response.json();
|
|
18818
18844
|
}).then((res) => {
|
|
18819
|
-
if (res.errcode === 0)
|
|
18820
|
-
|
|
18821
|
-
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18845
|
+
if (res.errcode === 0) {
|
|
18846
|
+
log("钉钉: 推送成功");
|
|
18847
|
+
return { content: [{
|
|
18848
|
+
type: "text",
|
|
18849
|
+
text: "✅ DingDing 代码审查报告已推送。"
|
|
18850
|
+
}] };
|
|
18851
|
+
}
|
|
18852
|
+
if (res.errcode === 31e4) {
|
|
18853
|
+
log("钉钉: 推送成功,但被关键词拦截");
|
|
18854
|
+
return { content: [{
|
|
18855
|
+
type: "text",
|
|
18856
|
+
text: "✅ DingDing 代码审查报告已推送,但被屏蔽关键词拦截。"
|
|
18857
|
+
}] };
|
|
18858
|
+
}
|
|
18827
18859
|
throw new Error("Post comments to DingTalk with error code:" + res.errcode + ", message: " + res.errmsg);
|
|
18828
|
-
}).catch((error$1) =>
|
|
18829
|
-
|
|
18830
|
-
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18860
|
+
}).catch((error$1) => {
|
|
18861
|
+
log(`钉钉: 推送失败 - ${error$1.message || "Post comments to DingTalk failed"}`);
|
|
18862
|
+
return {
|
|
18863
|
+
content: [{
|
|
18864
|
+
type: "text",
|
|
18865
|
+
text: errorMessage + "-dingding, reason: " + (error$1.message || "Post comments to DingTalk failed")
|
|
18866
|
+
}],
|
|
18867
|
+
isError: true
|
|
18868
|
+
};
|
|
18869
|
+
});
|
|
18835
18870
|
};
|
|
18836
18871
|
|
|
18837
18872
|
//#endregion
|
|
@@ -18886,15 +18921,20 @@ function install(server$1) {
|
|
|
18886
18921
|
description: noMandatory,
|
|
18887
18922
|
inputSchema: reportSchema
|
|
18888
18923
|
}, async (...args) => {
|
|
18924
|
+
log(`报告提交开始 - 问题数: ${args[0]?.severityIssues?.length || 0}`);
|
|
18889
18925
|
const git = await postComments(...args);
|
|
18890
18926
|
const ding = await postComments$1(...args);
|
|
18891
|
-
if (git.isError || ding.isError)
|
|
18892
|
-
|
|
18893
|
-
|
|
18894
|
-
|
|
18895
|
-
|
|
18896
|
-
|
|
18897
|
-
|
|
18927
|
+
if (git.isError || ding.isError) {
|
|
18928
|
+
log(`报告提交失败 - GitLab: ${git.isError ? "失败" : "成功"}, 钉钉: ${ding.isError ? "失败" : "成功"}`);
|
|
18929
|
+
return {
|
|
18930
|
+
content: [{
|
|
18931
|
+
type: "text",
|
|
18932
|
+
text: [...git.isError ? git.content : [], ...ding.isError ? ding.content : []].map((c) => c.text).join(", ")
|
|
18933
|
+
}],
|
|
18934
|
+
isError: true
|
|
18935
|
+
};
|
|
18936
|
+
}
|
|
18937
|
+
log(`报告提交成功 - GitLab: 已发布, 钉钉: 已推送`);
|
|
18898
18938
|
return { content: [{
|
|
18899
18939
|
type: "text",
|
|
18900
18940
|
text: args[0]?.summary || ""
|