@wuyanbin/ai-code-review-cli-remote 1.0.25-canary.0 → 1.0.26
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/dist/core/model.d.ts.map +1 -1
- package/dist/core/model.js +36 -55
- package/dist/core/model.js.map +1 -1
- package/dist/core/run-report-fields.d.ts +25 -0
- package/dist/core/run-report-fields.d.ts.map +1 -0
- package/dist/core/run-report-fields.js +68 -0
- package/dist/core/run-report-fields.js.map +1 -0
- package/dist/platform/config.d.ts.map +1 -1
- package/dist/platform/config.js +3 -1
- package/dist/platform/config.js.map +1 -1
- package/dist/platform/report.d.ts +6 -0
- package/dist/platform/report.d.ts.map +1 -1
- package/dist/platform/report.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +7 -0
- package/dist/runner.js.map +1 -1
- package/package.json +1 -1
- package/dist/client.d.ts +0 -18
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -57
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -11
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -161
- package/dist/config.js.map +0 -1
- package/dist/core/priority.d.ts +0 -8
- package/dist/core/priority.d.ts.map +0 -1
- package/dist/core/priority.js +0 -48
- package/dist/core/priority.js.map +0 -1
- package/dist/diff.d.ts +0 -6
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js +0 -127
- package/dist/diff.js.map +0 -1
- package/dist/formatters.d.ts +0 -4
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js +0 -31
- package/dist/formatters.js.map +0 -1
- package/dist/gitlab.d.ts +0 -11
- package/dist/gitlab.d.ts.map +0 -1
- package/dist/gitlab.js +0 -193
- package/dist/gitlab.js.map +0 -1
- package/dist/http.d.ts +0 -4
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -31
- package/dist/http.js.map +0 -1
- package/dist/model.d.ts +0 -6
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js +0 -120
- package/dist/model.js.map +0 -1
- package/dist/report.d.ts +0 -9
- package/dist/report.d.ts.map +0 -1
- package/dist/report.js +0 -31
- package/dist/report.js.map +0 -1
- package/dist/reviewer.d.ts +0 -3
- package/dist/reviewer.d.ts.map +0 -1
- package/dist/reviewer.js +0 -140
- package/dist/reviewer.js.map +0 -1
- package/dist/summarizer.d.ts +0 -3
- package/dist/summarizer.d.ts.map +0 -1
- package/dist/summarizer.js +0 -75
- package/dist/summarizer.js.map +0 -1
package/dist/config.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadReviewConfig = loadReviewConfig;
|
|
4
|
-
exports.sanitizeConfigForLog = sanitizeConfigForLog;
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const promises_1 = require("node:fs/promises");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const node_module_1 = require("node:module");
|
|
9
|
-
const constants_1 = require("./constants");
|
|
10
|
-
const http_1 = require("./http");
|
|
11
|
-
const LOCAL_CONFIG_FILES = [
|
|
12
|
-
".aicr.config.js",
|
|
13
|
-
"aicr.config.js",
|
|
14
|
-
".aicr.config.cjs",
|
|
15
|
-
"aicr.config.cjs",
|
|
16
|
-
];
|
|
17
|
-
const requireConfig = (0, node_module_1.createRequire)(__filename);
|
|
18
|
-
function normalizePlatformUrl(env) {
|
|
19
|
-
const raw = env[constants_1.ENV_PLATFORM_URL]?.replace(/\/+$/, "");
|
|
20
|
-
return raw || null;
|
|
21
|
-
}
|
|
22
|
-
function asStringArray(value) {
|
|
23
|
-
return Array.isArray(value)
|
|
24
|
-
? value.filter((item) => typeof item === "string")
|
|
25
|
-
: [];
|
|
26
|
-
}
|
|
27
|
-
function normalizeSeverity(value) {
|
|
28
|
-
return value === "info" || value === "warning" || value === "error"
|
|
29
|
-
? value
|
|
30
|
-
: "warning";
|
|
31
|
-
}
|
|
32
|
-
function normalizeMaxComments(value) {
|
|
33
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
34
|
-
? Math.floor(value)
|
|
35
|
-
: 100;
|
|
36
|
-
}
|
|
37
|
-
function normalizeApiFormat(value, provider, endpoint) {
|
|
38
|
-
if (value === "openai" || value === "claude")
|
|
39
|
-
return value;
|
|
40
|
-
if (provider === "claude")
|
|
41
|
-
return "claude";
|
|
42
|
-
if (typeof endpoint === "string" &&
|
|
43
|
-
(endpoint.includes("anthropic.com") || endpoint.includes("/v1/messages"))) {
|
|
44
|
-
return "claude";
|
|
45
|
-
}
|
|
46
|
-
return "openai";
|
|
47
|
-
}
|
|
48
|
-
function normalizeConfig(raw, source, env) {
|
|
49
|
-
return {
|
|
50
|
-
source,
|
|
51
|
-
ai: {
|
|
52
|
-
name: raw.ai?.name,
|
|
53
|
-
provider: raw.ai?.provider,
|
|
54
|
-
apiFormat: normalizeApiFormat(raw.ai?.apiFormat, raw.ai?.provider, raw.ai?.endpoint),
|
|
55
|
-
model: raw.ai?.model || "deepseek-chat",
|
|
56
|
-
endpoint: raw.ai?.endpoint || "https://api.deepseek.com/chat/completions",
|
|
57
|
-
apiKey: env.MODEL_API_KEY || raw.ai?.apiKey || "",
|
|
58
|
-
},
|
|
59
|
-
rules: {
|
|
60
|
-
custom: asStringArray(raw.rules?.custom),
|
|
61
|
-
},
|
|
62
|
-
review: {
|
|
63
|
-
severity: normalizeSeverity(raw.review?.severity),
|
|
64
|
-
ignore: asStringArray(raw.review?.ignore),
|
|
65
|
-
maxComments: normalizeMaxComments(raw.review?.maxComments),
|
|
66
|
-
},
|
|
67
|
-
summary: {
|
|
68
|
-
enabled: raw.summary?.enabled ?? true,
|
|
69
|
-
},
|
|
70
|
-
gitlab: raw.gitlab?.token ? { token: raw.gitlab.token } : undefined,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function loadDevhubConfig(env, fetchImpl) {
|
|
74
|
-
const platformUrl = normalizePlatformUrl(env);
|
|
75
|
-
const token = env[constants_1.ENV_PROJECT_TOKEN];
|
|
76
|
-
if (!platformUrl || !token)
|
|
77
|
-
return null;
|
|
78
|
-
const url = `${platformUrl}${constants_1.API_CONFIG_PATH}`;
|
|
79
|
-
try {
|
|
80
|
-
console.error("[config] fetching Devhub config");
|
|
81
|
-
const resp = await fetchImpl(url, {
|
|
82
|
-
method: "GET",
|
|
83
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
84
|
-
});
|
|
85
|
-
if (!resp.ok) {
|
|
86
|
-
console.error(`[config] Devhub 配置获取失败 status=${resp.status}`);
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
const raw = (await resp.json());
|
|
90
|
-
const config = normalizeConfig(raw, "devhub", {});
|
|
91
|
-
if (!config.ai.apiKey || !config.ai.endpoint) {
|
|
92
|
-
console.error("[config] Devhub 配置缺少模型密钥或 endpoint,回退本地配置");
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return config;
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.error("[config] Devhub 配置获取异常,回退本地配置:", error instanceof Error ? error.message : String(error));
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function loadCachedConfig(env) {
|
|
103
|
-
const cachePath = env.AICR_CONFIG_CACHE;
|
|
104
|
-
if (!cachePath || !(0, node_fs_1.existsSync)(cachePath))
|
|
105
|
-
return null;
|
|
106
|
-
try {
|
|
107
|
-
const raw = JSON.parse(await (0, promises_1.readFile)(cachePath, "utf8"));
|
|
108
|
-
if (raw.source === "devhub" && raw.ai?.apiKey && raw.ai?.endpoint) {
|
|
109
|
-
console.error("[config] Loaded config from Devhub cache");
|
|
110
|
-
return normalizeConfig(raw, "devhub", {});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
console.error("[config] Devhub 配置缓存读取失败:", error instanceof Error ? error.message : String(error));
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
async function writeCachedConfig(env, config) {
|
|
119
|
-
const cachePath = env.AICR_CONFIG_CACHE;
|
|
120
|
-
if (!cachePath || config.source !== "devhub")
|
|
121
|
-
return;
|
|
122
|
-
await (0, promises_1.writeFile)(cachePath, JSON.stringify(config), { mode: 0o600 });
|
|
123
|
-
console.error("[config] Devhub config cached");
|
|
124
|
-
}
|
|
125
|
-
async function loadLocalConfig(cwd, env) {
|
|
126
|
-
for (const filename of LOCAL_CONFIG_FILES) {
|
|
127
|
-
const file = (0, node_path_1.resolve)(cwd, filename);
|
|
128
|
-
if (!(0, node_fs_1.existsSync)(file))
|
|
129
|
-
continue;
|
|
130
|
-
delete requireConfig.cache[requireConfig.resolve(file)];
|
|
131
|
-
const imported = requireConfig(file);
|
|
132
|
-
const raw = imported.default ?? imported;
|
|
133
|
-
console.error(`[config] Loaded local config from: ${file}`);
|
|
134
|
-
return normalizeConfig(raw, "local", env);
|
|
135
|
-
}
|
|
136
|
-
console.error("[config] No local config file found, using defaults.");
|
|
137
|
-
return normalizeConfig({}, "local", env);
|
|
138
|
-
}
|
|
139
|
-
async function loadReviewConfig(options = {}) {
|
|
140
|
-
const env = options.env ?? process.env;
|
|
141
|
-
const fetchImpl = options.fetchImpl ??
|
|
142
|
-
((url, init) => (0, http_1.fetchWithTimeout)(url, init ?? {}, constants_1.API_TIMEOUT_MS));
|
|
143
|
-
const cached = await loadCachedConfig(env);
|
|
144
|
-
if (cached)
|
|
145
|
-
return cached;
|
|
146
|
-
const devhubConfig = await loadDevhubConfig(env, fetchImpl);
|
|
147
|
-
if (devhubConfig) {
|
|
148
|
-
await writeCachedConfig(env, devhubConfig);
|
|
149
|
-
console.error("[config] Loaded config from Devhub");
|
|
150
|
-
return devhubConfig;
|
|
151
|
-
}
|
|
152
|
-
return loadLocalConfig(options.cwd ?? process.cwd(), env);
|
|
153
|
-
}
|
|
154
|
-
function sanitizeConfigForLog(config) {
|
|
155
|
-
return {
|
|
156
|
-
...config,
|
|
157
|
-
ai: { ...config.ai, apiKey: config.ai.apiKey ? "***" : "" },
|
|
158
|
-
gitlab: config.gitlab?.token ? { token: "***" } : config.gitlab,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAyLA,4CAmBC;AAED,oDAMC;AApND,qCAAqC;AACrC,+CAAuD;AACvD,yCAAoC;AACpC,6CAA4C;AAC5C,2CAAmG;AACnG,iCAAyD;AAWzD,MAAM,kBAAkB,GAAG;IACzB,iBAAiB;IACjB,gBAAgB;IAChB,kBAAkB;IAClB,iBAAiB;CAClB,CAAC;AACF,MAAM,aAAa,GAAG,IAAA,2BAAa,EAAC,UAAU,CAAC,CAAC;AAEhD,SAAS,oBAAoB,CAAC,GAAsB;IAClD,MAAM,GAAG,GAAG,GAAG,CAAC,4BAAgB,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,GAAG,IAAI,IAAI,CAAC;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;QAClE,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,OAAO;QACjE,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,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,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,SAAS,GACb,OAAO,CAAC,SAAS;QACjB,CAAC,CAAC,GAAW,EAAE,IAAkB,EAAE,EAAE,CACnC,IAAA,uBAAgB,EAAC,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,0BAAc,CAAC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC5D,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,iBAAiB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC3C,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACpD,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,OAAO,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAwB;IAC3D,OAAO;QACL,GAAG,MAAM;QACT,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;KAChE,CAAC;AACJ,CAAC"}
|
package/dist/core/priority.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AIComment, ReviewPriority, Severity } from "../types";
|
|
2
|
-
export declare const PRIORITY_ORDER: Record<ReviewPriority, number>;
|
|
3
|
-
export declare function isReviewPriority(value: unknown): value is ReviewPriority;
|
|
4
|
-
export declare function priorityFromSeverity(severity: Severity): ReviewPriority;
|
|
5
|
-
export declare function severityFromPriority(priority: ReviewPriority): Severity;
|
|
6
|
-
export declare function normalizeAICommentPriority(comment: AIComment): AIComment;
|
|
7
|
-
export declare function priorityLabel(priority?: ReviewPriority): string;
|
|
8
|
-
//# sourceMappingURL=priority.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../../src/core/priority.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAcpE,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAIzD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAEvE;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,CAEvE;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAOxE;AAED,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,MAAM,CAI/D"}
|
package/dist/core/priority.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PRIORITY_ORDER = void 0;
|
|
4
|
-
exports.isReviewPriority = isReviewPriority;
|
|
5
|
-
exports.priorityFromSeverity = priorityFromSeverity;
|
|
6
|
-
exports.severityFromPriority = severityFromPriority;
|
|
7
|
-
exports.normalizeAICommentPriority = normalizeAICommentPriority;
|
|
8
|
-
exports.priorityLabel = priorityLabel;
|
|
9
|
-
const PRIORITY_TO_SEVERITY = {
|
|
10
|
-
P0: "error",
|
|
11
|
-
P1: "warning",
|
|
12
|
-
P2: "info",
|
|
13
|
-
};
|
|
14
|
-
const SEVERITY_TO_PRIORITY = {
|
|
15
|
-
error: "P0",
|
|
16
|
-
warning: "P1",
|
|
17
|
-
info: "P2",
|
|
18
|
-
};
|
|
19
|
-
exports.PRIORITY_ORDER = {
|
|
20
|
-
P2: 0,
|
|
21
|
-
P1: 1,
|
|
22
|
-
P0: 2,
|
|
23
|
-
};
|
|
24
|
-
function isReviewPriority(value) {
|
|
25
|
-
return value === "P0" || value === "P1" || value === "P2";
|
|
26
|
-
}
|
|
27
|
-
function priorityFromSeverity(severity) {
|
|
28
|
-
return SEVERITY_TO_PRIORITY[severity];
|
|
29
|
-
}
|
|
30
|
-
function severityFromPriority(priority) {
|
|
31
|
-
return PRIORITY_TO_SEVERITY[priority];
|
|
32
|
-
}
|
|
33
|
-
function normalizeAICommentPriority(comment) {
|
|
34
|
-
const priority = comment.priority ?? priorityFromSeverity(comment.severity);
|
|
35
|
-
return {
|
|
36
|
-
...comment,
|
|
37
|
-
priority,
|
|
38
|
-
severity: severityFromPriority(priority),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function priorityLabel(priority) {
|
|
42
|
-
if (priority === "P0")
|
|
43
|
-
return "P0 Critical";
|
|
44
|
-
if (priority === "P2")
|
|
45
|
-
return "P2 Minor";
|
|
46
|
-
return "P1 Major";
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=priority.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"priority.js","sourceRoot":"","sources":["../../src/core/priority.ts"],"names":[],"mappings":";;;AAoBA,4CAEC;AAED,oDAEC;AAED,oDAEC;AAED,gEAOC;AAED,sCAIC;AA3CD,MAAM,oBAAoB,GAAqC;IAC7D,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,MAAM;CACX,CAAC;AAEF,MAAM,oBAAoB,GAAqC;IAC7D,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,IAAI;CACX,CAAC;AAEW,QAAA,cAAc,GAAmC;IAC5D,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;CACN,CAAC;AAEF,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC;AAC5D,CAAC;AAED,SAAgB,oBAAoB,CAAC,QAAkB;IACrD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,oBAAoB,CAAC,QAAwB;IAC3D,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,0BAA0B,CAAC,OAAkB;IAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5E,OAAO;QACL,GAAG,OAAO;QACV,QAAQ;QACR,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC;KACzC,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,QAAyB;IACrD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC;IAC5C,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,UAAU,CAAC;IACzC,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/diff.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AIComment } from "./types";
|
|
2
|
-
export declare function globToRegExp(pattern: string): RegExp;
|
|
3
|
-
export declare function filterDiffByIgnore(diff: string, ignorePatterns?: string[]): string;
|
|
4
|
-
export declare function buildAddedLinesIndexText(diff: string, maxLines?: number): string;
|
|
5
|
-
export declare function alignCommentsToDiffAddedLines(diff: string, comments: AIComment[]): AIComment[];
|
|
6
|
-
//# sourceMappingURL=diff.d.ts.map
|
package/dist/diff.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAgBpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAmBlF;AA4DD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAO,GAAG,MAAM,CAU9E;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,EAAE,GACpB,SAAS,EAAE,CAqBb"}
|
package/dist/diff.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.globToRegExp = globToRegExp;
|
|
4
|
-
exports.filterDiffByIgnore = filterDiffByIgnore;
|
|
5
|
-
exports.buildAddedLinesIndexText = buildAddedLinesIndexText;
|
|
6
|
-
exports.alignCommentsToDiffAddedLines = alignCommentsToDiffAddedLines;
|
|
7
|
-
function globToRegExp(pattern) {
|
|
8
|
-
if (pattern.endsWith("/**")) {
|
|
9
|
-
const prefix = pattern.slice(0, -3).replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
10
|
-
return new RegExp(`^${prefix}/.*$`);
|
|
11
|
-
}
|
|
12
|
-
if (pattern.startsWith("**/")) {
|
|
13
|
-
const rest = pattern
|
|
14
|
-
.slice(3)
|
|
15
|
-
.replace(/[.+?^${}()|[\]\\]/g, "\\$&")
|
|
16
|
-
.replace(/\*/g, "[^/]*");
|
|
17
|
-
return new RegExp(`^(?:.*/)?${rest}$`);
|
|
18
|
-
}
|
|
19
|
-
const escaped = pattern
|
|
20
|
-
.replace(/[.+?^${}()|[\]\\]/g, "\\$&")
|
|
21
|
-
.replace(/\*/g, "[^/]*");
|
|
22
|
-
return new RegExp(`^${escaped}$`);
|
|
23
|
-
}
|
|
24
|
-
function filterDiffByIgnore(diff, ignorePatterns) {
|
|
25
|
-
if (!ignorePatterns?.length || !diff.trim())
|
|
26
|
-
return diff;
|
|
27
|
-
const lines = diff.split("\n");
|
|
28
|
-
const kept = [];
|
|
29
|
-
let ignoreCurrent = false;
|
|
30
|
-
for (const line of lines) {
|
|
31
|
-
if (line.startsWith("diff --git ")) {
|
|
32
|
-
ignoreCurrent = false;
|
|
33
|
-
const match = /^diff --git a\/(.+?) b\/(.+)$/.exec(line);
|
|
34
|
-
if (match) {
|
|
35
|
-
ignoreCurrent = ignorePatterns.some((pattern) => globToRegExp(pattern).test(match[2]));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!ignoreCurrent)
|
|
39
|
-
kept.push(line);
|
|
40
|
-
}
|
|
41
|
-
return kept.join("\n");
|
|
42
|
-
}
|
|
43
|
-
function normalizePath(path) {
|
|
44
|
-
return path.trim().replace(/^[ab]\//, "").replace(/^\.\//, "");
|
|
45
|
-
}
|
|
46
|
-
function collectAddedLines(diff) {
|
|
47
|
-
const files = new Map();
|
|
48
|
-
let currentFile = null;
|
|
49
|
-
let inHunk = false;
|
|
50
|
-
let newLine = 0;
|
|
51
|
-
let oldLine = 0;
|
|
52
|
-
for (const raw of diff.split("\n")) {
|
|
53
|
-
if (raw.startsWith("diff --git ")) {
|
|
54
|
-
inHunk = false;
|
|
55
|
-
currentFile = null;
|
|
56
|
-
const match = /^diff --git a\/(.+?) b\/(.+)$/.exec(raw);
|
|
57
|
-
if (match) {
|
|
58
|
-
currentFile = normalizePath(match[2]);
|
|
59
|
-
files.set(currentFile, files.get(currentFile) ?? []);
|
|
60
|
-
}
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (raw.startsWith("+++ b/")) {
|
|
64
|
-
currentFile = normalizePath(raw.slice("+++ b/".length));
|
|
65
|
-
files.set(currentFile, files.get(currentFile) ?? []);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (raw.startsWith("@@")) {
|
|
69
|
-
const match = /^@@\s+\-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/.exec(raw);
|
|
70
|
-
inHunk = !!match;
|
|
71
|
-
oldLine = Number(match?.[1] ?? 0);
|
|
72
|
-
newLine = Number(match?.[2] ?? 0);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (!inHunk || !currentFile)
|
|
76
|
-
continue;
|
|
77
|
-
if (raw.startsWith("+") && !raw.startsWith("+++")) {
|
|
78
|
-
files.get(currentFile)?.push({
|
|
79
|
-
file: currentFile,
|
|
80
|
-
line: newLine,
|
|
81
|
-
content: raw.slice(1),
|
|
82
|
-
});
|
|
83
|
-
newLine += 1;
|
|
84
|
-
}
|
|
85
|
-
else if (raw.startsWith("-") && !raw.startsWith("---")) {
|
|
86
|
-
oldLine += 1;
|
|
87
|
-
}
|
|
88
|
-
else if (raw.startsWith(" ")) {
|
|
89
|
-
oldLine += 1;
|
|
90
|
-
newLine += 1;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return files;
|
|
94
|
-
}
|
|
95
|
-
function buildAddedLinesIndexText(diff, maxLines = 5000) {
|
|
96
|
-
const rows = [];
|
|
97
|
-
for (const [file, lines] of collectAddedLines(diff)) {
|
|
98
|
-
for (const item of lines) {
|
|
99
|
-
if (rows.length >= maxLines)
|
|
100
|
-
break;
|
|
101
|
-
rows.push(`[${file}:${item.line}] ${item.content}`);
|
|
102
|
-
}
|
|
103
|
-
if (rows.length >= maxLines)
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
return rows.length ? rows.join("\n") : "(diff 中未检测到可评论的新增行)";
|
|
107
|
-
}
|
|
108
|
-
function alignCommentsToDiffAddedLines(diff, comments) {
|
|
109
|
-
const added = collectAddedLines(diff);
|
|
110
|
-
return comments.flatMap((comment) => {
|
|
111
|
-
const file = normalizePath(comment.file);
|
|
112
|
-
const candidates = added.get(file);
|
|
113
|
-
if (!candidates?.length)
|
|
114
|
-
return [];
|
|
115
|
-
const exact = candidates.find((item) => item.line === comment.line);
|
|
116
|
-
const byCode = typeof comment.code === "string"
|
|
117
|
-
? candidates.find((item) => item.content.trim() === comment.code?.trim())
|
|
118
|
-
: undefined;
|
|
119
|
-
const chosen = exact ??
|
|
120
|
-
byCode ??
|
|
121
|
-
candidates.reduce((best, item) => Math.abs(item.line - comment.line) < Math.abs(best.line - comment.line)
|
|
122
|
-
? item
|
|
123
|
-
: best);
|
|
124
|
-
return [{ ...comment, file, line: chosen.line }];
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=diff.js.map
|
package/dist/diff.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":";;AAEA,oCAgBC;AAED,gDAmBC;AA4DD,4DAUC;AAED,sEAwBC;AArID,SAAgB,YAAY,CAAC,OAAe;IAC1C,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QAC1E,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,MAAM,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,OAAO;aACjB,KAAK,CAAC,CAAC,CAAC;aACR,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC;aACrC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QA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AC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;gBACrE,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,IAAI,CACT,CAAC;QACJ,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/formatters.d.ts
DELETED
package/dist/formatters.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAY,MAAM,SAAS,CAAC;AAQjE,wBAAgB,gBAAgB,IAAI,YAAY,CAE/C;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,YAAY,CAgB/D"}
|
package/dist/formatters.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildEmptyRdjson = buildEmptyRdjson;
|
|
4
|
-
exports.buildRdjson = buildRdjson;
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
function toRdjsonSeverity(severity) {
|
|
7
|
-
if (severity === "error")
|
|
8
|
-
return "ERROR";
|
|
9
|
-
if (severity === "info")
|
|
10
|
-
return "INFO";
|
|
11
|
-
return "WARNING";
|
|
12
|
-
}
|
|
13
|
-
function buildEmptyRdjson() {
|
|
14
|
-
return { source: { name: "ai_code_review" }, diagnostics: [] };
|
|
15
|
-
}
|
|
16
|
-
function buildRdjson(comments) {
|
|
17
|
-
return {
|
|
18
|
-
source: { name: "ai_code_review" },
|
|
19
|
-
diagnostics: comments
|
|
20
|
-
.filter((comment) => comment.file && comment.line)
|
|
21
|
-
.map((comment) => ({
|
|
22
|
-
message: `${comment.message || constants_1.DEFAULT_COMMENT_MESSAGE}${comment.suggestion ? `\n建议:${comment.suggestion}` : ""}`,
|
|
23
|
-
location: {
|
|
24
|
-
path: comment.file,
|
|
25
|
-
range: { start: { line: Number(comment.line) || 1, column: 1 } },
|
|
26
|
-
},
|
|
27
|
-
severity: toRdjsonSeverity(comment.severity),
|
|
28
|
-
})),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=formatters.js.map
|
package/dist/formatters.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":";;AASA,4CAEC;AAED,kCAgBC;AA7BD,2CAAsD;AAGtD,SAAS,gBAAgB,CAAC,QAAkB;IAC1C,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACvC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AACjE,CAAC;AAED,SAAgB,WAAW,CAAC,QAAqB;IAC/C,OAAO;QACL,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;QAClC,WAAW,EAAE,QAAQ;aAClB,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;aACjD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACjB,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,mCAAuB,GACpD,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EACtD,EAAE;YACF,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;aACjE;YACD,QAAQ,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC;SAC7C,CAAC,CAAC;KACN,CAAC;AACJ,CAAC"}
|
package/dist/gitlab.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AIComment } from "./types";
|
|
2
|
-
export declare function cleanupBotComments(options: {
|
|
3
|
-
token?: string;
|
|
4
|
-
env?: NodeJS.ProcessEnv;
|
|
5
|
-
}): Promise<number>;
|
|
6
|
-
export declare function postGitlabDiscussions(options: {
|
|
7
|
-
comments: AIComment[];
|
|
8
|
-
token?: string;
|
|
9
|
-
env?: NodeJS.ProcessEnv;
|
|
10
|
-
}): Promise<boolean>;
|
|
11
|
-
//# sourceMappingURL=gitlab.d.ts.map
|
package/dist/gitlab.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab.d.ts","sourceRoot":"","sources":["../src/gitlab.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAsIzC,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB,GAAG,OAAO,CAAC,MAAM,CAAC,CA2DlB;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB,GAAG,OAAO,CAAC,OAAO,CAAC,CAgEnB"}
|
package/dist/gitlab.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanupBotComments = cleanupBotComments;
|
|
4
|
-
exports.postGitlabDiscussions = postGitlabDiscussions;
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
const http_1 = require("./http");
|
|
7
|
-
const GITLAB_API_CONCURRENCY = 5;
|
|
8
|
-
function gitlabFetch(url, init = {}) {
|
|
9
|
-
return (0, http_1.fetchWithTimeout)(url, init, constants_1.API_TIMEOUT_MS);
|
|
10
|
-
}
|
|
11
|
-
function buildCommentBody(comment) {
|
|
12
|
-
const message = comment.message || constants_1.DEFAULT_COMMENT_MESSAGE;
|
|
13
|
-
return comment.suggestion
|
|
14
|
-
? `${message}\n\n建议:${comment.suggestion}`
|
|
15
|
-
: message;
|
|
16
|
-
}
|
|
17
|
-
function buildApiUrl(env, suffix) {
|
|
18
|
-
if (!env.CI_API_V4_URL || !env.CI_PROJECT_ID || !env.CI_MERGE_REQUEST_IID) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const apiBase = env.CI_API_V4_URL.replace(/\/+$/, "");
|
|
22
|
-
const projectId = encodeURIComponent(env.CI_PROJECT_ID);
|
|
23
|
-
const mrIid = encodeURIComponent(env.CI_MERGE_REQUEST_IID);
|
|
24
|
-
return `${apiBase}/projects/${projectId}/merge_requests/${mrIid}${suffix}`;
|
|
25
|
-
}
|
|
26
|
-
async function fetchMergeRequest(token, env) {
|
|
27
|
-
const url = buildApiUrl(env, "");
|
|
28
|
-
if (!url)
|
|
29
|
-
return null;
|
|
30
|
-
try {
|
|
31
|
-
const resp = await gitlabFetch(url, {
|
|
32
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
33
|
-
});
|
|
34
|
-
if (!resp.ok) {
|
|
35
|
-
console.error(`[gitlab] merge request fetch failed status=${resp.status}`);
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return await (0, http_1.parseJsonSafe)(resp);
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
console.error(`[gitlab] merge request fetch error: ${err instanceof Error ? err.message : err}`);
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function fetchCurrentUser(token, env) {
|
|
46
|
-
const apiBase = env.CI_API_V4_URL?.replace(/\/+$/, "");
|
|
47
|
-
if (!apiBase)
|
|
48
|
-
return null;
|
|
49
|
-
try {
|
|
50
|
-
const resp = await gitlabFetch(`${apiBase}/user`, {
|
|
51
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
52
|
-
});
|
|
53
|
-
if (!resp.ok) {
|
|
54
|
-
console.error(`[gitlab] fetch current user failed status=${resp.status}`);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return await (0, http_1.parseJsonSafe)(resp);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
console.error(`[gitlab] fetch current user error: ${err instanceof Error ? err.message : err}`);
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async function fetchAllPages(url, token) {
|
|
65
|
-
const results = [];
|
|
66
|
-
let page = 1;
|
|
67
|
-
while (page <= constants_1.MAX_PAGINATION_PAGES) {
|
|
68
|
-
const sep = url.includes("?") ? "&" : "?";
|
|
69
|
-
let resp;
|
|
70
|
-
try {
|
|
71
|
-
resp = await gitlabFetch(`${url}${sep}per_page=100&page=${page}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
console.error(`[gitlab] pagination request failed page=${page}`);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
if (!resp.ok)
|
|
78
|
-
break;
|
|
79
|
-
const items = await (0, http_1.parseJsonSafe)(resp);
|
|
80
|
-
if (!items?.length)
|
|
81
|
-
break;
|
|
82
|
-
results.push(...items);
|
|
83
|
-
if (items.length < 100)
|
|
84
|
-
break;
|
|
85
|
-
page += 1;
|
|
86
|
-
}
|
|
87
|
-
return results;
|
|
88
|
-
}
|
|
89
|
-
async function cleanupBotComments(options) {
|
|
90
|
-
const env = options.env ?? process.env;
|
|
91
|
-
if (!options.token) {
|
|
92
|
-
console.error("[gitlab] cleanup skipped: missing GitLab token");
|
|
93
|
-
return 0;
|
|
94
|
-
}
|
|
95
|
-
const discussionUrl = buildApiUrl(env, "/discussions");
|
|
96
|
-
if (!discussionUrl) {
|
|
97
|
-
console.error("[gitlab] cleanup skipped: missing GitLab CI context");
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
|
-
const user = await fetchCurrentUser(options.token, env);
|
|
101
|
-
if (!user) {
|
|
102
|
-
console.error("[gitlab] cleanup skipped: cannot determine bot user");
|
|
103
|
-
return 0;
|
|
104
|
-
}
|
|
105
|
-
console.error(`[gitlab] cleanup bot user=${user.username} (id=${user.id})`);
|
|
106
|
-
const discussions = await fetchAllPages(discussionUrl, options.token);
|
|
107
|
-
const toDelete = [];
|
|
108
|
-
for (const discussion of discussions) {
|
|
109
|
-
for (const note of discussion.notes) {
|
|
110
|
-
if (note.author.id !== user.id || note.system)
|
|
111
|
-
continue;
|
|
112
|
-
toDelete.push({ discussionId: discussion.id, noteId: note.id });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
let deleted = 0;
|
|
116
|
-
await (0, http_1.mapConcurrent)(toDelete, GITLAB_API_CONCURRENCY, async ({ discussionId, noteId }) => {
|
|
117
|
-
const deleteUrl = `${discussionUrl}/${discussionId}/notes/${noteId}`;
|
|
118
|
-
try {
|
|
119
|
-
const resp = await gitlabFetch(deleteUrl, {
|
|
120
|
-
method: "DELETE",
|
|
121
|
-
headers: { Authorization: `Bearer ${options.token}` },
|
|
122
|
-
});
|
|
123
|
-
if (resp.ok || resp.status === 204) {
|
|
124
|
-
deleted += 1;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
console.error(`[gitlab] delete note failed discussion=${discussionId} note=${noteId} status=${resp.status}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
console.error(`[gitlab] delete note error discussion=${discussionId} note=${noteId}: ${err instanceof Error ? err.message : err}`);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
console.error(`[gitlab] cleanup complete deleted=${deleted}`);
|
|
135
|
-
return deleted;
|
|
136
|
-
}
|
|
137
|
-
async function postGitlabDiscussions(options) {
|
|
138
|
-
const env = options.env ?? process.env;
|
|
139
|
-
if (options.comments.length === 0) {
|
|
140
|
-
console.error("[gitlab] MR discussions skipped: no diagnostics");
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
if (!options.token) {
|
|
144
|
-
console.error("[gitlab] MR discussions skipped: missing GitLab token");
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
const discussionUrl = buildApiUrl(env, "/discussions");
|
|
148
|
-
if (!discussionUrl) {
|
|
149
|
-
console.error("[gitlab] MR discussions skipped: missing GitLab CI context");
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
const mr = await fetchMergeRequest(options.token, env);
|
|
153
|
-
const refs = mr?.diff_refs;
|
|
154
|
-
if (!refs?.base_sha || !refs.start_sha || !refs.head_sha) {
|
|
155
|
-
console.error("[gitlab] MR discussions skipped: missing diff refs");
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
const validComments = options.comments.filter((c) => c.file && c.line);
|
|
159
|
-
let posted = 0;
|
|
160
|
-
await (0, http_1.mapConcurrent)(validComments, GITLAB_API_CONCURRENCY, async (comment) => {
|
|
161
|
-
try {
|
|
162
|
-
const resp = await gitlabFetch(discussionUrl, {
|
|
163
|
-
method: "POST",
|
|
164
|
-
headers: {
|
|
165
|
-
"Content-Type": "application/json",
|
|
166
|
-
Authorization: `Bearer ${options.token}`,
|
|
167
|
-
},
|
|
168
|
-
body: JSON.stringify({
|
|
169
|
-
body: buildCommentBody(comment),
|
|
170
|
-
position: {
|
|
171
|
-
base_sha: refs.base_sha,
|
|
172
|
-
start_sha: refs.start_sha,
|
|
173
|
-
head_sha: refs.head_sha,
|
|
174
|
-
position_type: "text",
|
|
175
|
-
new_path: comment.file,
|
|
176
|
-
new_line: Number(comment.line),
|
|
177
|
-
},
|
|
178
|
-
}),
|
|
179
|
-
});
|
|
180
|
-
if (!resp.ok) {
|
|
181
|
-
console.error(`[gitlab] MR discussion failed file=${comment.file} line=${comment.line} status=${resp.status}`);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
posted += 1;
|
|
185
|
-
}
|
|
186
|
-
catch (err) {
|
|
187
|
-
console.error(`[gitlab] MR discussion error file=${comment.file} line=${comment.line}: ${err instanceof Error ? err.message : err}`);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
console.error(`[gitlab] MR discussions posted count=${posted}`);
|
|
191
|
-
return posted > 0;
|
|
192
|
-
}
|
|
193
|
-
//# sourceMappingURL=gitlab.js.map
|