Добавлены проверки и логирование
This commit is contained in:
parent
4f0355c09c
commit
c543acbbef
2 changed files with 12 additions and 2 deletions
|
|
@ -30,9 +30,10 @@ export namespace TagStyledEnhancerNs {
|
||||||
export function CreateTagStyledEnhancerForConfig(
|
export function CreateTagStyledEnhancerForConfig(
|
||||||
cfg: ConfigWithTagsStyles,
|
cfg: ConfigWithTagsStyles,
|
||||||
): TagStyledEnhancer | null {
|
): TagStyledEnhancer | null {
|
||||||
if (!cfg.tags) return null;
|
if (!cfg || !cfg.tags) return null;
|
||||||
return new TagStyledEnhancer(
|
return new TagStyledEnhancer(
|
||||||
(issue: RedmineTypes.ExtendedIssue) => {
|
(issue: RedmineTypes.ExtendedIssue) => {
|
||||||
|
if (!issue) return [];
|
||||||
if (
|
if (
|
||||||
typeof issue[cfg.tags.tagsKeyName] === 'object' &&
|
typeof issue[cfg.tags.tagsKeyName] === 'object' &&
|
||||||
issue[cfg.tags.tagsKeyName].length > 0
|
issue[cfg.tags.tagsKeyName].length > 0
|
||||||
|
|
@ -64,6 +65,7 @@ export class TagStyledEnhancer implements IssueEnhancerInterface {
|
||||||
async enhance(
|
async enhance(
|
||||||
issue: RedmineTypes.ExtendedIssue,
|
issue: RedmineTypes.ExtendedIssue,
|
||||||
): Promise<RedmineTypes.ExtendedIssue> {
|
): Promise<RedmineTypes.ExtendedIssue> {
|
||||||
|
if (!issue) return issue;
|
||||||
const tags = this.tagsGetter(issue);
|
const tags = this.tagsGetter(issue);
|
||||||
this.logger.debug(`Found tags for issue_id = ${issue.id} - ${tags}`);
|
this.logger.debug(`Found tags for issue_id = ${issue.id} - ${tags}`);
|
||||||
const styles = [] as TagStyledEnhancerNs.StyledTag[];
|
const styles = [] as TagStyledEnhancerNs.StyledTag[];
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import TelegramBot from 'node-telegram-bot-api';
|
import TelegramBot from 'node-telegram-bot-api';
|
||||||
import { Change } from 'src/models/change.model';
|
import { Change } from 'src/models/change.model';
|
||||||
|
|
@ -18,6 +18,7 @@ namespace StatusChangeAdapter {
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class StatusChangeAdapterService {
|
export class StatusChangeAdapterService {
|
||||||
|
private logger = new Logger(StatusChangeAdapterService.name);
|
||||||
private periodValidityNotification: number;
|
private periodValidityNotification: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -54,6 +55,7 @@ export class StatusChangeAdapterService {
|
||||||
item.options = { parse_mode: 'HTML' };
|
item.options = { parse_mode: 'HTML' };
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
this.logger.debug(`Change messages for sending to telegram - ${JSON.stringify(messages)}`);
|
||||||
for (let i = 0; i < messages.length; i++) {
|
for (let i = 0; i < messages.length; i++) {
|
||||||
const message = messages[i];
|
const message = messages[i];
|
||||||
await this.telegramBotService.sendMessageByRedmineId(
|
await this.telegramBotService.sendMessageByRedmineId(
|
||||||
|
|
@ -74,6 +76,12 @@ export class StatusChangeAdapterService {
|
||||||
nowTimestamp - change.created_on_timestamp >
|
nowTimestamp - change.created_on_timestamp >
|
||||||
this.periodValidityNotification
|
this.periodValidityNotification
|
||||||
) {
|
) {
|
||||||
|
this.logger.debug(
|
||||||
|
`Skipping sending due to the prescription ` +
|
||||||
|
`of the origin of the event - ` +
|
||||||
|
`issue_id = ${change.issue_id}, ` +
|
||||||
|
`messages = ${change.messages.map((m) => m.notification_message).filter((m) => !!m)}`
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (let j = 0; j < change.messages.length; j++) {
|
for (let j = 0; j < change.messages.length; j++) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue