Доработаны enhancer-ы задач
This commit is contained in:
parent
b0acc664d5
commit
90c4433afb
4 changed files with 19 additions and 4 deletions
|
|
@ -6,23 +6,33 @@ import { IssueEnhancerInterface } from './issue-enhancer-interface';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EnhancerService {
|
export class EnhancerService {
|
||||||
private logger = new Logger(EnhancerService.name);
|
private logger = new Logger(EnhancerService.name);
|
||||||
|
private initilialized = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private moduleRef: ModuleRef,
|
private moduleRef: ModuleRef,
|
||||||
@Inject('ENHANCERS')
|
@Inject('ENHANCERS')
|
||||||
private enhancers: IssueEnhancerInterface[],
|
private enhancers: IssueEnhancerInterface[],
|
||||||
) {
|
) {}
|
||||||
|
|
||||||
|
private init(): void {
|
||||||
|
if (!this.initilialized) {
|
||||||
|
this.logger.log(`Initialize EnhancerService`);
|
||||||
this.enhancers.forEach((e) => e.init(this.moduleRef));
|
this.enhancers.forEach((e) => e.init(this.moduleRef));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async enhanceIssue(
|
async enhanceIssue(
|
||||||
issue: RedmineTypes.Issue & Record<string, any>,
|
issue: RedmineTypes.Issue & Record<string, any>,
|
||||||
): Promise<RedmineTypes.Issue & Record<string, any>> {
|
): Promise<RedmineTypes.Issue & Record<string, any>> {
|
||||||
|
this.init();
|
||||||
for (let i = 0; i < this.enhancers.length; i++) {
|
for (let i = 0; i < this.enhancers.length; i++) {
|
||||||
const enhancer = this.enhancers[i];
|
const enhancer = this.enhancers[i];
|
||||||
|
// eslint-disable-next-line prettier/prettier
|
||||||
|
this.logger.debug(`Start enhancer "${enhancer.name}" for issue.id = ${issue.id}...`);
|
||||||
issue = await enhancer.enhance(issue);
|
issue = await enhancer.enhance(issue);
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Issue after enhancer: issue = ${JSON.stringify(issue)}`,
|
// eslint-disable-next-line prettier/prettier
|
||||||
|
`Success finished enhancer "${enhancer.name}" for issue.id = ${issue.id}...`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return issue;
|
return issue;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { ModuleRef } from '@nestjs/core';
|
||||||
import { RedmineTypes } from '../models/redmine-types';
|
import { RedmineTypes } from '../models/redmine-types';
|
||||||
|
|
||||||
export interface IssueEnhancerInterface {
|
export interface IssueEnhancerInterface {
|
||||||
|
name: string;
|
||||||
init(moduleRef: ModuleRef);
|
init(moduleRef: ModuleRef);
|
||||||
enhance(
|
enhance(
|
||||||
issue: RedmineTypes.Issue,
|
issue: RedmineTypes.Issue,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import { IssueEnhancerInterface } from './issue-enhancer-interface';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TimestampEnhancer implements IssueEnhancerInterface {
|
export class TimestampEnhancer implements IssueEnhancerInterface {
|
||||||
|
name = 'timestamp';
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import { ModuleRef } from '@nestjs/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
||||||
|
name = 'custom-fields';
|
||||||
|
|
||||||
private usersService: UsersService;
|
private usersService: UsersService;
|
||||||
|
|
||||||
init(moduleRef: ModuleRef): void {
|
init(moduleRef: ModuleRef): void {
|
||||||
|
|
@ -46,7 +48,7 @@ export class CustomFieldsEnhancer implements IssueEnhancerInterface {
|
||||||
|
|
||||||
const tags = customFields.find((cf) => cf.name === 'Tags');
|
const tags = customFields.find((cf) => cf.name === 'Tags');
|
||||||
if (tags && tags.value) {
|
if (tags && tags.value) {
|
||||||
res.tags = tags.value.split(',; ');
|
res.tags = tags.value.split(/[ ,;]/);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sp = customFields.find(
|
const sp = customFields.find(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue