Skip to content

Commit d64a874

Browse files
committed
bugfix-314-error-merging-release-branch-after-successful-deployment: Enhance IssueRepository and publishFindings functionality to support commit SHA watermarks in comments. Updated addComment and updateComment methods to accept an options parameter for commitSha, allowing comments to include a link to the specific commit. Adjusted related tests to verify the inclusion of watermarks in comment bodies.
1 parent b199bde commit d64a874

File tree

16 files changed

+324
-53
lines changed

16 files changed

+324
-53
lines changed

build/cli/index.js

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50335,6 +50335,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5033550335
exports.IssueRepository = exports.PROGRESS_LABEL_PATTERN = void 0;
5033650336
const core = __importStar(__nccwpck_require__(2186));
5033750337
const github = __importStar(__nccwpck_require__(5438));
50338+
const comment_watermark_1 = __nccwpck_require__(4467);
5033850339
const logger_1 = __nccwpck_require__(8836);
5033950340
const milestone_1 = __nccwpck_require__(2298);
5034050341
/** Matches labels that are progress percentages (e.g. "0%", "85%"). Used for setProgressLabel and syncing. */
@@ -50691,23 +50692,27 @@ class IssueRepository {
5069150692
});
5069250693
return pullRequest.data.head.ref;
5069350694
};
50694-
this.addComment = async (owner, repository, issueNumber, comment, token) => {
50695+
this.addComment = async (owner, repository, issueNumber, comment, token, options) => {
50696+
const watermark = (0, comment_watermark_1.getCommentWatermark)(options?.commitSha ? { commitSha: options.commitSha, owner, repo: repository } : undefined);
50697+
const body = `${comment}\n\n${watermark}`;
5069550698
const octokit = github.getOctokit(token);
5069650699
await octokit.rest.issues.createComment({
5069750700
owner: owner,
5069850701
repo: repository,
5069950702
issue_number: issueNumber,
50700-
body: comment,
50703+
body,
5070150704
});
5070250705
(0, logger_1.logDebugInfo)(`Comment added to Issue ${issueNumber}.`);
5070350706
};
50704-
this.updateComment = async (owner, repository, issueNumber, commentId, comment, token) => {
50707+
this.updateComment = async (owner, repository, issueNumber, commentId, comment, token, options) => {
50708+
const watermark = (0, comment_watermark_1.getCommentWatermark)(options?.commitSha ? { commitSha: options.commitSha, owner, repo: repository } : undefined);
50709+
const body = `${comment}\n\n${watermark}`;
5070550710
const octokit = github.getOctokit(token);
5070650711
await octokit.rest.issues.updateComment({
5070750712
owner: owner,
5070850713
repo: repository,
5070950714
comment_id: commentId,
50710-
body: comment,
50715+
body,
5071150716
});
5071250717
(0, logger_1.logDebugInfo)(`Comment ${commentId} updated in Issue ${issueNumber}.`);
5071350718
};
@@ -56273,31 +56278,36 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5627356278
exports.publishFindings = publishFindings;
5627456279
const issue_repository_1 = __nccwpck_require__(57);
5627556280
const pull_request_repository_1 = __nccwpck_require__(634);
56281+
const comment_watermark_1 = __nccwpck_require__(4467);
5627656282
const logger_1 = __nccwpck_require__(8836);
5627756283
const marker_1 = __nccwpck_require__(2401);
5627856284
const path_validation_1 = __nccwpck_require__(1999);
5627956285
/** Creates or updates issue comments for each finding; creates PR review comments only when finding.file is in prFiles. */
5628056286
async function publishFindings(param) {
56281-
const { execution, context, findings, overflowCount = 0, overflowTitles = [] } = param;
56287+
const { execution, context, findings, commitSha, overflowCount = 0, overflowTitles = [] } = param;
5628256288
const { existingByFindingId, openPrNumbers, prContext } = context;
5628356289
const issueNumber = execution.issueNumber;
5628456290
const token = execution.tokens.token;
5628556291
const owner = execution.owner;
5628656292
const repo = execution.repo;
5628756293
const issueRepository = new issue_repository_1.IssueRepository();
5628856294
const pullRequestRepository = new pull_request_repository_1.PullRequestRepository();
56295+
const bugbotWatermark = commitSha && owner && repo
56296+
? (0, comment_watermark_1.getCommentWatermark)({ commitSha, owner, repo })
56297+
: (0, comment_watermark_1.getCommentWatermark)();
5628956298
const prFiles = prContext?.prFiles ?? [];
5629056299
const pathToFirstDiffLine = prContext?.pathToFirstDiffLine ?? {};
5629156300
const prCommentsToCreate = [];
5629256301
for (const finding of findings) {
5629356302
const existing = existingByFindingId[finding.id];
5629456303
const commentBody = (0, marker_1.buildCommentBody)(finding, false);
56304+
const bodyWithWatermark = `${commentBody}\n\n${bugbotWatermark}`;
5629556305
if (existing?.issueCommentId != null) {
56296-
await issueRepository.updateComment(owner, repo, issueNumber, existing.issueCommentId, commentBody, token);
56306+
await issueRepository.updateComment(owner, repo, issueNumber, existing.issueCommentId, commentBody, token, commitSha ? { commitSha } : undefined);
5629756307
(0, logger_1.logDebugInfo)(`Updated bugbot comment for finding ${finding.id} on issue.`);
5629856308
}
5629956309
else {
56300-
await issueRepository.addComment(owner, repo, issueNumber, commentBody, token);
56310+
await issueRepository.addComment(owner, repo, issueNumber, commentBody, token, commitSha ? { commitSha } : undefined);
5630156311
(0, logger_1.logDebugInfo)(`Added bugbot comment for finding ${finding.id} on issue.`);
5630256312
}
5630356313
// PR review comment: only if this finding's file is in the PR changed files (so GitHub can attach the comment).
@@ -56306,10 +56316,10 @@ async function publishFindings(param) {
5630656316
if (path) {
5630756317
const line = finding.line ?? pathToFirstDiffLine[path] ?? 1;
5630856318
if (existing?.prCommentId != null && existing.prNumber === openPrNumbers[0]) {
56309-
await pullRequestRepository.updatePullRequestReviewComment(owner, repo, existing.prCommentId, commentBody, token);
56319+
await pullRequestRepository.updatePullRequestReviewComment(owner, repo, existing.prCommentId, bodyWithWatermark, token);
5631056320
}
5631156321
else {
56312-
prCommentsToCreate.push({ path, line, body: commentBody });
56322+
prCommentsToCreate.push({ path, line, body: bodyWithWatermark });
5631356323
}
5631456324
}
5631556325
else if (finding.file != null && String(finding.file).trim() !== "") {
@@ -56327,7 +56337,7 @@ async function publishFindings(param) {
5632756337
const overflowBody = `## More findings (comment limit)
5632856338

5632956339
There are **${overflowCount}** more finding(s) that were not published as individual comments. Review locally or in the full diff to see the list.${titlesList}`;
56330-
await issueRepository.addComment(owner, repo, issueNumber, overflowBody, token);
56340+
await issueRepository.addComment(owner, repo, issueNumber, overflowBody, token, commitSha ? { commitSha } : undefined);
5633156341
(0, logger_1.logDebugInfo)(`Added overflow comment: ${overflowCount} additional finding(s) not published individually.`);
5633256342
}
5633356343
}
@@ -56587,12 +56597,46 @@ exports.CheckChangesIssueSizeUseCase = CheckChangesIssueSizeUseCase;
5658756597
/***/ }),
5658856598

5658956599
/***/ 7395:
56590-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
56600+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
5659156601

5659256602
"use strict";
5659356603

56604+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
56605+
if (k2 === undefined) k2 = k;
56606+
var desc = Object.getOwnPropertyDescriptor(m, k);
56607+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
56608+
desc = { enumerable: true, get: function() { return m[k]; } };
56609+
}
56610+
Object.defineProperty(o, k2, desc);
56611+
}) : (function(o, m, k, k2) {
56612+
if (k2 === undefined) k2 = k;
56613+
o[k2] = m[k];
56614+
}));
56615+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
56616+
Object.defineProperty(o, "default", { enumerable: true, value: v });
56617+
}) : function(o, v) {
56618+
o["default"] = v;
56619+
});
56620+
var __importStar = (this && this.__importStar) || (function () {
56621+
var ownKeys = function(o) {
56622+
ownKeys = Object.getOwnPropertyNames || function (o) {
56623+
var ar = [];
56624+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
56625+
return ar;
56626+
};
56627+
return ownKeys(o);
56628+
};
56629+
return function (mod) {
56630+
if (mod && mod.__esModule) return mod;
56631+
var result = {};
56632+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
56633+
__setModuleDefault(result, mod);
56634+
return result;
56635+
};
56636+
})();
5659456637
Object.defineProperty(exports, "__esModule", ({ value: true }));
5659556638
exports.DetectPotentialProblemsUseCase = void 0;
56639+
const github = __importStar(__nccwpck_require__(5438));
5659656640
const result_1 = __nccwpck_require__(7305);
5659756641
const ai_repository_1 = __nccwpck_require__(8307);
5659856642
const constants_1 = __nccwpck_require__(8593);
@@ -56671,6 +56715,7 @@ class DetectPotentialProblemsUseCase {
5667156715
execution: param,
5667256716
context,
5667356717
findings: toPublish,
56718+
commitSha: github.context.sha,
5667456719
overflowCount: overflowCount > 0 ? overflowCount : undefined,
5667556720
overflowTitles: overflowCount > 0 ? overflowTitles : undefined,
5667656721
});
@@ -59766,6 +59811,34 @@ ${this.translatedKey}
5976659811
exports.CheckPullRequestCommentLanguageUseCase = CheckPullRequestCommentLanguageUseCase;
5976759812

5976859813

59814+
/***/ }),
59815+
59816+
/***/ 4467:
59817+
/***/ ((__unused_webpack_module, exports) => {
59818+
59819+
"use strict";
59820+
59821+
/**
59822+
* Watermark appended to comments (issues and PRs) to attribute Copilot.
59823+
* Bugbot comments include commit link and note about auto-update on new commits.
59824+
*/
59825+
Object.defineProperty(exports, "__esModule", ({ value: true }));
59826+
exports.COPILOT_MARKETPLACE_URL = void 0;
59827+
exports.getCommentWatermark = getCommentWatermark;
59828+
exports.COPILOT_MARKETPLACE_URL = 'https://github.com/marketplace/actions/copilot-github-with-super-powers';
59829+
const DEFAULT_WATERMARK = `<sup>Made with ❤️ by [vypdev/copilot](${exports.COPILOT_MARKETPLACE_URL})</sup>`;
59830+
function commitUrl(owner, repo, sha) {
59831+
return `https://github.com/${owner}/${repo}/commit/${sha}`;
59832+
}
59833+
function getCommentWatermark(options) {
59834+
if (options?.commitSha && options?.owner && options?.repo) {
59835+
const url = commitUrl(options.owner, options.repo, options.commitSha);
59836+
return `<sup>Written by [vypdev/copilot](${exports.COPILOT_MARKETPLACE_URL}) for commit [${options.commitSha}](${url}). This will update automatically on new commits.</sup>`;
59837+
}
59838+
return DEFAULT_WATERMARK;
59839+
}
59840+
59841+
5976959842
/***/ }),
5977059843

5977159844
/***/ 8593:

build/cli/src/data/repository/issue_repository.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ export declare class IssueRepository {
3737
isIssue: (owner: string, repository: string, issueNumber: number, token: string) => Promise<boolean>;
3838
isPullRequest: (owner: string, repository: string, issueNumber: number, token: string) => Promise<boolean>;
3939
getHeadBranch: (owner: string, repository: string, issueNumber: number, token: string) => Promise<string | undefined>;
40-
addComment: (owner: string, repository: string, issueNumber: number, comment: string, token: string) => Promise<void>;
41-
updateComment: (owner: string, repository: string, issueNumber: number, commentId: number, comment: string, token: string) => Promise<void>;
40+
addComment: (owner: string, repository: string, issueNumber: number, comment: string, token: string, options?: {
41+
commitSha?: string;
42+
}) => Promise<void>;
43+
updateComment: (owner: string, repository: string, issueNumber: number, commentId: number, comment: string, token: string, options?: {
44+
commitSha?: string;
45+
}) => Promise<void>;
4246
/**
4347
* Lists all comments on an issue (for bugbot: find existing findings by marker).
4448
* Uses pagination to fetch every comment (default API returns only 30 per page).

build/cli/src/usecase/steps/commit/bugbot/publish_findings_use_case.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface PublishFindingsParam {
1212
execution: Execution;
1313
context: BugbotContext;
1414
findings: BugbotFinding[];
15+
/** Commit SHA for bugbot watermark (commit link). When set, comment uses "for commit ..." watermark. */
16+
commitSha?: string;
1517
/** When findings were limited by max comments, add one summary comment with this overflow info. */
1618
overflowCount?: number;
1719
overflowTitles?: string[];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Watermark appended to comments (issues and PRs) to attribute Copilot.
3+
* Bugbot comments include commit link and note about auto-update on new commits.
4+
*/
5+
export declare const COPILOT_MARKETPLACE_URL = "https://github.com/marketplace/actions/copilot-github-with-super-powers";
6+
export interface BugbotWatermarkOptions {
7+
commitSha: string;
8+
owner: string;
9+
repo: string;
10+
}
11+
export declare function getCommentWatermark(options?: BugbotWatermarkOptions): string;

0 commit comments

Comments
 (0)