From de12b71f7f69032d8a524cff89df53779d787f4b Mon Sep 17 00:00:00 2001 From: Github Actions autocommiter Date: Mon, 20 Jan 2025 12:10:07 +0000 Subject: [PATCH] Release 0.2.25 --- lib/Bot/index.d.ts | 26 +++ lib/Bot/index.js | 299 +++++++++++++++++++++++++++++++ lib/Bot/index.js.map | 1 + lib/CommentParser/index.d.ts | 8 + lib/CommentParser/index.js | 28 +++ lib/CommentParser/index.js.map | 1 + lib/Responder/index.d.ts | 11 ++ lib/Responder/index.js | 67 +++++++ lib/Responder/index.js.map | 1 + lib/SnippetResolver/index.d.ts | 41 +++++ lib/SnippetResolver/index.js | 114 ++++++++++++ lib/SnippetResolver/index.js.map | 1 + lib/Utils/index.d.ts | 1 + lib/Utils/index.js | 48 +++++ lib/Utils/index.js.map | 1 + lib/index.d.ts | 3 + lib/index.js | 13 ++ lib/index.js.map | 1 + 18 files changed, 665 insertions(+) create mode 100644 lib/Bot/index.d.ts create mode 100644 lib/Bot/index.js create mode 100644 lib/Bot/index.js.map create mode 100644 lib/CommentParser/index.d.ts create mode 100644 lib/CommentParser/index.js create mode 100644 lib/CommentParser/index.js.map create mode 100644 lib/Responder/index.d.ts create mode 100644 lib/Responder/index.js create mode 100644 lib/Responder/index.js.map create mode 100644 lib/SnippetResolver/index.d.ts create mode 100644 lib/SnippetResolver/index.js create mode 100644 lib/SnippetResolver/index.js.map create mode 100644 lib/Utils/index.d.ts create mode 100644 lib/Utils/index.js create mode 100644 lib/Utils/index.js.map create mode 100644 lib/index.d.ts create mode 100644 lib/index.js create mode 100644 lib/index.js.map diff --git a/lib/Bot/index.d.ts b/lib/Bot/index.d.ts new file mode 100644 index 00000000..89c062a2 --- /dev/null +++ b/lib/Bot/index.d.ts @@ -0,0 +1,26 @@ +import { Context, Probot } from "probot"; +import { CommentParser } from '../CommentParser'; +import { Responder } from "../Responder"; +import { SnippetResolver } from "../SnippetResolver"; +export declare class Bot { + parser: CommentParser; + resolver: SnippetResolver; + responder: Responder; + responses: Map; + constructor(parser: CommentParser, resolver: SnippetResolver, responder: Responder); + onIssueOpened(context: Context<'issues.opened'>): Promise; + onIssueCommentCreated(context: Context<'issue_comment.created'>): Promise; + onIssueEdited(context: Context<'issues.edited'>): Promise; + onIssueCommentEdited(context: Context<'issue_comment.edited'>): Promise; + onIssueCommentDeleted(context: Context<'issue_comment.deleted'>): Promise; + onPullRequestOpened(context: Context<'pull_request.opened'>): Promise; + onPullRequestEdited(context: Context<'pull_request.edited'>): Promise; + private greet; + private respond; + private updateResponse; + private deleteResponse; + private makeResponse; +} +export declare class BotFactory { + static make(app: Probot): Bot; +} diff --git a/lib/Bot/index.js b/lib/Bot/index.js new file mode 100644 index 00000000..bd125dd0 --- /dev/null +++ b/lib/Bot/index.js @@ -0,0 +1,299 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + 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); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BotFactory = exports.Bot = void 0; +var CommentParser_1 = require("../CommentParser"); +var Responder_1 = require("../Responder"); +var SnippetResolver_1 = require("../SnippetResolver"); +var Utils_1 = require("../Utils"); +var Bot = /** @class */ (function () { + function Bot(parser, resolver, responder) { + this.parser = parser; + this.resolver = resolver; + this.responder = responder; + this.responses = new Map(); + } + Bot.prototype.onIssueOpened = function (context) { + return __awaiter(this, void 0, void 0, function () { + var responded; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.respond(context)]; + case 1: + responded = _a.sent(); + if (!(false === responded)) return [3 /*break*/, 3]; + return [4 /*yield*/, this.greet(context)]; + case 2: + _a.sent(); + _a.label = 3; + case 3: return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onIssueCommentCreated = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.respond(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onIssueEdited = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.updateResponse(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onIssueCommentEdited = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.updateResponse(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onIssueCommentDeleted = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.deleteResponse(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onPullRequestOpened = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.respond(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.onPullRequestEdited = function (context) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.updateResponse(context)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.greet = function (context) { + return __awaiter(this, void 0, void 0, function () { + var issue, issueComment, result; + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + issue = context.payload.issue; + if (!this.responder.shouldGreet((_a = issue.body) !== null && _a !== void 0 ? _a : '', context.payload.repository.full_name)) return [3 /*break*/, 3]; + issueComment = context.issue({ + body: this.responder.greet(issue.user.login) + }); + return [4 /*yield*/, (0, Utils_1.delay)(1000)]; + case 1: + _b.sent(); + return [4 /*yield*/, context.octokit.issues.createComment(issueComment)]; + case 2: + result = _b.sent(); + this.responses.set(issue.id, result.data.id); + _b.label = 3; + case 3: return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.respond = function (context) { + return __awaiter(this, void 0, void 0, function () { + var respondingTo, links, issueComment, _a, _b, result; + var _c; + var _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + if (context.isBot) { + return [2 /*return*/, null]; + } + if ('comment' in context.payload) { + respondingTo = context.payload.comment; + } + else if ('pull_request' in context.payload) { + respondingTo = context.payload.pull_request; + } + else { + respondingTo = context.payload.issue; + } + links = this.parser.parseComment((_d = respondingTo.body) !== null && _d !== void 0 ? _d : ''); + if (!links.length) return [3 /*break*/, 4]; + _b = (_a = context).issue; + _c = {}; + return [4 /*yield*/, this.makeResponse(links)]; + case 1: + issueComment = _b.apply(_a, [(_c.body = _e.sent(), + _c)]); + return [4 /*yield*/, (0, Utils_1.delay)(1000)]; + case 2: + _e.sent(); + return [4 /*yield*/, context.octokit.issues.createComment(issueComment)]; + case 3: + result = _e.sent(); + this.responses.set(respondingTo.id, result.data.id); + _e.label = 4; + case 4: return [2 /*return*/, false]; + } + }); + }); + }; + Bot.prototype.updateResponse = function (context) { + return __awaiter(this, void 0, void 0, function () { + var respondingTo, existingResponseId, links, issueComment, _a, _b; + var _c; + var _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + if ('comment' in context.payload) { + respondingTo = context.payload.comment; + } + else if ('pull_request' in context.payload) { + respondingTo = context.payload.pull_request; + } + else { + respondingTo = context.payload.issue; + } + if (!this.responses.has(respondingTo.id)) return [3 /*break*/, 5]; + existingResponseId = this.responses.get(respondingTo.id); + links = this.parser.parseComment((_d = respondingTo.body) !== null && _d !== void 0 ? _d : ''); + if (!links.length) return [3 /*break*/, 3]; + _b = (_a = context).issue; + _c = { + comment_id: existingResponseId + }; + return [4 /*yield*/, this.makeResponse(links)]; + case 1: + issueComment = _b.apply(_a, [(_c.body = _e.sent(), + _c)]); + return [4 /*yield*/, context.octokit.issues.updateComment(issueComment)]; + case 2: + _e.sent(); + return [3 /*break*/, 5]; + case 3: return [4 /*yield*/, context.octokit.issues.deleteComment(context.issue({ + comment_id: existingResponseId + }))]; + case 4: + _e.sent(); + this.responses.delete(respondingTo.id); + _e.label = 5; + case 5: return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.deleteResponse = function (context) { + return __awaiter(this, void 0, void 0, function () { + var comment, existingResponseId; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + comment = context.payload.comment; + if (!this.responses.has(comment.id)) return [3 /*break*/, 2]; + existingResponseId = this.responses.get(comment.id); + return [4 /*yield*/, context.octokit.issues.deleteComment(context.issue({ + comment_id: existingResponseId + }))]; + case 1: + _a.sent(); + this.responses.delete(comment.id); + _a.label = 2; + case 2: return [2 /*return*/]; + } + }); + }); + }; + Bot.prototype.makeResponse = function (links) { + return __awaiter(this, void 0, void 0, function () { + var resolvedSnippets; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, Promise.all(links.map(function (entry) { return _this.resolver.resolve(entry); }))]; + case 1: + resolvedSnippets = _a.sent(); + return [2 /*return*/, this.responder.snippetResponse(resolvedSnippets)]; + } + }); + }); + }; + return Bot; +}()); +exports.Bot = Bot; +var BotFactory = /** @class */ (function () { + function BotFactory() { + } + BotFactory.make = function (app) { + return new Bot(new CommentParser_1.CommentParser(), new SnippetResolver_1.SnippetResolver(app.log), new Responder_1.Responder()); + }; + return BotFactory; +}()); +exports.BotFactory = BotFactory; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/Bot/index.js.map b/lib/Bot/index.js.map new file mode 100644 index 00000000..231f6c5e --- /dev/null +++ b/lib/Bot/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Bot/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA0D;AAC1D,0CAAuC;AACvC,sDAAmD;AACnD,kCAA+B;AAE/B;IAOE,aAAY,MAAqB,EAAE,QAAyB,EAAE,SAAoB;QAChF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,SAAS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AAG,SAExB;wBACD,sBAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAA;;;;KACxD;IACH,UAAC;AAAD,CAAC,AAtID,IAsIC;AAtIY,kBAAG;AAwIhB;IAAA;IAQA,CAAC;IAPQ,eAAI,GAAX,UAAY,GAAW;QACrB,OAAO,IAAI,GAAG,CACZ,IAAI,6BAAa,EAAE,EACnB,IAAI,iCAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAC5B,IAAI,qBAAS,EAAE,CAChB,CAAA;IACH,CAAC;IACH,iBAAC;AAAD,CAAC,AARD,IAQC;AARY,gCAAU"} \ No newline at end of file diff --git a/lib/CommentParser/index.d.ts b/lib/CommentParser/index.d.ts new file mode 100644 index 00000000..f6911912 --- /dev/null +++ b/lib/CommentParser/index.d.ts @@ -0,0 +1,8 @@ +export declare class CommentParser { + parseComment(comment: string): LinkEntry[]; +} +export interface LinkEntry { + link: string; + snippet: string; + params: string; +} diff --git a/lib/CommentParser/index.js b/lib/CommentParser/index.js new file mode 100644 index 00000000..04c13889 --- /dev/null +++ b/lib/CommentParser/index.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CommentParser = void 0; +var CommentParser = /** @class */ (function () { + function CommentParser() { + } + CommentParser.prototype.parseComment = function (comment) { + var matches; + var snippets = []; + var regexp = /psalm\.dev\/r\/(\w+)(\?(php=\d+\.\d+))?/g; + var seen = new Set; + while ((matches = regexp.exec(comment)) !== null) { + if (seen.has(matches[0])) { + continue; + } + snippets.push({ + link: 'https://' + matches[0], + snippet: matches[1], + params: matches[3] || '' + }); + seen.add(matches[0]); + } + return snippets; + }; + return CommentParser; +}()); +exports.CommentParser = CommentParser; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/CommentParser/index.js.map b/lib/CommentParser/index.js.map new file mode 100644 index 00000000..ed35f7ea --- /dev/null +++ b/lib/CommentParser/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CommentParser/index.ts"],"names":[],"mappings":";;;AAAA;IAAA;IAwBA,CAAC;IAvBC,oCAAY,GAAZ,UAAa,OAAe;QAC1B,IAAI,OAAO,CAAC;QACZ,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,IAAM,MAAM,GAAG,0CAA0C,CAAC;QAE1D,IAAM,IAAI,GAAgB,IAAI,GAAG,CAAC;QAElC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACjD,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YAED,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC;gBAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;gBACnB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;aACzB,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,oBAAC;AAAD,CAAC,AAxBD,IAwBC;AAxBY,sCAAa"} \ No newline at end of file diff --git a/lib/Responder/index.d.ts b/lib/Responder/index.d.ts new file mode 100644 index 00000000..a8b106ef --- /dev/null +++ b/lib/Responder/index.d.ts @@ -0,0 +1,11 @@ +import { ResolvedSnippet } from "../SnippetResolver"; +export declare class Responder { + greet(login: string): string; + shouldGreet(issue: string, repoName: string): boolean; + snippetResponse(resolvedSnippets: ResolvedSnippet[]): string; + private formatSnippet; + private formatSnippetOutput; + private formatInternalError; + private formatSnippetResult; + private formatSnippetIssue; +} diff --git a/lib/Responder/index.js b/lib/Responder/index.js new file mode 100644 index 00000000..a5ab5234 --- /dev/null +++ b/lib/Responder/index.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Responder = void 0; +var Responder = /** @class */ (function () { + function Responder() { + } + Responder.prototype.greet = function (login) { + return "Hey @".concat(login, ", can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug."); + }; + Responder.prototype.shouldGreet = function (issue, repoName) { + var allowedRepos = [ + 'vimeo/psalm', + 'weirdan/psalm-github-bot' + ]; + if (!allowedRepos.includes(repoName)) { + return false; + } + var links = issue.match(/psalm\.dev(\/\w*)?/g); + if (!links) { + return true; + } + var validLinks = links.filter(function (link) { return !/psalm\.dev\/\d/.test(link); }); + if (null === validLinks) { + return true; + } + if (!validLinks.length) { + return true; + } + return false; + }; + Responder.prototype.snippetResponse = function (resolvedSnippets) { + var snippets = resolvedSnippets.map(this.formatSnippet.bind(this)).join('\n'); + return "I found these snippets:\n".concat(snippets); + }; + Responder.prototype.formatSnippet = function (snippet) { + var snippetCode = "".concat(snippet.link, "\n\n```php\n").concat(snippet.text, "\n```\n"); + var snippetOutput = this.formatSnippetOutput(snippet); + return "
\n".concat(snippetCode, "\n").concat(snippetOutput, "\n
\n"); + }; + Responder.prototype.formatSnippetOutput = function (snippet) { + if (snippet.internalError !== null) { + return this.formatInternalError(snippet); + } + else if (snippet.results !== null) { + return this.formatSnippetResult(snippet); + } + return ''; + }; + Responder.prototype.formatInternalError = function (snippet) { + if (null === snippet.internalError) { + throw new Error('expected to receive errored snippet'); + } + return "```\nPsalm encountered an internal error:\n\n".concat(snippet.internalError.message, "\n```"); + }; + Responder.prototype.formatSnippetResult = function (snippet) { + if (null === snippet.results) { + throw new Error('expected to receive successful snippet'); + } + return "```\nPsalm output (using commit ".concat(snippet.results.version.split('@')[1].substr(0, 7), "):\n\n").concat(snippet.results.results.length ? snippet.results.results.map(this.formatSnippetIssue.bind(this)).join('\n\n') : 'No issues!', "\n```"); + }; + Responder.prototype.formatSnippetIssue = function (issue) { + return "".concat(issue.severity.toUpperCase(), ": ").concat(issue.type, " - ").concat(issue.line_from, ":").concat(issue.column_from, " - ").concat(issue.message); + }; + return Responder; +}()); +exports.Responder = Responder; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/Responder/index.js.map b/lib/Responder/index.js.map new file mode 100644 index 00000000..69e644d6 --- /dev/null +++ b/lib/Responder/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Responder/index.ts"],"names":[],"mappings":";;;AAEA;IAAA;IA4FA,CAAC;IA1FC,yBAAK,GAAL,UAAM,KAAa;QACjB,OAAO,eAAQ,KAAK,8IAA2I,CAAA;IACjK,CAAC;IAED,+BAAW,GAAX,UAAY,KAAa,EAAE,QAAgB;QACzC,IAAM,YAAY,GAAG;YACnB,aAAa;YACb,0BAA0B;SAC3B,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;QAChD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAC7B,UAAA,IAAI,IAAI,OAAA,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAA5B,CAA4B,CACrC,CAAA;QAED,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YACxB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mCAAe,GAAf,UAAgB,gBAAmC;QACjD,IAAM,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,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,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,UACvH,CAAA;IACL,CAAC;IAEO,sCAAkB,GAA1B,UAA2B,KAAmB;QAC5C,OAAO,UAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,eAAK,KAAK,CAAC,IAAI,gBAAM,KAAK,CAAC,SAAS,cAAI,KAAK,CAAC,WAAW,gBAAM,KAAK,CAAC,OAAO,CAAE,CAAA;IACtH,CAAC;IACH,gBAAC;AAAD,CAAC,AA5FD,IA4FC;AA5FY,8BAAS"} \ No newline at end of file diff --git a/lib/SnippetResolver/index.d.ts b/lib/SnippetResolver/index.d.ts new file mode 100644 index 00000000..a1b279e8 --- /dev/null +++ b/lib/SnippetResolver/index.d.ts @@ -0,0 +1,41 @@ +import type { Logger } from 'pino'; +import { PerformanceObserver } from 'perf_hooks'; +import { LinkEntry } from '../CommentParser'; +export declare class SnippetResolver { + log: Logger; + obs: PerformanceObserver; + constructor(log: Logger); + resolve(link: LinkEntry): Promise; +} +export interface ResolvedSnippet { + link: string; + text: string; + results: SnippetResults | null; + internalError: SnippetInternalError | null; +} +export interface SnippetResults { + results: SnippetIssue[]; + version: string; + fixed_contents?: string; + hash: string; +} +export interface SnippetInternalError { + message: string; +} +export interface SnippetIssue { + severity: string; + line_from: number; + line_to: number; + type: string; + message: string; + file_name: string; + file_path: string; + snippet: string; + selected_text: string; + from: number; + to: number; + snippet_from: number; + snippet_to: number; + column_from: number; + column_to: number; +} diff --git a/lib/SnippetResolver/index.js b/lib/SnippetResolver/index.js new file mode 100644 index 00000000..313c8050 --- /dev/null +++ b/lib/SnippetResolver/index.js @@ -0,0 +1,114 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + 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); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SnippetResolver = void 0; +var node_fetch_1 = __importDefault(require("node-fetch")); +var perf_hooks_1 = require("perf_hooks"); +var util_1 = __importDefault(require("util")); +var SnippetResolver = /** @class */ (function () { + function SnippetResolver(log) { + var _this = this; + this.log = log; + this.obs = new perf_hooks_1.PerformanceObserver(function (list) { + _this.log.debug('Logging the performance marks: %s', JSON.stringify(list)); + list.getEntries().forEach(function (entry) { return _this.log.info('%s: %dms', entry.name, entry.duration); }); + }); + this.obs.observe({ entryTypes: ['measure'] }); + } + SnippetResolver.prototype.resolve = function (link) { + return __awaiter(this, void 0, void 0, function () { + var url, startMark, snippetReceivedMark, resultsReceivedMark, text, response, results, body; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.log.debug('Resolving snippet: %s', link.snippet); + url = "https://psalm.dev/r/".concat(link.snippet); + startMark = util_1.default.format('start resolving %s', link.snippet); + snippetReceivedMark = util_1.default.format('snippet received %s', link.snippet); + resultsReceivedMark = util_1.default.format('results received %s', link.snippet); + perf_hooks_1.performance.mark(startMark); + return [4 /*yield*/, (0, node_fetch_1.default)("".concat(url, "/raw")) + .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, response.text()]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); })]; + case 1: + text = _a.sent(); + perf_hooks_1.performance.mark(snippetReceivedMark); + return [4 /*yield*/, (0, node_fetch_1.default)("".concat(url, "/results") + (link.params.length ? ('?' + link.params) : ''))]; + case 2: + response = _a.sent(); + results = { error: { message: 'Bot failed to fetch results' } }; + return [4 /*yield*/, response.text()]; + case 3: + body = _a.sent(); + if (body.length) { + try { + results = JSON.parse(body); + } + catch (ex) { + results = { error: { message: 'Failed to parse results: ' + body } }; + } + } + else { + results = { error: { message: 'Failed to parse results: (received no output)' } }; + } + perf_hooks_1.performance.mark(resultsReceivedMark); + perf_hooks_1.performance.measure(util_1.default.format('Fetching snippet %s', link.snippet), startMark, snippetReceivedMark); + perf_hooks_1.performance.measure(util_1.default.format('Fetching results for %s', link.snippet), snippetReceivedMark, resultsReceivedMark); + perf_hooks_1.performance.measure(util_1.default.format('Total for %s', link.snippet), startMark, resultsReceivedMark); + return [2 /*return*/, { + link: url, + text: text, + results: results.error === undefined ? results : null, + internalError: results.error === undefined ? null : results.error + }]; + } + }); + }); + }; + return SnippetResolver; +}()); +exports.SnippetResolver = SnippetResolver; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/SnippetResolver/index.js.map b/lib/SnippetResolver/index.js.map new file mode 100644 index 00000000..c4ab6549 --- /dev/null +++ b/lib/SnippetResolver/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/SnippetResolver/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAA+B;AAC/B,yCAA4D;AAC5D,8CAAwB;AAGxB;IAIE,yBAAY,GAAW;QAAvB,iBAOC;QANC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,IAAI,gCAAmB,CAAC,UAAA,IAAI;YACrC,KAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAmC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;YACzE,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,KAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,EAArD,CAAqD,CAAC,CAAA;QAC3F,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAC,UAAU,EAAE,CAAC,SAAS,CAAC,EAAC,CAAC,CAAA;IAC7C,CAAC;IAEK,iCA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,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;4BAC5B,CAAC;4BAAC,OAAO,EAAE,EAAE,CAAC;gCACZ,OAAO,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,2BAA2B,GAAG,IAAI,EAAE,EAAS,CAAA;4BAC7E,CAAC;wBACH,CAAC;6BAAM,CAAC;4BACN,OAAO,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,+CAA+C,EAAE,EAAS,CAAA;wBAC1F,CAAC;wBAED,wBAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;wBAErC,wBAAW,CAAC,OAAO,CACjB,cAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE,IAAI,CAAC,OAAO,CAAC,EAChD,SAAS,EACT,mBAAmB,CACpB,CAAA;wBACD,wBAAW,CAAC,OAAO,CACjB,cAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE,IAAI,CAAC,OAAO,CAAC,EACpD,mBAAmB,EACnB,mBAAmB,CACpB,CAAA;wBACD,wBAAW,CAAC,OAAO,CACjB,cAAI,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,EACzC,SAAS,EACT,mBAAmB,CACpB,CAAA;wBAED,sBAAO;gCACL,IAAI,EAAE,GAAG;gCACT,IAAI,EAAE,IAAI;gCACV,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;gCACrD,aAAa,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK;6BAClE,EAAA;;;;KACF;IACH,sBAAC;AAAD,CAAC,AAlED,IAkEC;AAlEY,0CAAe"} \ No newline at end of file diff --git a/lib/Utils/index.d.ts b/lib/Utils/index.d.ts new file mode 100644 index 00000000..ed340ebc --- /dev/null +++ b/lib/Utils/index.d.ts @@ -0,0 +1 @@ +export declare function delay(ms: number): Promise; diff --git a/lib/Utils/index.js b/lib/Utils/index.js new file mode 100644 index 00000000..8d9254bc --- /dev/null +++ b/lib/Utils/index.js @@ -0,0 +1,48 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + 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); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.delay = delay; +function delay(ms) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + new Promise(function (resolve) { return setTimeout(resolve, ms); }); + return [2 /*return*/]; + }); + }); +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/Utils/index.js.map b/lib/Utils/index.js.map new file mode 100644 index 00000000..49558ff6 --- /dev/null +++ b/lib/Utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sBAEC;AAFD,SAAsB,KAAK,CAAC,EAAU;;;YACpC,IAAI,OAAO,CAAO,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,EAAvB,CAAuB,CAAC,CAAA;;;;CACtD"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 00000000..cdc1a1d5 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,3 @@ +import { Probot } from 'probot'; +declare const _default: (app: Probot) => void; +export = _default; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 00000000..f8560421 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,13 @@ +"use strict"; +var Bot_1 = require("./Bot"); +module.exports = function (app) { + var bot = Bot_1.BotFactory.make(app); + app.on('issues.opened', bot.onIssueOpened.bind(bot)); + app.on('issue_comment.created', bot.onIssueCommentCreated.bind(bot)); + app.on('issues.edited', bot.onIssueEdited.bind(bot)); + app.on('issue_comment.edited', bot.onIssueCommentEdited.bind(bot)); + app.on('issue_comment.deleted', bot.onIssueCommentDeleted.bind(bot)); + app.on('pull_request.opened', bot.onPullRequestOpened.bind(bot)); + app.on('pull_request.edited', bot.onPullRequestEdited.bind(bot)); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map new file mode 100644 index 00000000..b201e68d --- /dev/null +++ b/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,6BAAkC;AAElC,iBAAS,UAAC,GAAW;IACnB,IAAM,GAAG,GAAG,gBAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEhC,GAAG,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACpD,GAAG,CAAC,EAAE,CAAC,uBAAuB,EAAE,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACpE,GAAG,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACpD,GAAG,CAAC,EAAE,CAAC,sBAAsB,EAAE,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAClE,GAAG,CAAC,EAAE,CAAC,uBAAuB,EAAE,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACpE,GAAG,CAAC,EAAE,CAAC,qBAAqB,EAAE,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAChE,GAAG,CAAC,EAAE,CAAC,qBAAqB,EAAE,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAClE,CAAC,CAAA"} \ No newline at end of file