diff --git a/package.json b/package.json index b30543a2..f6e898e5 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "mime": "^3.0.0", "node-emoji": "^1.11.0", "nyc": "^15.1.0", + "parse-duration": "^1.0.2", "prom-client": "^14.0.1", "reflect-metadata": "^0.1.13", "rss-parser": "^3.12.0", diff --git a/src/Connections/GithubRepo.ts b/src/Connections/GithubRepo.ts index 7c6dc3b8..d07b4143 100644 --- a/src/Connections/GithubRepo.ts +++ b/src/Connections/GithubRepo.ts @@ -26,6 +26,7 @@ import { ApiError, ErrCode, ValidatorApiError } from "../api"; import { PermissionCheckFn } from "."; import { MinimalGitHubIssue, MinimalGitHubRepo } from "../libRs"; import Ajv, { JSONSchemaType } from "ajv"; +import parseDuration from 'parse-duration'; const log = new Logger("GitHubRepoConnection"); const md = new markdown(); @@ -273,6 +274,14 @@ export interface GitHubTargetFilter { perPage?: number; } +interface SilencedHook { + eventNames: AllowedEventsNames[]; + filters?: { + by?: string; + }; + until: Date, +} + /** * Handles rooms connected to a GitHub repo. */ @@ -431,6 +440,8 @@ export class GitHubRepoConnection extends CommandConnection, timeout: NodeJS.Timeout}>(); + public tempSilencedHooks: SilencedHook[] = []; + constructor(roomId: string, private readonly as: Appservice, state: GitHubRepoConnectionState, @@ -712,6 +723,32 @@ export class GitHubRepoConnection extends CommandConnection s in AllowedEvents === false) + if (invalidEventNames.length) { + throw new CommandError(`${invalidEventNames.join(', ')} are not valid event names`); + } + const filterSet: Record = {}; + filters?.split(',').forEach(s => { + const [key,value] = s.toLowerCase().split(':'); + filterSet[key] = value; + }); + // One hour + const until = new Date(Date.now() + (time ? parseDuration(time) : 1000 * 60 * 60)); + this.tempSilencedHooks.push({ + until, + filters: { + by: filterSet.by, + }, + eventNames: eventNames as AllowedEventsNames[], + }) + } + public async onIssueCreated(event: IssuesOpenedEvent) { if (this.shouldSkipHook('issue.created', 'issue') || !this.matchesLabelFilter(event.issue)) { return; diff --git a/yarn.lock b/yarn.lock index 2083700d..dbfe7ad6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4823,6 +4823,11 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" +parse-duration@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-1.0.2.tgz#b9aa7d3a1363cc7e8845bea8fd3baf8a11df5805" + integrity sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg== + parse-srcset@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/parse-srcset/-/parse-srcset-1.0.2.tgz#f2bd221f6cc970a938d88556abc589caaaa2bde1"