Skip to content

Commit

Permalink
feat(outputs): add new outputs removed-issues-labels-count and `iss…
Browse files Browse the repository at this point in the history
…ues-labels-count`

Closes #858.
  • Loading branch information
C0ZEN committed Aug 30, 2022
1 parent 929efa7 commit 1b9ae0b
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ All the inputs that are used both for issues and pull requests.
| [remove-stale-issues-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/remove-stale-issues-count-output) | The number of issues from where the stale state was removed. |
| [close-issues-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/close-issues-count-output) | The number of issues closed. |
| [added-issues-comments-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/added-issues-comments-count-output) | The number of added issues comments. |
| [issues-labels-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/issues-labels-count-output) | The number of issues labels mutated (added or removed). |
| [added-issues-labels-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/added-issues-labels-count-output) | The number of added issues labels. |
| [removed-issues-labels-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/removed-issues-labels-count-output) | The number of removed issues labels. |
| [called-api-issues-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/called-api-issues-count-output) | The number of GitHub API calls performed for the issues. |
| [called-api-issues-queries-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/called-api-issues-queries-count-output) | The number of GitHub API queries calls performed for the issues. |
| [called-api-issues-mutations-count](https://sonia-stale-action.vercel.app/docs/issues/outputs/called-api-issues-mutations-count-output) | The number of GitHub API mutations calls performed for the issues. |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ outputs:
description: 'The number of issues closed.'
added-issues-comments-count:
description: 'The number of added issues comments.'
issues-labels-count:
description: 'The number of issues labels mutated (added or removed).'
added-issues-labels-count:
description: 'The number of added issues labels.'
removed-issues-labels-count:
description: 'The number of removed issues labels.'
called-api-issues-count:
description: 'The number of GitHub API calls performed for the issues.'
called-api-issues-queries-count:
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/04-all-outputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ The list of all the outputs.
| [already-stale-issues-count](issues/outputs/already-stale-issues-count-output) | The number of issues processed which were already stale. | `number` |
| [remove-stale-issues-count](issues/outputs/remove-stale-issues-count-output) | The number of issues from where the stale state was removed. | `number` |
| [close-issues-count](issues/outputs/close-issues-count-output) | The number of issues closed. | `number` |
| [issues-comments-count](issues/outputs/issues-comments-count-output) | The number of issues labels mutated (added or removed). | `number` |
| [added-issues-comments-count](issues/outputs/added-issues-comments-count-output) | The number of added issues comments. | `number` |
| [removed-issues-comments-count](issues/outputs/removed-issues-comments-count-output) | The number of removed issues comments. | `number` |
| [added-issues-labels-count](issues/outputs/added-issues-labels-count-output) | The number of added issues labels. | `number` |
| [called-api-issues-count](issues/outputs/called-api-issues-count-output) | The number of GitHub API calls performed for the issues. | `number` |
| [called-api-issues-queries-count](issues/outputs/called-api-issues-queries-count-output) | The number of GitHub API queries calls performed for the issues. | `number` |
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/06-issues/02-outputs/01-all-outputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ The list of all issues the outputs.
| [remove-stale-issues-count](remove-stale-issues-count-output) | The number of issues from where the stale state was removed. | `number` |
| [close-issues-count](close-issues-count-output) | The number of issues closed. | `number` |
| [added-issues-comments-count](added-issues-comments-count-output) | The number of added issues comments. | `number` |
| [issues-labels-count](issues-labels-count-output) | The number of issues labels mutated (added or removed). | `number` |
| [added-issues-labels-count](added-issues-labels-count-output) | The number of added issues labels. | `number` |
| [removed-issues-labels-count](removed-issues-labels-count-output) | The number of removed issues labels. | `number` |
| [called-api-issues-count](called-api-issues-count-output) | The number of GitHub API calls performed for the issues. | `number` |
| [called-api-issues-queries-count](called-api-issues-queries-count-output) | The number of GitHub API queries calls performed for the issues. | `number` |
| [called-api-issues-mutations-count](called-api-issues-mutations-count-output) | The number of GitHub API mutations calls performed for the issues. | `number` |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: issues-labels-count-output
title: Issues labels count output
description: |
All the information you need to know about the issues labels count output.
Including a detailed description and an example.
tags:
- Issues
- Outputs
---

### Output {#output}

Name: `issues-labels-count`
Type: `number`

### Description {#description}

This output will expose the number of issues labels mutated (added or removed).

### Example {#example}

```yml {6-7}
# ...
steps:
- name: Stale
id: stale
uses: sonia-corporation/stale@latest
- name: Count
run: echo "${{ steps.Stale.outputs.issues-labels-count }}"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: removed-issues-labels-count-output
title: Removed issues labels count output
description: |
All the information you need to know about the removed issues labels count output.
Including a detailed description and an example.
tags:
- Issues
- Outputs
---

### Output {#output}

Name: `removed-issues-labels-count`
Type: `number`

### Description {#description}

This output will expose the number of removed issues labels.

### Example {#example}

```yml {6-7}
# ...
steps:
- name: Stale
id: stale
uses: sonia-corporation/stale@latest
- name: Count
run: echo "${{ steps.Stale.outputs.removed-issues-labels-count }}"
```
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ describe(`IssuesOutputsAnnotationsService`, (): void => {
IssuesStatisticsService.getInstance().closedIssuesCount = 7;
IssuesStatisticsService.getInstance().addedIssuesCommentsCount = 8;
IssuesStatisticsService.getInstance().addedIssuesLabelsCount = 9;
IssuesStatisticsService.getInstance().calledApiIssuesQueriesCount = 10;
IssuesStatisticsService.getInstance().calledApiIssuesMutationsCount = 11;
IssuesStatisticsService.getInstance().removedIssuesLabelsCount = 10;
IssuesStatisticsService.getInstance().calledApiIssuesQueriesCount = 11;
IssuesStatisticsService.getInstance().calledApiIssuesMutationsCount = 12;
});

it(`should log the issues outputs annotations`, (): void => {
expect.assertions(13);
expect.assertions(15);

service.noticeAllOutputs();

expect(coreNoticeSpy).toHaveBeenCalledTimes(12);
expect(coreNoticeSpy).toHaveBeenCalledTimes(14);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(1, `Already stale issues: 5`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(2, `Ignored issues: 2`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(3, `Unaltered issues: 3`);
Expand All @@ -78,10 +79,12 @@ describe(`IssuesOutputsAnnotationsService`, (): void => {
expect(coreNoticeSpy).toHaveBeenNthCalledWith(6, `Remove stale issues: 6`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(7, `Closed issues: 7`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(8, `Added issues comments: 8`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(9, `Added issues labels: 9`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(10, `Called api issues: 21`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(11, `Called api issues queries: 10`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(12, `Called api issues mutations: 11`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(9, `Issues labels: 19`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(10, `Added issues labels: 9`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(11, `Removed issues labels: 10`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(12, `Called api issues: 23`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(13, `Called api issues queries: 11`);
expect(coreNoticeSpy).toHaveBeenNthCalledWith(14, `Called api issues mutations: 12`);
});
});

Expand All @@ -96,6 +99,7 @@ describe(`IssuesOutputsAnnotationsService`, (): void => {
IssuesStatisticsService.getInstance().closedIssuesCount = 0;
IssuesStatisticsService.getInstance().addedIssuesCommentsCount = 0;
IssuesStatisticsService.getInstance().addedIssuesLabelsCount = 0;
IssuesStatisticsService.getInstance().removedIssuesLabelsCount = 0;
IssuesStatisticsService.getInstance().calledApiIssuesQueriesCount = 0;
IssuesStatisticsService.getInstance().calledApiIssuesMutationsCount = 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ const MAP: { [key in keyof typeof EIssuesOutputs]: () => void } = {
IGNORED_ISSUES_COUNT(): void {
noticeCount(`Ignored issues`, IssuesStatisticsService.getInstance().ignoredIssuesCount);
},
ISSUES_LABELS_COUNT(): void {
noticeCount(`Issues labels`, IssuesStatisticsService.getInstance().issuesLabelsCount);
},
PROCESSED_ISSUES_COUNT(): void {
noticeCount(`Processed issues`, IssuesStatisticsService.getInstance().processedIssuesCount);
},
REMOVE_STALE_ISSUES_COUNT(): void {
noticeCount(`Remove stale issues`, IssuesStatisticsService.getInstance().removeStaleIssuesCount);
},
REMOVED_ISSUES_LABELS_COUNT(): void {
noticeCount(`Removed issues labels`, IssuesStatisticsService.getInstance().removedIssuesLabelsCount);
},
STALE_ISSUES_COUNT(): void {
noticeCount(`Stale issues`, IssuesStatisticsService.getInstance().staleIssuesCount);
},
Expand Down
2 changes: 2 additions & 0 deletions src/core/outputs/enums/issues-outputs.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export enum EIssuesOutputs {
REMOVE_STALE_ISSUES_COUNT = `remove-stale-issues-count`,
CLOSE_ISSUES_COUNT = `close-issues-count`,
ADDED_ISSUES_COMMENTS_COUNT = `added-issues-comments-count`,
ISSUES_LABELS_COUNT = `issues-labels-count`,
ADDED_ISSUES_LABELS_COUNT = `added-issues-labels-count`,
REMOVED_ISSUES_LABELS_COUNT = `removed-issues-labels-count`,
CALLED_API_ISSUES_COUNT = `called-api-issues-count`,
CALLED_API_ISSUES_QUERIES_COUNT = `called-api-issues-queries-count`,
CALLED_API_ISSUES_MUTATIONS_COUNT = `called-api-issues-mutations-count`,
Expand Down
15 changes: 9 additions & 6 deletions src/core/outputs/issues-outputs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe(`IssuesOutputsService`, (): void => {
});

it(`should set the statistics outputs`, (): void => {
expect.assertions(13);
expect.assertions(15);
IssuesStatisticsService.getInstance().processedIssuesCount = 1;
IssuesStatisticsService.getInstance().ignoredIssuesCount = 1;
IssuesStatisticsService.getInstance().unalteredIssuesCount = 1;
Expand All @@ -61,12 +61,13 @@ describe(`IssuesOutputsService`, (): void => {
IssuesStatisticsService.getInstance().closedIssuesCount = 1;
IssuesStatisticsService.getInstance().addedIssuesCommentsCount = 1;
IssuesStatisticsService.getInstance().addedIssuesLabelsCount = 1;
IssuesStatisticsService.getInstance().removedIssuesLabelsCount = 1;
IssuesStatisticsService.getInstance().calledApiIssuesQueriesCount = 1;
IssuesStatisticsService.getInstance().calledApiIssuesMutationsCount = 1;

service.setOutputs();

expect(coreSetOutputSpy).toHaveBeenCalledTimes(12);
expect(coreSetOutputSpy).toHaveBeenCalledTimes(14);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(1, EIssuesOutputs.ALREADY_STALE_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(2, EIssuesOutputs.IGNORED_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(3, EIssuesOutputs.UNALTERED_ISSUES_COUNT, 1);
Expand All @@ -75,10 +76,12 @@ describe(`IssuesOutputsService`, (): void => {
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(6, EIssuesOutputs.REMOVE_STALE_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(7, EIssuesOutputs.CLOSE_ISSUES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(8, EIssuesOutputs.ADDED_ISSUES_COMMENTS_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(9, EIssuesOutputs.ADDED_ISSUES_LABELS_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(10, EIssuesOutputs.CALLED_API_ISSUES_COUNT, 2);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(11, EIssuesOutputs.CALLED_API_ISSUES_QUERIES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(12, EIssuesOutputs.CALLED_API_ISSUES_MUTATIONS_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(9, EIssuesOutputs.ISSUES_LABELS_COUNT, 2);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(10, EIssuesOutputs.ADDED_ISSUES_LABELS_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(11, EIssuesOutputs.REMOVED_ISSUES_LABELS_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(12, EIssuesOutputs.CALLED_API_ISSUES_COUNT, 2);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(13, EIssuesOutputs.CALLED_API_ISSUES_QUERIES_COUNT, 1);
expect(coreSetOutputSpy).toHaveBeenNthCalledWith(14, EIssuesOutputs.CALLED_API_ISSUES_MUTATIONS_COUNT, 1);
});

it(`should log about the end of the issues output setup`, (): void => {
Expand Down
2 changes: 2 additions & 0 deletions src/core/outputs/issues-outputs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const MAP: { [key in keyof typeof EIssuesOutputs]: () => number } = {
CALLED_API_ISSUES_QUERIES_COUNT: (): number => IssuesStatisticsService.getInstance().calledApiIssuesQueriesCount,
CLOSE_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().closedIssuesCount,
IGNORED_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().ignoredIssuesCount,
ISSUES_LABELS_COUNT: (): number => IssuesStatisticsService.getInstance().calledApiIssuesCount,
PROCESSED_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().processedIssuesCount,
REMOVE_STALE_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().removeStaleIssuesCount,
REMOVED_ISSUES_LABELS_COUNT: (): number => IssuesStatisticsService.getInstance().removedIssuesLabelsCount,
STALE_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().staleIssuesCount,
UNALTERED_ISSUES_COUNT: (): number => IssuesStatisticsService.getInstance().unalteredIssuesCount,
};
Expand Down
4 changes: 4 additions & 0 deletions src/core/statistics/issues-statistics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class IssuesStatisticsService extends AbstractStatisticsService<IStat> {
public unalteredIssuesCount: number = 0;
protected readonly _statisticsName: 'issues' = `issues`;

public get issuesLabelsCount(): number {
return this.addedIssuesLabelsCount + this.removedIssuesLabelsCount;
}

public get calledApiIssuesCount(): number {
return this.calledApiIssuesQueriesCount + this.calledApiIssuesMutationsCount;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FakeIssuesProcessor } from '@tests/utils/fake-issues-processor';
import { DateTime } from 'luxon';

describe(`Issue to stale extra labels`, (): void => {
describe(`Issue to stale add extra labels`, (): void => {
let issueSut: FakeIssuesProcessor;

describe(`when the issue should not have extra labels when stale`, (): void => {
describe(`when the issue should not have extra labels added when stale`, (): void => {
beforeEach((): void => {
issueSut = new FakeIssuesProcessor({
issueAddLabelsAfterStale: [],
Expand Down Expand Up @@ -54,7 +54,7 @@ describe(`Issue to stale extra labels`, (): void => {
});
});

it(`should stale the issue and add the extra labels`, async (): Promise<void> => {
it(`should stale the issue and add the extra label`, async (): Promise<void> => {
expect.assertions(11);

await issueSut.process();
Expand Down Expand Up @@ -122,7 +122,7 @@ describe(`Issue to stale extra labels`, (): void => {

describe(`when the issue should add three more labels when stale`, (): void => {
beforeEach((): void => {
issueSut.setExtraStaleLabels([`extra-stale-label-1`, `extra-stale-label-2`, `extra-stale-label-3`]);
issueSut.setExtraAddedStaleLabels([`extra-stale-label-1`, `extra-stale-label-2`, `extra-stale-label-3`]);
});

it(`should stale the issue and not add some extra labels`, async (): Promise<void> => {
Expand Down

0 comments on commit 1b9ae0b

Please sign in to comment.