Skip to content

Commit

Permalink
feat(logs): add more logs to debug the project card features
Browse files Browse the repository at this point in the history
Will help #498
  • Loading branch information
C0ZEN committed Feb 15, 2022
1 parent 8426ae2 commit ec9d2ce
Show file tree
Hide file tree
Showing 5 changed files with 616 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

301 changes: 295 additions & 6 deletions src/core/processing/issues/issue-include-processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,29 @@ describe(`IssueIncludeProcessor`, (): void => {
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(3);
expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-1`,
`whiteBright-project card on this issue`,
`value-dummy-project`
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Not containing any of the required project card. Skipping the processing of this issue...`
);
});
Expand Down Expand Up @@ -349,14 +364,29 @@ describe(`IssueIncludeProcessor`, (): void => {
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(3);
expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-1`,
`whiteBright-project card on this issue`,
`value-dummy-project`
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Not containing any of the required project card. Skipping the processing of this issue...`
);
});
Expand All @@ -379,14 +409,29 @@ describe(`IssueIncludeProcessor`, (): void => {
);
});

it(`should log about finding one project card in common (continuing the processing)`, (): void => {
it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-1`,
`whiteBright-project card on this issue`,
`value-dummy-project`
);
});

it(`should log about finding one project card in common (continuing the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Containing one of the required project card`,
`white-->`,
`value-dummy-project`
Expand All @@ -398,9 +443,253 @@ describe(`IssueIncludeProcessor`, (): void => {

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
5,
`Continuing the processing for this issue...`
);
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(result).toBeTrue();
});
});
});

describe(`when the issue has two project cards`, (): void => {
beforeEach((): void => {
issueProcessor = createHydratedMock<IssueProcessor>({
item: {
projectCards: {
nodes: [
createHydratedMock<IGithubApiProjectCard>({
project: {
name: `dummy-project-1`,
},
}),
createHydratedMock<IGithubApiProjectCard>({
project: {
name: `dummy-project-2`,
},
}),
],
totalCount: 2,
},
},
});
issueIncludeProcessor = new IssueIncludeProcessor(issueProcessor);

issueProcessorLoggerInfoSpy = jest
.spyOn(issueIncludeProcessor.processor.logger, `info`)
.mockImplementation();
issuesInputsServiceGetInputsSpy = jest
.spyOn(IssuesInputsService.getInstance(), `getInputs`)
.mockReturnValue(
createHydratedMock<IIssuesInputs>({
issueOnlyAnyProjectCards: [`dummy-card`],
})
);
});

describe(`when none of the project cards match`, (): void => {
beforeEach((): void => {
issuesInputsServiceGetInputsSpy.mockReturnValue(
createHydratedMock<IIssuesInputs>({
issueOnlyAnyProjectCards: [`dummy-other-project`],
})
);
});

it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-2`,
`whiteBright-project cards on this issue`,
`value-dummy-project-1,dummy-project-2`
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Not containing any of the required project card. Skipping the processing of this issue...`
);
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(result).toBeFalse();
});
});

describe(`when none of the project cards match and the pagination is higher than 20`, (): void => {
beforeEach((): void => {
issueProcessor = createHydratedMock<IssueProcessor>({
item: {
projectCards: {
nodes: [
createHydratedMock<IGithubApiProjectCard>({
project: {
name: `dummy-project-1`,
},
}),
createHydratedMock<IGithubApiProjectCard>({
project: {
name: `dummy-project-2`,
},
}),
],
totalCount: 21,
},
},
});
issueIncludeProcessor = new IssueIncludeProcessor(issueProcessor);

issueProcessorLoggerInfoSpy = jest
.spyOn(issueIncludeProcessor.processor.logger, `info`)
.mockImplementation();
issueProcessorLoggerWarningSpy = jest
.spyOn(issueIncludeProcessor.processor.logger, `warning`)
.mockImplementation();
annotationsServiceWarningSpy = jest.spyOn(AnnotationsService, `warning`).mockImplementation();
issuesInputsServiceGetInputsSpy = jest
.spyOn(IssuesInputsService.getInstance(), `getInputs`)
.mockReturnValue(
createHydratedMock<IIssuesInputs>({
issueOnlyAnyProjectCards: [`dummy-other-project`],
})
);
});

it(`should log a warning about finding too many labels on this issue since the pagination is not handled`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerWarningSpy).toHaveBeenCalledTimes(1);
expect(issueProcessorLoggerWarningSpy).toHaveBeenCalledWith(
`Found`,
`value-21`,
`whiteBright-project cards attached on this issue. The pagination support is not yet implemented and may cause a mismatch!`
);
});

it(`should annotate about finding too many labels on this issue since the pagination is not handled`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(annotationsServiceWarningSpy).toHaveBeenCalledTimes(1);
expect(annotationsServiceWarningSpy).toHaveBeenCalledWith(
EAnnotationWarningIssue.TOO_MANY_PROJECT_CARDS_PAGINATION_NOT_IMPLEMENTED,
{
file: `issue-include-processor.ts`,
startLine: 76,
title: `Warning`,
}
);
});

it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-2`,
`whiteBright-project cards on this issue`,
`value-dummy-project-1,dummy-project-2`
);
});

it(`should log about not containing any common project card (skipping the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(4);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Not containing any of the required project card. Skipping the processing of this issue...`
);
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(result).toBeFalse();
});
});

describe(`when at least one of the project cards match`, (): void => {
beforeEach((): void => {
issuesInputsServiceGetInputsSpy.mockReturnValue(
createHydratedMock<IIssuesInputs>({
issueOnlyAnyProjectCards: [`dummy-project-2`],
})
);
});

it(`should log the project names`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
3,
`Found`,
`value-2`,
`whiteBright-project cards on this issue`,
`value-dummy-project-1,dummy-project-2`
);
});

it(`should log about finding one project card in common (continuing the processing)`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
4,
`Containing one of the required project card`,
`white-->`,
`value-dummy-project-2`
);
});

it(`should log continuing the processing`, (): void => {
expect.assertions(2);

issueIncludeProcessor.shouldIncludeAnyWhiteListedProjectCard$$();

expect(issueProcessorLoggerInfoSpy).toHaveBeenCalledTimes(5);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(
5,
`Continuing the processing for this issue...`
);
});
Expand Down
16 changes: 12 additions & 4 deletions src/core/processing/issues/issue-include-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IssuesInputsService } from '@core/inputs/issues-inputs.service';
import { AbstractIncludeProcessor } from '@core/processing/abstract-include-processor';
import { IssueProcessor } from '@core/processing/issues/issue-processor';
import { GithubApiIssuesService } from '@github/api/issues/github-api-issues.service';
import { IGithubApiProjectCard } from '@github/api/labels/interfaces/github-api-project-card.interface';
import { AnnotationsService } from '@utils/annotations/annotations.service';
import { EAnnotationWarningIssue } from '@utils/annotations/enums/annotation-warning-issue.enum';
import { getDuplicates } from '@utils/arrays/get-duplicates';
Expand Down Expand Up @@ -46,17 +47,24 @@ export class IssueIncludeProcessor extends AbstractIncludeProcessor<IssueProcess
`is set. This feature is considered as enabled, and so, may alter the processing. Checking...`
)
);
const projectCards: IGithubApiProjectCard[] = this.processor.item.projectCards.nodes;
const projectCardsCount: number = projectCards.length;
const projectNames: string[] = this._getProjectNames(projectCards);

if (this.processor.item.projectCards.nodes.length === 0) {
if (projectCardsCount === 0) {
this.processor.logger.info(`Not containing any project card. Skipping the processing of this issue...`);

return false;
}

const duplicatedProjectNames: string[] = getDuplicates(
this._getProjectNames(this.processor.item.projectCards.nodes),
issuesInputs.issueOnlyAnyProjectCards
this.processor.logger.info(
`Found`,
LoggerService.value(projectCardsCount),
LoggerFormatService.whiteBright(`project card${projectCardsCount > 1 ? `s` : ``} on this issue`),
LoggerService.value(projectNames)
);

const duplicatedProjectNames: string[] = getDuplicates(projectNames, issuesInputs.issueOnlyAnyProjectCards);
const firstDuplicatedProjectCard: string | undefined = _.head(duplicatedProjectNames);

if (!_.isUndefined(firstDuplicatedProjectCard)) {
Expand Down
Loading

0 comments on commit ec9d2ce

Please sign in to comment.