Skip to content

Commit

Permalink
feat(stats): add a statistics regarding the unaltered issues
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Nov 14, 2021
1 parent fff0065 commit acca942
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/core/issues/issue-processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe(`IssueProcessor`, (): void => {

let stopProcessingSpy: jest.SpyInstance;
let statisticsServiceIncreaseStaleIssuesCountSpy: jest.SpyInstance;
let statisticsServiceIncreaseUnalteredIssuesCountSpy: jest.SpyInstance;

beforeEach((): void => {
mockedIssueStaleProcessor.mockClear();
Expand All @@ -393,6 +394,9 @@ describe(`IssueProcessor`, (): void => {
statisticsServiceIncreaseStaleIssuesCountSpy = jest
.spyOn(StatisticsService, `increaseStaleIssuesCount`)
.mockImplementation();
statisticsServiceIncreaseUnalteredIssuesCountSpy = jest
.spyOn(StatisticsService, `increaseUnalteredIssuesCount`)
.mockImplementation();
});

it(`should check if the issue should be stale`, async (): Promise<void> => {
Expand All @@ -419,6 +423,15 @@ describe(`IssueProcessor`, (): void => {
expect(statisticsServiceIncreaseStaleIssuesCountSpy).not.toHaveBeenCalled();
});

it(`should increase the unaltered issues statistic by 1`, async (): Promise<void> => {
expect.assertions(2);

await issueProcessor.processForStale$$();

expect(statisticsServiceIncreaseUnalteredIssuesCountSpy).toHaveBeenCalledTimes(1);
expect(statisticsServiceIncreaseUnalteredIssuesCountSpy).toHaveBeenCalledWith();
});

it(`should stop to process this issue`, async (): Promise<void> => {
expect.assertions(3);

Expand Down Expand Up @@ -453,6 +466,14 @@ describe(`IssueProcessor`, (): void => {
expect(statisticsServiceIncreaseStaleIssuesCountSpy).toHaveBeenCalledWith();
});

it(`should not increase the unaltered issues statistics`, async (): Promise<void> => {
expect.assertions(1);

await issueProcessor.processForStale$$();

expect(statisticsServiceIncreaseUnalteredIssuesCountSpy).not.toHaveBeenCalled();
});

it(`should stop to process this issue`, async (): Promise<void> => {
expect.assertions(2);

Expand Down
2 changes: 2 additions & 0 deletions src/core/issues/issue-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export class IssueProcessor {
if (issueStaleProcessor.shouldStale()) {
await issueStaleProcessor.stale();
StatisticsService.increaseStaleIssuesCount();
} else {
StatisticsService.increaseUnalteredIssuesCount();
}

this.stopProcessing$$();
Expand Down
22 changes: 22 additions & 0 deletions src/core/statistics/statistics.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ describe(`StatisticsService`, (): void => {
});
});

describe(`increaseUnalteredIssuesCount()`, (): void => {
it(`should increase the unaltered issues count`, (): void => {
expect.assertions(1);
StatisticsService.unalteredIssuesCount$$ = 0;

StatisticsService.increaseUnalteredIssuesCount();

expect(StatisticsService.unalteredIssuesCount$$).toBe(1);
});

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

const result = StatisticsService.increaseUnalteredIssuesCount();

expect(result).toStrictEqual(StatisticsService);
});
});

describe(`increaseStaleIssuesCount()`, (): void => {
it(`should increase the stale issues count`, (): void => {
expect.assertions(1);
Expand Down Expand Up @@ -124,6 +143,7 @@ describe(`StatisticsService`, (): void => {
beforeEach((): void => {
StatisticsService.processedIssuesCount$$ = 0;
StatisticsService.ignoredIssuesCount$$ = 0;
StatisticsService.unalteredIssuesCount$$ = 0;
StatisticsService.staleIssuesCount$$ = 0;
StatisticsService.alreadyStaleIssuesCount$$ = 0;
StatisticsService.removeStaleIssuesCount$$ = 0;
Expand All @@ -142,6 +162,7 @@ describe(`StatisticsService`, (): void => {
beforeEach((): void => {
StatisticsService.processedIssuesCount$$ = 1;
StatisticsService.ignoredIssuesCount$$ = 0;
StatisticsService.unalteredIssuesCount$$ = 0;
StatisticsService.staleIssuesCount$$ = 0;
StatisticsService.removeStaleIssuesCount$$ = 0;
StatisticsService.alreadyStaleIssuesCount$$ = 0;
Expand All @@ -161,6 +182,7 @@ describe(`StatisticsService`, (): void => {
beforeEach((): void => {
StatisticsService.processedIssuesCount$$ = 1;
StatisticsService.ignoredIssuesCount$$ = 2;
StatisticsService.unalteredIssuesCount$$ = 0;
StatisticsService.staleIssuesCount$$ = 3;
StatisticsService.alreadyStaleIssuesCount$$ = 4;
StatisticsService.removeStaleIssuesCount$$ = 5;
Expand Down
16 changes: 15 additions & 1 deletion src/core/statistics/statistics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import { mapFilter } from '@utils/maps/map-filter';
import { ETreeRows } from '@utils/trees/tree-rows.enum';
import _ from 'lodash';

type IStat = 'Processed issues' | 'Ignored issues' | 'Stale issues' | 'Remove stale issues' | 'Already stale issues';
type IStat =
| 'Processed issues'
| 'Ignored issues'
| 'Stale issues'
| 'Remove stale issues'
| 'Already stale issues'
| 'Unaltered issues';

export class StatisticsService {
public static processedIssuesCount$$: number = 0;
public static ignoredIssuesCount$$: number = 0;
public static unalteredIssuesCount$$: number = 0;
public static staleIssuesCount$$: number = 0;
public static alreadyStaleIssuesCount$$: number = 0;
public static removeStaleIssuesCount$$: number = 0;
Expand All @@ -27,6 +34,12 @@ export class StatisticsService {
return StatisticsService;
}

public static increaseUnalteredIssuesCount(): StatisticsService {
this.unalteredIssuesCount$$++;

return StatisticsService;
}

public static increaseStaleIssuesCount(): StatisticsService {
this.staleIssuesCount$$++;

Expand Down Expand Up @@ -85,6 +98,7 @@ export class StatisticsService {
return new Map<IStat, number>()
.set(`Processed issues`, StatisticsService.processedIssuesCount$$)
.set(`Ignored issues`, StatisticsService.ignoredIssuesCount$$)
.set(`Unaltered issues`, StatisticsService.unalteredIssuesCount$$)
.set(`Stale issues`, StatisticsService.staleIssuesCount$$)
.set(`Already stale issues`, StatisticsService.alreadyStaleIssuesCount$$)
.set(`Remove stale issues`, StatisticsService.removeStaleIssuesCount$$);
Expand Down

0 comments on commit acca942

Please sign in to comment.