From a0e183075fef8016fe0fe58baab89befe17312d9 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Sat, 24 Jun 2023 17:55:20 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/interview-projects.jsonc | 6 +++ configs/interview-projects.jsonc.dist | 4 ++ src/issue-enhancers/interview-enhancer.ts | 59 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 configs/interview-projects.jsonc create mode 100644 configs/interview-projects.jsonc.dist create mode 100644 src/issue-enhancers/interview-enhancer.ts diff --git a/configs/interview-projects.jsonc b/configs/interview-projects.jsonc new file mode 100644 index 0000000..2b2925b --- /dev/null +++ b/configs/interview-projects.jsonc @@ -0,0 +1,6 @@ +{ + "interviewProjects": [ + "Программисты, инженеры HW" + ], + "customFieldDateFormat": "yyyy-MM-dd HH:mm" +} \ No newline at end of file diff --git a/configs/interview-projects.jsonc.dist b/configs/interview-projects.jsonc.dist new file mode 100644 index 0000000..9f49eb9 --- /dev/null +++ b/configs/interview-projects.jsonc.dist @@ -0,0 +1,4 @@ +{ + "interviewProjects": [], + "customFieldDateFormat": "yyyy-MM-dd HH:mm" +} \ No newline at end of file diff --git a/src/issue-enhancers/interview-enhancer.ts b/src/issue-enhancers/interview-enhancer.ts new file mode 100644 index 0000000..06e11c1 --- /dev/null +++ b/src/issue-enhancers/interview-enhancer.ts @@ -0,0 +1,59 @@ +import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface'; +import { RedmineTypes } from '@app/event-emitter/models/redmine-types'; +import { Injectable } from '@nestjs/common'; +import * as Luxon from 'luxon'; + +export type SubjectParserParam = { + regexp: string; + format: string; + type: string; +}; + +export type DescriptionParserParam = {}; + +@Injectable() +export class InterviewEnhancer implements IssueEnhancerInterface { + name = 'interview'; + + constructor( + public interviewProjects: string[] = [], + public customFieldDateFormat: string = 'yyyy-MM-dd HH:mm', + public subjectParserParams: SubjectParserParam[] + ) {} + + async enhance( + issue: RedmineTypes.Issue, + ): Promise> { + const res: RedmineTypes.ExtendedIssue = { ...issue }; + + if (this.interviewProjects.indexOf(res.project.name) < 0) { + return res; + } + + const subject = res.subject; + const nextEventDateField = res.custom_fields.find((cf) => { + return cf.name === 'Дата следующего обновления'; + }); + + if () + + const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); + + return res; + } + + private getNextEventDate(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { + const nextEventDateField = issue.custom_fields.find((cf) => { + return cf.name === 'Дата следующего обновления'; + }); + if (!nextEventDateField) return null; + const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); + if (!nextEventDate.isValid) return null; + return nextEventDate; + } + + private getDateFromSubject(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { + const subject = issue.subject; + return null; + } +}