Skip to content

Commit 9780ee5

Browse files
committed
cleaning up proposal template enforcement debug 1
1 parent ec79239 commit 9780ee5

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

.github/scripts/proposalPoliceComment.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ function isCommentEditedEvent(payload) {
105105
function run() {
106106
return __awaiter(this, void 0, void 0, function () {
107107
var now, zonedDate, formattedDate, octokit, payload, prompt, assistantResponse, parsedAssistantResponse, _a, _b, action, _c, message, isNoAction, isActionEdit, isActionRequired, formattedResponse, formattedResponse;
108-
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
109-
return __generator(this, function (_x) {
110-
switch (_x.label) {
108+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
109+
return __generator(this, function (_y) {
110+
switch (_y.label) {
111111
case 0:
112112
now = Date.now();
113113
zonedDate = (0, date_fns_tz_1.utcToZonedTime)(now, 'UTC');
@@ -144,7 +144,7 @@ function run() {
144144
: "I NEED HELP WITH CASE (2.) WHEN A USER THAT POSTED AN INITIAL PROPOSAL OR COMMENT (UNEDITED) THEN EDITS THE COMMENT - WE NEED TO CLASSIFY THE COMMENT BASED IN THE GIVEN INSTRUCTIONS AND IF TEMPLATE IS FOLLOWED AS PER INSTRUCTIONS. IT IS MANDATORY THAT YOU RESPOND ONLY WITH \"".concat(CONST_1.default.NO_ACTION, "\" IN CASE THE COMMENT IS NOT A PROPOSAL. \n\nPrevious comment content: ").concat((_o = payload.changes.body) === null || _o === void 0 ? void 0 : _o.from, ".\n\nEdited comment content: ").concat((_p = payload.comment) === null || _p === void 0 ? void 0 : _p.body);
145145
return [4 /*yield*/, OpenAIUtils_1.default.prompt(prompt)];
146146
case 1:
147-
assistantResponse = _x.sent();
147+
assistantResponse = _y.sent();
148148
parsedAssistantResponse = JSON.parse(sanitizeJSONStringValues(assistantResponse));
149149
console.log('parsedAssistantResponse: ', parsedAssistantResponse);
150150
_a = parsedAssistantResponse !== null && parsedAssistantResponse !== void 0 ? parsedAssistantResponse : {}, _b = _a.action, action = _b === void 0 ? "" : _b, _c = _a.message, message = _c === void 0 ? "" : _c;
@@ -157,33 +157,30 @@ function run() {
157157
return [2 /*return*/];
158158
}
159159
if (!(isCommentCreatedEvent(payload) && isActionRequired)) return [3 /*break*/, 3];
160+
console.log('payload.comment?.url', (_q = payload.comment) === null || _q === void 0 ? void 0 : _q.url);
161+
console.log('payload.comment?.html_url', (_r = payload.comment) === null || _r === void 0 ? void 0 : _r.html_url);
160162
formattedResponse = message
161-
// replace {user} from response template with @username
162-
// @ts-ignore - process is not imported
163-
.replaceAll('{user}', "@".concat((_q = payload.comment) === null || _q === void 0 ? void 0 : _q.user.login))
164-
// replace {proposalLink} from response template with the link to the comment
165-
.replaceAll('{proposalLink}', (_r = payload.comment) === null || _r === void 0 ? void 0 : _r.html_url)
166-
// remove any double quotes from the final comment because sometimes the assistant's
167-
// response contains double quotes / sometimes it doesn't
168-
.replaceAll('"', '');
163+
// replace {user} from response template with GH @username
164+
// @ts-ignore - replaceAll exists
165+
.replaceAll('{user}', "@".concat((_s = payload.comment) === null || _s === void 0 ? void 0 : _s.user.login));
169166
// Create a comment with the assistant's response
170167
console.log('ProposalPolice™ commenting on issue...');
171168
return [4 /*yield*/, octokit.issues.createComment(__assign(__assign({}, github_1.context.repo), {
172169
/* eslint-disable @typescript-eslint/naming-convention */
173-
issue_number: (_t = (_s = payload.issue) === null || _s === void 0 ? void 0 : _s.number) !== null && _t !== void 0 ? _t : -1, body: formattedResponse }))];
170+
issue_number: (_u = (_t = payload.issue) === null || _t === void 0 ? void 0 : _t.number) !== null && _u !== void 0 ? _u : -1, body: formattedResponse }))];
174171
case 2:
175-
_x.sent();
172+
_y.sent();
176173
return [3 /*break*/, 5];
177174
case 3:
178175
if (!isActionEdit) return [3 /*break*/, 5];
179176
formattedResponse = message.replace('{updated_timestamp}', formattedDate);
180177
console.log('ProposalPolice™ editing issue comment...', payload.comment.id);
181178
return [4 /*yield*/, octokit.issues.updateComment(__assign(__assign({}, github_1.context.repo), {
182179
/* eslint-disable @typescript-eslint/naming-convention */
183-
comment_id: (_v = (_u = payload.comment) === null || _u === void 0 ? void 0 : _u.id) !== null && _v !== void 0 ? _v : -1, body: "".concat(formattedResponse, "\n\n").concat((_w = payload.comment) === null || _w === void 0 ? void 0 : _w.body) }))];
180+
comment_id: (_w = (_v = payload.comment) === null || _v === void 0 ? void 0 : _v.id) !== null && _w !== void 0 ? _w : -1, body: "".concat(formattedResponse, "\n\n").concat((_x = payload.comment) === null || _x === void 0 ? void 0 : _x.body) }))];
184181
case 4:
185-
_x.sent();
186-
_x.label = 5;
182+
_y.sent();
183+
_y.label = 5;
187184
case 5: return [2 /*return*/];
188185
}
189186
});

.github/scripts/proposalPoliceComment.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,12 @@ async function run() {
128128
}
129129

130130
if (isCommentCreatedEvent(payload) && isActionRequired) {
131+
console.log('payload.comment?.url', payload.comment?.url);
132+
console.log('payload.comment?.html_url', payload.comment?.html_url);
131133
const formattedResponse = message
132-
// replace {user} from response template with @username
133-
// @ts-ignore - process is not imported
134-
.replaceAll('{user}', `@${payload.comment?.user.login}`)
135-
136-
// replace {proposalLink} from response template with the link to the comment
137-
.replaceAll('{proposalLink}', payload.comment?.html_url)
138-
139-
// remove any double quotes from the final comment because sometimes the assistant's
140-
// response contains double quotes / sometimes it doesn't
141-
.replaceAll('"', '');
134+
// replace {user} from response template with GH @username
135+
// @ts-ignore - replaceAll exists
136+
.replaceAll('{user}', `@${payload.comment?.user.login}`);
142137

143138
// Create a comment with the assistant's response
144139
console.log('ProposalPolice™ commenting on issue...');

0 commit comments

Comments
 (0)