Skip to content

Commit

Permalink
feat(outputs): add some outputs to this action
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Nov 15, 2021
1 parent 19fa98f commit 6c8390f
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 7 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ All the inputs that are used both for issues and Pull Requests.
| issue-days-before-stale | The number of days until the issue is considered as stale. | `30` |
| issue-days-before-close | The number of days until a stale issue is considered as closed. | `10` |

## All the Pull Requests inputs

| Input | Description | Default |
| ----- | ----------- | ------- |
## All the issues outputs

| Output | Description |
| -------------------------- | --------------------------------------------------------------------------- |
| processed-issues-count | The number of issues processed. |
| ignored-issues-count | The number of issues ignored. |
| unaltered-issues-count | The number of issues unaltered (either not good to stale or already stale). |
| stale-issues-count | The number of issues stale. |
| already-stale-issues-count | The number of issues processed which were already stale. |
| remove-stale-issues-count | The number of issues from where the stale state was removed. |

## Debug the action

Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/core/outputs/outputs.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum EOutputs {
ALREADY_STALE_ISSUES_COUNT = `already-stale-issues-count`,
IGNORED_ISSUES_COUNT = `ignored-issues-count`,
UNALTERED_ISSUES_COUNT = `unaltered-issues-count`,
STALE_ISSUES_COUNT = `stale-issues-count`,
PROCESSED_ISSUES_COUNT = `processed-issues-count`,
REMOVE_STALE_ISSUES_COUNT = `remove-stale-issues-count`,
}
66 changes: 66 additions & 0 deletions src/core/outputs/outputs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { EOutputs } from '@core/outputs/outputs.enum';
import { OutputsService } from '@core/outputs/outputs.service';
import { StatisticsService } from '@core/statistics/statistics.service';
import { LoggerService } from '@utils/loggers/logger.service';
import * as core from '@actions/core';

jest.mock(`@utils/loggers/logger.service`);
jest.mock(`@utils/loggers/logger-format.service`);

describe(`OutputsService`, (): void => {
describe(`setOutputs()`, (): void => {
let loggerServiceInfoSpy: jest.SpyInstance;
let coreSetOutputSpy: jest.SpyInstance;

beforeEach((): void => {
loggerServiceInfoSpy = jest.spyOn(LoggerService, `info`).mockImplementation();
coreSetOutputSpy = jest.spyOn(core, `setOutput`).mockImplementation();
});

it(`should log about setting the outputs`, (): void => {
expect.assertions(2);

OutputsService.setOutputs();

expect(loggerServiceInfoSpy).toHaveBeenCalledTimes(2);
expect(loggerServiceInfoSpy).toHaveBeenNthCalledWith(1, `Creating the outputs...`);
});

it(`should set the statistics outputs`, (): void => {
expect.assertions(7);
StatisticsService.processedIssuesCount$$ = 1;
StatisticsService.ignoredIssuesCount$$ = 1;
StatisticsService.unalteredIssuesCount$$ = 1;
StatisticsService.staleIssuesCount$$ = 1;
StatisticsService.alreadyStaleIssuesCount$$ = 1;
StatisticsService.removeStaleIssuesCount$$ = 1;

OutputsService.setOutputs();

expect(coreSetOutputSpy).toHaveBeenCalledTimes(6);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(1, EOutputs.ALREADY_STALE_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(2, EOutputs.IGNORED_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(3, EOutputs.UNALTERED_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(4, EOutputs.STALE_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(5, EOutputs.PROCESSED_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(6, EOutputs.REMOVE_STALE_ISSUES_COUNT, 1);
});

it(`should log about the end of the output setup`, (): void => {
expect.assertions(2);

OutputsService.setOutputs();

expect(loggerServiceInfoSpy).toHaveBeenCalledTimes(2);
expect(loggerServiceInfoSpy).toHaveBeenNthCalledWith(2, `Outputs created`);
});

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

const result = OutputsService.setOutputs();

expect(result).toStrictEqual(OutputsService);
});
});
});
21 changes: 21 additions & 0 deletions src/core/outputs/outputs.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EOutputs } from '@core/outputs/outputs.enum';
import { StatisticsService } from '@core/statistics/statistics.service';
import { LoggerService } from '@utils/loggers/logger.service';
import * as core from '@actions/core';

export class OutputsService {
public static setOutputs(): OutputsService {
LoggerService.info(`Creating the outputs...`);

core.setOutput(EOutputs.ALREADY_STALE_ISSUES_COUNT, StatisticsService.alreadyStaleIssuesCount$$);
core.setOutput(EOutputs.IGNORED_ISSUES_COUNT, StatisticsService.ignoredIssuesCount$$);
core.setOutput(EOutputs.UNALTERED_ISSUES_COUNT, StatisticsService.unalteredIssuesCount$$);
core.setOutput(EOutputs.STALE_ISSUES_COUNT, StatisticsService.staleIssuesCount$$);
core.setOutput(EOutputs.PROCESSED_ISSUES_COUNT, StatisticsService.processedIssuesCount$$);
core.setOutput(EOutputs.REMOVE_STALE_ISSUES_COUNT, StatisticsService.removeStaleIssuesCount$$);

LoggerService.info(`Outputs created`);

return OutputsService;
}
}
12 changes: 12 additions & 0 deletions src/core/stale.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InputsService } from '@core/inputs/inputs.service';
import { IssuesService } from '@core/issues/issues.service';
import { OutputsService } from '@core/outputs/outputs.service';
import { StaleService } from '@core/stale.service';
import { StatisticsService } from '@core/statistics/statistics.service';
import { OctokitService } from '@github/octokit/octokit.service';
Expand All @@ -20,6 +21,7 @@ describe(`StaleService`, (): void => {
let loggerServiceDebugSpy: jest.SpyInstance;
let loggerServiceInfoSpy: jest.SpyInstance;
let statisticsServiceLogsAllStatisticsSpy: jest.SpyInstance;
let outputsServiceSetOutputsSpy: jest.SpyInstance;

beforeEach((): void => {
statisticsServiceInitializeSpy = jest.spyOn(StatisticsService, `initialize`).mockImplementation();
Expand All @@ -31,6 +33,7 @@ describe(`StaleService`, (): void => {
loggerServiceDebugSpy = jest.spyOn(LoggerService, `debug`).mockImplementation();
loggerServiceInfoSpy = jest.spyOn(LoggerService, `info`).mockImplementation();
statisticsServiceLogsAllStatisticsSpy = jest.spyOn(StatisticsService, `logsAllStatistics`).mockImplementation();
outputsServiceSetOutputsSpy = jest.spyOn(OutputsService, `setOutputs`).mockImplementation();
});

it(`should log starting the stale process`, async (): Promise<void> => {
Expand Down Expand Up @@ -183,6 +186,15 @@ describe(`StaleService`, (): void => {
expect(statisticsServiceLogsAllStatisticsSpy).toHaveBeenCalledWith();
});

it(`should set the outputs`, async (): Promise<void> => {
expect.assertions(2);

await StaleService.initialize();

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

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

Expand Down
2 changes: 2 additions & 0 deletions src/core/stale.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InputsService } from '@core/inputs/inputs.service';
import { IssuesService } from '@core/issues/issues.service';
import { OutputsService } from '@core/outputs/outputs.service';
import { StatisticsService } from '@core/statistics/statistics.service';
import { OctokitService } from '@github/octokit/octokit.service';
import { LoggerFormatService } from '@utils/loggers/logger-format.service';
Expand All @@ -16,6 +17,7 @@ export class StaleService {
await IssuesService.process();
LoggerService.info(LoggerFormatService.green(`The stale processing is over`));
StatisticsService.logsAllStatistics();
OutputsService.setOutputs();
} catch (error: unknown) {
if (error instanceof Error) {
LoggerService.error(`[${error.name}] ${error.message}`);
Expand Down

0 comments on commit 6c8390f

Please sign in to comment.