Категории добавляются к тегам в проекте eccm

This commit is contained in:
Pavel Gnedov 2023-03-03 08:08:31 +07:00
parent 6d5293f85a
commit e447b381e3
2 changed files with 57 additions and 2 deletions

View file

@ -3,8 +3,14 @@ import { RedmineIssuesCacheWriterService } from '@app/event-emitter/issue-cache-
import { EnhancerService } from '@app/event-emitter/issue-enhancers/enhancer.service'; import { EnhancerService } from '@app/event-emitter/issue-enhancers/enhancer.service';
import { TimestampEnhancer } from '@app/event-emitter/issue-enhancers/timestamps-enhancer'; import { TimestampEnhancer } from '@app/event-emitter/issue-enhancers/timestamps-enhancer';
import { MainController } from '@app/event-emitter/main/main.controller'; import { MainController } from '@app/event-emitter/main/main.controller';
import { CacheModule, Logger, Module, OnModuleInit } from '@nestjs/common'; import {
import { ConfigModule } from '@nestjs/config'; CacheModule,
Inject,
Logger,
Module,
OnModuleInit,
} from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { switchMap, tap } from 'rxjs'; import { switchMap, tap } from 'rxjs';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
@ -38,6 +44,7 @@ import { DailyEccmWithExtraDataService } from './reports/daily-eccm-with-extra-d
import { SimpleKanbanBoardController } from './dashboards/simple-kanban-board.controller'; import { SimpleKanbanBoardController } from './dashboards/simple-kanban-board.controller';
import { IssueUrlEnhancer } from '@app/event-emitter/issue-enhancers/issue-url-enhancer'; import { IssueUrlEnhancer } from '@app/event-emitter/issue-enhancers/issue-url-enhancer';
import { IssuesByTagsWidgetService } from './dashboards/widgets/issues-by-tags.widget.service'; import { IssuesByTagsWidgetService } from './dashboards/widgets/issues-by-tags.widget.service';
import { CategoryMergeToTagsEnhancer } from './issue-enhancers/category-merge-to-tags-enhancer';
@Module({ @Module({
imports: [ imports: [
@ -81,6 +88,16 @@ import { IssuesByTagsWidgetService } from './dashboards/widgets/issues-by-tags.w
SetDailyEccmUserCommentBotHandlerService, SetDailyEccmUserCommentBotHandlerService,
DailyEccmWithExtraDataService, DailyEccmWithExtraDataService,
IssuesByTagsWidgetService, IssuesByTagsWidgetService,
{
provide: 'CATEGORY_MERGE_TO_TAGS_ENHANCER',
useFactory: (configService: ConfigService) => {
const eccmProjectName = configService.get<string>(
'redmineEccm.projectName',
);
return new CategoryMergeToTagsEnhancer([eccmProjectName]);
},
inject: [ConfigService],
},
], ],
}) })
export class AppModule implements OnModuleInit { export class AppModule implements OnModuleInit {
@ -101,6 +118,9 @@ export class AppModule implements OnModuleInit {
private statusChangeAdapterService: StatusChangeAdapterService, private statusChangeAdapterService: StatusChangeAdapterService,
private dailyEccmUserCommentsService: DailyEccmUserCommentsService, private dailyEccmUserCommentsService: DailyEccmUserCommentsService,
private setDailyEccmUserCommentBotHandlerService: SetDailyEccmUserCommentBotHandlerService, private setDailyEccmUserCommentBotHandlerService: SetDailyEccmUserCommentBotHandlerService,
@Inject('CATEGORY_MERGE_TO_TAGS_ENHANCER')
private categoryMergeToTagsEnhancer: CategoryMergeToTagsEnhancer,
) {} ) {}
onModuleInit() { onModuleInit() {
@ -116,6 +136,7 @@ export class AppModule implements OnModuleInit {
this.customFieldsEnhancer, this.customFieldsEnhancer,
this.currentUserEnhancer, this.currentUserEnhancer,
this.issueUrlEnhancer, this.issueUrlEnhancer,
this.categoryMergeToTagsEnhancer,
]); ]);
this.personalNotificationsService.$messages.subscribe((resp) => { this.personalNotificationsService.$messages.subscribe((resp) => {

View file

@ -0,0 +1,34 @@
import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface';
import { RedmineTypes } from '@app/event-emitter/models/redmine-types';
import { Injectable, Logger } from '@nestjs/common';
@Injectable()
export class CategoryMergeToTagsEnhancer implements IssueEnhancerInterface {
name = 'category-merge-to-tags';
private logger = new Logger(CategoryMergeToTagsEnhancer.name);
constructor(private forProjects: string[]) {
this.logger.debug(`Enhancer created for ${forProjects}`);
}
async enhance(
issue: RedmineTypes.ExtendedIssue,
): Promise<RedmineTypes.ExtendedIssue> {
if (this.forProjects.indexOf(issue.project.name) < 0) {
return issue;
}
if (!issue.tags || !this.isArray(issue.tags)) {
issue.tags = [];
}
const category = issue.category.name.toLowerCase().replaceAll(' ', '');
if (issue.tags.indexOf(category) < 0) {
issue.tags.push(category);
}
return issue;
}
private isArray(a: any): boolean {
return typeof a == 'object' && typeof a.length === 'number';
}
}