Skip to content

Commit 7b149c5

Browse files
committed
feature-296-bugbot-autofix: Refactor bugbot fix intent handling by extracting payload functions into a separate module, enhancing code organization and maintainability in issue comment processing.
1 parent 695bb09 commit 7b149c5

File tree

11 files changed

+559
-101
lines changed

11 files changed

+559
-101
lines changed

build/cli/index.js

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53294,19 +53294,7 @@ const bugbot_autofix_use_case_1 = __nccwpck_require__(4570);
5329453294
const bugbot_autofix_commit_1 = __nccwpck_require__(6263);
5329553295
const mark_findings_resolved_use_case_1 = __nccwpck_require__(61);
5329653296
const marker_1 = __nccwpck_require__(2401);
53297-
function getBugbotFixIntentPayload(results) {
53298-
const last = results[results.length - 1];
53299-
const payload = last?.payload;
53300-
if (!payload || typeof payload !== "object")
53301-
return undefined;
53302-
return payload;
53303-
}
53304-
function canRunBugbotAutofix(payload) {
53305-
return (!!payload?.isFixRequest &&
53306-
Array.isArray(payload.targetFindingIds) &&
53307-
payload.targetFindingIds.length > 0 &&
53308-
!!payload.context);
53309-
}
53297+
const bugbot_fix_intent_payload_1 = __nccwpck_require__(2528);
5331053298
class IssueCommentUseCase {
5331153299
constructor() {
5331253300
this.taskId = "IssueCommentUseCase";
@@ -53318,8 +53306,8 @@ class IssueCommentUseCase {
5331853306
(0, logger_1.logInfo)("Running bugbot fix intent detection (before Think).");
5331953307
const intentResults = await new detect_bugbot_fix_intent_use_case_1.DetectBugbotFixIntentUseCase().invoke(param);
5332053308
results.push(...intentResults);
53321-
const intentPayload = getBugbotFixIntentPayload(intentResults);
53322-
const runAutofix = canRunBugbotAutofix(intentPayload);
53309+
const intentPayload = (0, bugbot_fix_intent_payload_1.getBugbotFixIntentPayload)(intentResults);
53310+
const runAutofix = (0, bugbot_fix_intent_payload_1.canRunBugbotAutofix)(intentPayload);
5332353311
if (intentPayload) {
5332453312
(0, logger_1.logInfo)(`Bugbot fix intent: isFixRequest=${intentPayload.isFixRequest}, targetFindingIds=${intentPayload.targetFindingIds?.length ?? 0}.`);
5332553313
}
@@ -53474,12 +53462,14 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5347453462
exports.PullRequestReviewCommentUseCase = void 0;
5347553463
const logger_1 = __nccwpck_require__(8836);
5347653464
const task_emoji_1 = __nccwpck_require__(9785);
53465+
const think_use_case_1 = __nccwpck_require__(3841);
5347753466
const check_pull_request_comment_language_use_case_1 = __nccwpck_require__(7112);
5347853467
const detect_bugbot_fix_intent_use_case_1 = __nccwpck_require__(5289);
5347953468
const bugbot_autofix_use_case_1 = __nccwpck_require__(4570);
5348053469
const bugbot_autofix_commit_1 = __nccwpck_require__(6263);
5348153470
const mark_findings_resolved_use_case_1 = __nccwpck_require__(61);
5348253471
const marker_1 = __nccwpck_require__(2401);
53472+
const bugbot_fix_intent_payload_1 = __nccwpck_require__(2528);
5348353473
class PullRequestReviewCommentUseCase {
5348453474
constructor() {
5348553475
this.taskId = "PullRequestReviewCommentUseCase";
@@ -53488,38 +53478,60 @@ class PullRequestReviewCommentUseCase {
5348853478
(0, logger_1.logInfo)(`${(0, task_emoji_1.getTaskEmoji)(this.taskId)} Executing ${this.taskId}.`);
5348953479
const results = [];
5349053480
results.push(...(await new check_pull_request_comment_language_use_case_1.CheckPullRequestCommentLanguageUseCase().invoke(param)));
53481+
(0, logger_1.logInfo)("Running bugbot fix intent detection (before Think).");
5349153482
const intentResults = await new detect_bugbot_fix_intent_use_case_1.DetectBugbotFixIntentUseCase().invoke(param);
5349253483
results.push(...intentResults);
53493-
const intentPayload = intentResults[intentResults.length - 1]?.payload;
53494-
if (intentPayload?.isFixRequest &&
53495-
Array.isArray(intentPayload.targetFindingIds) &&
53496-
intentPayload.targetFindingIds.length > 0 &&
53497-
intentPayload.context) {
53484+
const intentPayload = (0, bugbot_fix_intent_payload_1.getBugbotFixIntentPayload)(intentResults);
53485+
const runAutofix = (0, bugbot_fix_intent_payload_1.canRunBugbotAutofix)(intentPayload);
53486+
if (intentPayload) {
53487+
(0, logger_1.logInfo)(`Bugbot fix intent: isFixRequest=${intentPayload.isFixRequest}, targetFindingIds=${intentPayload.targetFindingIds?.length ?? 0}.`);
53488+
}
53489+
else {
53490+
(0, logger_1.logInfo)("Bugbot fix intent: no payload from intent detection.");
53491+
}
53492+
if (runAutofix && intentPayload) {
53493+
const payload = intentPayload;
53494+
(0, logger_1.logInfo)("Running bugbot autofix.");
5349853495
const userComment = param.pullRequest.commentBody ?? "";
5349953496
const autofixResults = await new bugbot_autofix_use_case_1.BugbotAutofixUseCase().invoke({
5350053497
execution: param,
53501-
targetFindingIds: intentPayload.targetFindingIds,
53498+
targetFindingIds: payload.targetFindingIds,
5350253499
userComment,
53503-
context: intentPayload.context,
53504-
branchOverride: intentPayload.branchOverride,
53500+
context: payload.context,
53501+
branchOverride: payload.branchOverride,
5350553502
});
5350653503
results.push(...autofixResults);
5350753504
const lastAutofix = autofixResults[autofixResults.length - 1];
5350853505
if (lastAutofix?.success) {
53506+
(0, logger_1.logInfo)("Bugbot autofix succeeded; running commit and push.");
5350953507
const commitResult = await (0, bugbot_autofix_commit_1.runBugbotAutofixCommitAndPush)(param, {
53510-
branchOverride: intentPayload.branchOverride,
53508+
branchOverride: payload.branchOverride,
5351153509
});
53512-
if (commitResult.committed && intentPayload.context) {
53513-
const ids = intentPayload.targetFindingIds;
53510+
if (commitResult.committed && payload.context) {
53511+
const ids = payload.targetFindingIds;
5351453512
const normalized = new Set(ids.map(marker_1.sanitizeFindingIdForMarker));
5351553513
await (0, mark_findings_resolved_use_case_1.markFindingsResolved)({
5351653514
execution: param,
53517-
context: intentPayload.context,
53515+
context: payload.context,
5351853516
resolvedFindingIds: new Set(ids),
5351953517
normalizedResolvedIds: normalized,
5352053518
});
53519+
(0, logger_1.logInfo)(`Marked ${ids.length} finding(s) as resolved.`);
53520+
}
53521+
else if (!commitResult.committed) {
53522+
(0, logger_1.logInfo)("No commit performed (no changes or error).");
5352153523
}
5352253524
}
53525+
else {
53526+
(0, logger_1.logInfo)("Bugbot autofix did not succeed; skipping commit.");
53527+
}
53528+
}
53529+
else {
53530+
(0, logger_1.logInfo)("Skipping bugbot autofix (no fix request, no targets, or no context).");
53531+
}
53532+
if (!runAutofix) {
53533+
(0, logger_1.logInfo)("Running ThinkUseCase (comment was not a bugbot fix request).");
53534+
results.push(...(await new think_use_case_1.ThinkUseCase().invoke(param)));
5352353535
}
5352453536
return results;
5352553537
}
@@ -53936,6 +53948,31 @@ class BugbotAutofixUseCase {
5393653948
exports.BugbotAutofixUseCase = BugbotAutofixUseCase;
5393753949

5393853950

53951+
/***/ }),
53952+
53953+
/***/ 2528:
53954+
/***/ ((__unused_webpack_module, exports) => {
53955+
53956+
"use strict";
53957+
53958+
Object.defineProperty(exports, "__esModule", ({ value: true }));
53959+
exports.getBugbotFixIntentPayload = getBugbotFixIntentPayload;
53960+
exports.canRunBugbotAutofix = canRunBugbotAutofix;
53961+
function getBugbotFixIntentPayload(results) {
53962+
const last = results[results.length - 1];
53963+
const payload = last?.payload;
53964+
if (!payload || typeof payload !== "object")
53965+
return undefined;
53966+
return payload;
53967+
}
53968+
function canRunBugbotAutofix(payload) {
53969+
return (!!payload?.isFixRequest &&
53970+
Array.isArray(payload.targetFindingIds) &&
53971+
payload.targetFindingIds.length > 0 &&
53972+
!!payload.context);
53973+
}
53974+
53975+
5393953976
/***/ }),
5394053977

5394153978
/***/ 7960:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Result } from "../../../../data/model/result";
2+
import type { MarkFindingsResolvedParam } from "./mark_findings_resolved_use_case";
3+
export type BugbotFixIntentPayload = {
4+
isFixRequest: boolean;
5+
targetFindingIds: string[];
6+
context?: MarkFindingsResolvedParam["context"];
7+
branchOverride?: string;
8+
};
9+
export declare function getBugbotFixIntentPayload(results: Result[]): BugbotFixIntentPayload | undefined;
10+
export declare function canRunBugbotAutofix(payload: BugbotFixIntentPayload | undefined): payload is BugbotFixIntentPayload & {
11+
context: NonNullable<BugbotFixIntentPayload["context"]>;
12+
};

build/github_action/index.js

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48385,19 +48385,7 @@ const bugbot_autofix_use_case_1 = __nccwpck_require__(4570);
4838548385
const bugbot_autofix_commit_1 = __nccwpck_require__(6263);
4838648386
const mark_findings_resolved_use_case_1 = __nccwpck_require__(61);
4838748387
const marker_1 = __nccwpck_require__(2401);
48388-
function getBugbotFixIntentPayload(results) {
48389-
const last = results[results.length - 1];
48390-
const payload = last?.payload;
48391-
if (!payload || typeof payload !== "object")
48392-
return undefined;
48393-
return payload;
48394-
}
48395-
function canRunBugbotAutofix(payload) {
48396-
return (!!payload?.isFixRequest &&
48397-
Array.isArray(payload.targetFindingIds) &&
48398-
payload.targetFindingIds.length > 0 &&
48399-
!!payload.context);
48400-
}
48388+
const bugbot_fix_intent_payload_1 = __nccwpck_require__(2528);
4840148389
class IssueCommentUseCase {
4840248390
constructor() {
4840348391
this.taskId = "IssueCommentUseCase";
@@ -48409,8 +48397,8 @@ class IssueCommentUseCase {
4840948397
(0, logger_1.logInfo)("Running bugbot fix intent detection (before Think).");
4841048398
const intentResults = await new detect_bugbot_fix_intent_use_case_1.DetectBugbotFixIntentUseCase().invoke(param);
4841148399
results.push(...intentResults);
48412-
const intentPayload = getBugbotFixIntentPayload(intentResults);
48413-
const runAutofix = canRunBugbotAutofix(intentPayload);
48400+
const intentPayload = (0, bugbot_fix_intent_payload_1.getBugbotFixIntentPayload)(intentResults);
48401+
const runAutofix = (0, bugbot_fix_intent_payload_1.canRunBugbotAutofix)(intentPayload);
4841448402
if (intentPayload) {
4841548403
(0, logger_1.logInfo)(`Bugbot fix intent: isFixRequest=${intentPayload.isFixRequest}, targetFindingIds=${intentPayload.targetFindingIds?.length ?? 0}.`);
4841648404
}
@@ -48565,12 +48553,14 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4856548553
exports.PullRequestReviewCommentUseCase = void 0;
4856648554
const logger_1 = __nccwpck_require__(8836);
4856748555
const task_emoji_1 = __nccwpck_require__(9785);
48556+
const think_use_case_1 = __nccwpck_require__(3841);
4856848557
const check_pull_request_comment_language_use_case_1 = __nccwpck_require__(7112);
4856948558
const detect_bugbot_fix_intent_use_case_1 = __nccwpck_require__(5289);
4857048559
const bugbot_autofix_use_case_1 = __nccwpck_require__(4570);
4857148560
const bugbot_autofix_commit_1 = __nccwpck_require__(6263);
4857248561
const mark_findings_resolved_use_case_1 = __nccwpck_require__(61);
4857348562
const marker_1 = __nccwpck_require__(2401);
48563+
const bugbot_fix_intent_payload_1 = __nccwpck_require__(2528);
4857448564
class PullRequestReviewCommentUseCase {
4857548565
constructor() {
4857648566
this.taskId = "PullRequestReviewCommentUseCase";
@@ -48579,38 +48569,60 @@ class PullRequestReviewCommentUseCase {
4857948569
(0, logger_1.logInfo)(`${(0, task_emoji_1.getTaskEmoji)(this.taskId)} Executing ${this.taskId}.`);
4858048570
const results = [];
4858148571
results.push(...(await new check_pull_request_comment_language_use_case_1.CheckPullRequestCommentLanguageUseCase().invoke(param)));
48572+
(0, logger_1.logInfo)("Running bugbot fix intent detection (before Think).");
4858248573
const intentResults = await new detect_bugbot_fix_intent_use_case_1.DetectBugbotFixIntentUseCase().invoke(param);
4858348574
results.push(...intentResults);
48584-
const intentPayload = intentResults[intentResults.length - 1]?.payload;
48585-
if (intentPayload?.isFixRequest &&
48586-
Array.isArray(intentPayload.targetFindingIds) &&
48587-
intentPayload.targetFindingIds.length > 0 &&
48588-
intentPayload.context) {
48575+
const intentPayload = (0, bugbot_fix_intent_payload_1.getBugbotFixIntentPayload)(intentResults);
48576+
const runAutofix = (0, bugbot_fix_intent_payload_1.canRunBugbotAutofix)(intentPayload);
48577+
if (intentPayload) {
48578+
(0, logger_1.logInfo)(`Bugbot fix intent: isFixRequest=${intentPayload.isFixRequest}, targetFindingIds=${intentPayload.targetFindingIds?.length ?? 0}.`);
48579+
}
48580+
else {
48581+
(0, logger_1.logInfo)("Bugbot fix intent: no payload from intent detection.");
48582+
}
48583+
if (runAutofix && intentPayload) {
48584+
const payload = intentPayload;
48585+
(0, logger_1.logInfo)("Running bugbot autofix.");
4858948586
const userComment = param.pullRequest.commentBody ?? "";
4859048587
const autofixResults = await new bugbot_autofix_use_case_1.BugbotAutofixUseCase().invoke({
4859148588
execution: param,
48592-
targetFindingIds: intentPayload.targetFindingIds,
48589+
targetFindingIds: payload.targetFindingIds,
4859348590
userComment,
48594-
context: intentPayload.context,
48595-
branchOverride: intentPayload.branchOverride,
48591+
context: payload.context,
48592+
branchOverride: payload.branchOverride,
4859648593
});
4859748594
results.push(...autofixResults);
4859848595
const lastAutofix = autofixResults[autofixResults.length - 1];
4859948596
if (lastAutofix?.success) {
48597+
(0, logger_1.logInfo)("Bugbot autofix succeeded; running commit and push.");
4860048598
const commitResult = await (0, bugbot_autofix_commit_1.runBugbotAutofixCommitAndPush)(param, {
48601-
branchOverride: intentPayload.branchOverride,
48599+
branchOverride: payload.branchOverride,
4860248600
});
48603-
if (commitResult.committed && intentPayload.context) {
48604-
const ids = intentPayload.targetFindingIds;
48601+
if (commitResult.committed && payload.context) {
48602+
const ids = payload.targetFindingIds;
4860548603
const normalized = new Set(ids.map(marker_1.sanitizeFindingIdForMarker));
4860648604
await (0, mark_findings_resolved_use_case_1.markFindingsResolved)({
4860748605
execution: param,
48608-
context: intentPayload.context,
48606+
context: payload.context,
4860948607
resolvedFindingIds: new Set(ids),
4861048608
normalizedResolvedIds: normalized,
4861148609
});
48610+
(0, logger_1.logInfo)(`Marked ${ids.length} finding(s) as resolved.`);
48611+
}
48612+
else if (!commitResult.committed) {
48613+
(0, logger_1.logInfo)("No commit performed (no changes or error).");
4861248614
}
4861348615
}
48616+
else {
48617+
(0, logger_1.logInfo)("Bugbot autofix did not succeed; skipping commit.");
48618+
}
48619+
}
48620+
else {
48621+
(0, logger_1.logInfo)("Skipping bugbot autofix (no fix request, no targets, or no context).");
48622+
}
48623+
if (!runAutofix) {
48624+
(0, logger_1.logInfo)("Running ThinkUseCase (comment was not a bugbot fix request).");
48625+
results.push(...(await new think_use_case_1.ThinkUseCase().invoke(param)));
4861448626
}
4861548627
return results;
4861648628
}
@@ -49027,6 +49039,31 @@ class BugbotAutofixUseCase {
4902749039
exports.BugbotAutofixUseCase = BugbotAutofixUseCase;
4902849040

4902949041

49042+
/***/ }),
49043+
49044+
/***/ 2528:
49045+
/***/ ((__unused_webpack_module, exports) => {
49046+
49047+
"use strict";
49048+
49049+
Object.defineProperty(exports, "__esModule", ({ value: true }));
49050+
exports.getBugbotFixIntentPayload = getBugbotFixIntentPayload;
49051+
exports.canRunBugbotAutofix = canRunBugbotAutofix;
49052+
function getBugbotFixIntentPayload(results) {
49053+
const last = results[results.length - 1];
49054+
const payload = last?.payload;
49055+
if (!payload || typeof payload !== "object")
49056+
return undefined;
49057+
return payload;
49058+
}
49059+
function canRunBugbotAutofix(payload) {
49060+
return (!!payload?.isFixRequest &&
49061+
Array.isArray(payload.targetFindingIds) &&
49062+
payload.targetFindingIds.length > 0 &&
49063+
!!payload.context);
49064+
}
49065+
49066+
4903049067
/***/ }),
4903149068

4903249069
/***/ 7960:

build/github_action/src/data/repository/branch_repository.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export declare class BranchRepository {
3333
totalCommits: number;
3434
files: {
3535
filename: string;
36-
status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
36+
status: "modified" | "added" | "removed" | "renamed" | "copied" | "changed" | "unchanged";
3737
additions: number;
3838
deletions: number;
3939
changes: number;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Result } from "../../../../data/model/result";
2+
import type { MarkFindingsResolvedParam } from "./mark_findings_resolved_use_case";
3+
export type BugbotFixIntentPayload = {
4+
isFixRequest: boolean;
5+
targetFindingIds: string[];
6+
context?: MarkFindingsResolvedParam["context"];
7+
branchOverride?: string;
8+
};
9+
export declare function getBugbotFixIntentPayload(results: Result[]): BugbotFixIntentPayload | undefined;
10+
export declare function canRunBugbotAutofix(payload: BugbotFixIntentPayload | undefined): payload is BugbotFixIntentPayload & {
11+
context: NonNullable<BugbotFixIntentPayload["context"]>;
12+
};

0 commit comments

Comments
 (0)