Skip to content

Commit 1441748

Browse files
committed
date-fns
1 parent 06f0254 commit 1441748

File tree

6 files changed

+55
-32
lines changed

6 files changed

+55
-32
lines changed

.github/scripts/libs/OpenAIUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
var __generator = (this && this.__generator) || function (thisArg, body) {
12-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1414
function verb(n) { return function (v) { return step([n, v]); }; }
1515
function step(op) {
1616
if (f) throw new TypeError("Generator is already executing.");

.github/scripts/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
"@actions/github": "^4.0.0",
77
"@octokit/core": "^6.1.2",
88
"@octokit/rest": "^18.0.0",
9+
"date-fns": "^2.30.0",
10+
"date-fns-tz": "^2.0.0",
911
"@octokit/webhooks-types": "^7.5.1",
1012
"openai": "^4.24.7",
1113
"ts-node": "^10.9.2",
1214
"typescript": "^5.5.2"
1315
},
16+
"scripts": {
17+
"build": "tsc proposalPoliceComment.ts"
18+
},
1419
"license": "MIT"
1520
}

.github/scripts/proposalPoliceComment.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2020
});
2121
};
2222
var __generator = (this && this.__generator) || function (thisArg, body) {
23-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
23+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2525
function verb(n) { return function (v) { return step([n, v]); }; }
2626
function step(op) {
2727
if (f) throw new TypeError("Generator is already executing.");
@@ -49,6 +49,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4949
Object.defineProperty(exports, "__esModule", { value: true });
5050
var core_1 = require("@actions/core");
5151
var github_1 = require("@actions/github");
52+
var date_fns_1 = require("date-fns");
53+
var date_fns_tz_1 = require("date-fns-tz");
5254
var CONST_1 = require("./libs/CONST");
5355
var OpenAIUtils_1 = require("./libs/OpenAIUtils");
5456
function isCommentCreatedOrEditedEvent(payload) {
@@ -60,12 +62,14 @@ function isCommentCreatedEvent(payload) {
6062
// Main function to process the workflow event
6163
function run() {
6264
return __awaiter(this, void 0, void 0, function () {
63-
var date, octokit, payload, prompt, assistantResponse, isNoAction, noActionContext, formattedResponse, extractedNotice, formattedDate;
64-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
65-
return __generator(this, function (_0) {
66-
switch (_0.label) {
65+
var now, zonedDate, formattedDate, octokit, payload, prompt, assistantResponse, isNoAction, noActionContext, formattedResponse, extractedNotice;
66+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
67+
return __generator(this, function (_x) {
68+
switch (_x.label) {
6769
case 0:
68-
date = new Date();
70+
now = Date.now();
71+
zonedDate = (0, date_fns_tz_1.utcToZonedTime)(now, 'UTC');
72+
formattedDate = (0, date_fns_1.format)(zonedDate, "yyyy-MM-dd HH:mm:ss 'UTC'");
6973
octokit = (0, github_1.getOctokit)(process.env.GITHUB_TOKEN);
7074
// Verify this is running for an expected webhook event
7175
if (github_1.context.eventName !== CONST_1.default.EVENTS.ISSUE_COMMENT) {
@@ -93,7 +97,7 @@ function run() {
9397
: "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((_h = payload.changes.body) === null || _h === void 0 ? void 0 : _h.from, ".\n\nEdited comment content: ").concat((_j = payload.comment) === null || _j === void 0 ? void 0 : _j.body);
9498
return [4 /*yield*/, OpenAIUtils_1.default.prompt(prompt)];
9599
case 1:
96-
assistantResponse = _0.sent();
100+
assistantResponse = _x.sent();
97101
console.log('assistantResponse: ', assistantResponse);
98102
isNoAction = assistantResponse.trim().replaceAll(' ', '_').replaceAll('"', '').toUpperCase() === CONST_1.default.NO_ACTION;
99103
// If assistant response is NO_ACTION, do nothing
@@ -123,20 +127,19 @@ function run() {
123127
/* eslint-disable @typescript-eslint/naming-convention */
124128
issue_number: (_q = (_p = payload.issue) === null || _p === void 0 ? void 0 : _p.number) !== null && _q !== void 0 ? _q : -1, body: formattedResponse }))];
125129
case 2:
126-
_0.sent();
130+
_x.sent();
127131
return [3 /*break*/, 5];
128132
case 3:
129133
if (!(assistantResponse.includes('[EDIT_COMMENT]') && !((_r = payload.comment) === null || _r === void 0 ? void 0 : _r.body.includes('Edited by **proposal-police**')))) return [3 /*break*/, 5];
130134
extractedNotice = (_t = (_s = assistantResponse.split('[EDIT_COMMENT] ')) === null || _s === void 0 ? void 0 : _s[1]) === null || _t === void 0 ? void 0 : _t.replace('"', '');
131-
formattedDate = "".concat((_w = (_v = (_u = date.toISOString()) === null || _u === void 0 ? void 0 : _u.split('.')) === null || _v === void 0 ? void 0 : _v[0]) === null || _w === void 0 ? void 0 : _w.replace('T', ' '), " UTC");
132135
extractedNotice = extractedNotice.replace('{updated_timestamp}', formattedDate);
133136
console.log('ProposalPolice™ editing issue comment...', payload.comment.id);
134137
return [4 /*yield*/, octokit.issues.updateComment(__assign(__assign({}, github_1.context.repo), {
135138
/* eslint-disable @typescript-eslint/naming-convention */
136-
comment_id: (_y = (_x = payload.comment) === null || _x === void 0 ? void 0 : _x.id) !== null && _y !== void 0 ? _y : -1, body: "".concat(extractedNotice, "\n\n").concat((_z = payload.comment) === null || _z === void 0 ? void 0 : _z.body) }))];
139+
comment_id: (_v = (_u = payload.comment) === null || _u === void 0 ? void 0 : _u.id) !== null && _v !== void 0 ? _v : -1, body: "".concat(extractedNotice, "\n\n").concat((_w = payload.comment) === null || _w === void 0 ? void 0 : _w.body) }))];
137140
case 4:
138-
_0.sent();
139-
_0.label = 5;
141+
_x.sent();
142+
_x.label = 5;
140143
case 5: return [2 /*return*/];
141144
}
142145
});

.github/scripts/proposalPoliceComment.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import {setFailed} from '@actions/core';
22
import {context, getOctokit} from '@actions/github';
33
import type {IssueCommentCreatedEvent, IssueCommentEditedEvent, IssueCommentEvent} from '@octokit/webhooks-types';
4+
import {format} from 'date-fns';
5+
import {utcToZonedTime} from 'date-fns-tz';
46
import CONST from './libs/CONST';
57
import OpenAIUtils from './libs/OpenAIUtils';
68
import type {GitHubType} from './libs/OpenAIUtils';
79

10+
811
function isCommentCreatedOrEditedEvent(payload: IssueCommentEvent): payload is IssueCommentCreatedEvent | IssueCommentEditedEvent {
912
return payload.action === CONST.ACTIONS.CREATED || payload.action === CONST.ACTIONS.EDIT;
1013
}
@@ -15,7 +18,11 @@ function isCommentCreatedEvent(payload: IssueCommentEvent): payload is IssueComm
1518

1619
// Main function to process the workflow event
1720
async function run() {
18-
const date = new Date();
21+
// Capture the timestamp immediately at the start of the run
22+
const now = Date.now();
23+
const zonedDate = utcToZonedTime(now, 'UTC');
24+
const formattedDate = format(zonedDate, "yyyy-MM-dd HH:mm:ss 'UTC'");
25+
1926
// @ts-ignore - process is not imported
2027
const octokit: InstanceType<typeof GitHubType> = getOctokit(process.env.GITHUB_TOKEN);
2128
// Verify this is running for an expected webhook event
@@ -99,8 +106,6 @@ async function run() {
99106
// extract the text after [EDIT_COMMENT] from assistantResponse since this is a
100107
// bot related action keyword
101108
let extractedNotice = assistantResponse.split('[EDIT_COMMENT] ')?.[1]?.replace('"', '');
102-
// format the date like: 2024-01-24 13:15:24 UTC not 2024-01-28 18:18:28.000 UTC
103-
const formattedDate = `${date.toISOString()?.split('.')?.[0]?.replace('T', ' ')} UTC`;
104109
extractedNotice = extractedNotice.replace('{updated_timestamp}', formattedDate);
105110
console.log('ProposalPolice™ editing issue comment...', payload.comment.id);
106111
await octokit.issues.updateComment({

.github/scripts/tsconfig.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/scripts/yarn.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
tunnel "^0.0.6"
3636
undici "^5.25.4"
3737

38+
"@babel/runtime@^7.21.0":
39+
version "7.25.6"
40+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.6.tgz#9afc3289f7184d8d7f98b099884c26317b9264d2"
41+
integrity sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==
42+
dependencies:
43+
regenerator-runtime "^0.14.0"
44+
3845
"@cspotcode/source-map-support@^0.8.0":
3946
version "0.8.1"
4047
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
@@ -343,6 +350,18 @@ create-require@^1.1.0:
343350
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
344351
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
345352

353+
date-fns-tz@^2.0.0:
354+
version "2.0.1"
355+
resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-2.0.1.tgz#0a9b2099031c0d74120b45de9fd23192e48ea495"
356+
integrity sha512-fJCG3Pwx8HUoLhkepdsP7Z5RsucUi+ZBOxyM5d0ZZ6c4SdYustq0VMmOu6Wf7bli+yS/Jwp91TOCqn9jMcVrUA==
357+
358+
date-fns@^2.30.0:
359+
version "2.30.0"
360+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0"
361+
integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==
362+
dependencies:
363+
"@babel/runtime" "^7.21.0"
364+
346365
delayed-stream@~1.0.0:
347366
version "1.0.0"
348367
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -451,6 +470,11 @@ openai@^4.24.7:
451470
formdata-node "^4.3.2"
452471
node-fetch "^2.6.7"
453472

473+
regenerator-runtime@^0.14.0:
474+
version "0.14.1"
475+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f"
476+
integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==
477+
454478
tr46@~0.0.3:
455479
version "0.0.3"
456480
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"

0 commit comments

Comments
 (0)