Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: add new inputs to clean-up previously added stale comments #912

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ To help us have a clear vision over the workflow and also for you if you are jus

### Initialization

- Check if all GitHub schemas are valid, and stop the processing (failing status) if not
- Reach and parse the inputs from the job
- Authenticate to GitHub API by using the `github-token`

Expand Down Expand Up @@ -165,15 +166,15 @@ To help us have a clear vision over the workflow and also for you if you are jus
- Else, check if issue last update is older than X days (coming from `issue-days-before-close`)
- If it is old, close the issue (using the close reason coming from `issue-close-reason`)
- Check if the action should also add a comment (coming from the `issue-close-comment` input)
- When the input value is not empty, add a comment
- When the input value is not empty, add a comment (with a special header)
- Check if the action should also add extra labels (coming from the `issue-add-labels-after-close` input)
- When the input value is filled list, add the listed labels
- Check if the action should also remove extra labels (coming from the `issue-remove-labels-after-close` input)
- When the input value is filled list, remove the listed labels
- Check if the issue last update is older than X days (coming from the `issue-days-before-stale`)
- If the issue last update is older than X days (coming from the `issue-days-before-stale`)
- Check if the action should also add a comment (coming from the `issue-stale-comment` input)
- When the input value is not empty, add a comment
- When the input value is not empty, add a comment (with a special header)
- Check if the action should also add extra labels (coming from the `issue-add-labels-after-stale` input)
- When the input value is filled list, add the listed labels
- Check if the action should also remove extra labels (coming from the `issue-remove-labels-after-stale` input)
Expand Down Expand Up @@ -211,7 +212,7 @@ To help us have a clear vision over the workflow and also for you if you are jus
- Else, check if pull request last update is older than X days (coming from `pull-request-days-before-close`)
- If it is old, close the pull request
- Check if the action should also add a comment (coming from the `pull-request-close-comment` input)
- When the input value is not empty, add a comment
- When the input value is not empty, add a comment (with a special header)
- Check if the action should also add extra labels (coming from the `pull-request-add-labels-after-close` input)
- When the input value is filled list, add the listed labels
- Check if the action should also remove extra labels (coming from the `pull-request-remove-labels-after-close` input)
Expand All @@ -225,7 +226,7 @@ To help us have a clear vision over the workflow and also for you if you are jus
- Convert to draft and stop the processing
- If the draft mode is disabled
- Check if the action should also add a comment (coming from the `pull-request-stale-comment` input)
- When the input value is not empty, add a comment
- When the input value is not empty, add a comment (with a special header)
- Check if the action should also add extra labels (coming from the `pull-request-add-labels-after-stale` input)
- When the input value is filled list, add the listed labels
- Check if the action should also remove extra labels (coming from the `pull-request-remove-labels-after-stale` input)
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/inputs/core-inputs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CoreInputsService {
return fallback;
}

// @todo find a way to get rid of this type hack
// TODO find a way to get rid of this type hack
return inputValue as unknown as TEnum;
}
}
16 changes: 13 additions & 3 deletions src/core/processing/abstract-comments-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CommonInputsService } from '@core/inputs/common-inputs.service';
import { ICommonInputs } from '@core/inputs/interfaces/common-inputs.interface';
import { IssueProcessor } from '@core/processing/issues/issue-processor';
import { PullRequestProcessor } from '@core/processing/pull-requests/pull-request-processor';
import { ECommentType } from '@utils/enums/comment-type.enum';
import { ICommentHeaderOptions } from '@utils/interfaces/comment-header-options.interface';
import { LoggerService } from '@utils/loggers/logger.service';
import { AbstractProcessor } from '@utils/processors/abstract-processor';
import { IComment } from '@utils/types/comment';
Expand Down Expand Up @@ -31,7 +33,9 @@ export abstract class AbstractCommentsProcessor<
if (!commonInputs.dryRun) {
this.processor.logger.info(`Adding the stale comment...`);

await this._addComment(this._getItemId(), staleComment);
await this._addComment(this._getItemId(), staleComment, {
commentType: ECommentType.STALE,
});
}

this._increaseAddedCommentsCountStatistic();
Expand All @@ -55,7 +59,9 @@ export abstract class AbstractCommentsProcessor<
if (!commonInputs.dryRun) {
this.processor.logger.info(`Adding the close comment...`);

await this._addComment(this._getItemId(), closeComment);
await this._addComment(this._getItemId(), closeComment, {
commentType: ECommentType.CLOSE,
});
}

this._increaseAddedCommentsCountStatistic();
Expand All @@ -64,7 +70,11 @@ export abstract class AbstractCommentsProcessor<

protected abstract _getItemId(): IUuid;

protected abstract _addComment(itemId: Readonly<IUuid>, comment: Readonly<IComment>): Promise<void>;
protected abstract _addComment(
itemId: Readonly<IUuid>,
comment: Readonly<IComment>,
commentHeaderOptions: Readonly<ICommentHeaderOptions>
): Promise<void>;

protected abstract _getCloseComment(): IComment | '';

Expand Down
16 changes: 10 additions & 6 deletions src/core/processing/abstract-processing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
}

// Expose the item data for debug purpose
LoggerService.debug(JSON.stringify(item));
this._logItem(item);

// Note: we do not wish to have a blazing fast action
// The goal is to process a single item at a time
Expand Down Expand Up @@ -138,7 +138,7 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
const hasReachedQueriesLimit: boolean = this.hasReachedQueriesLimit$$();

if (hasReachedQueriesLimit) {
// @todo add the reached count
// TODO add the reached count
LoggerService.info(
`The limit of ${_.toLower(
this._itemType
Expand All @@ -148,13 +148,13 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
return false;
}

// @todo add the reached count versus reached count total
// TODO add the reached count versus reached count total
LoggerService.info(`The limit of API queries calls count is not reached yet, continuing...`);

const hasReachedMutationsLimit: boolean = this.hasReachedMutationsLimit$$();

if (hasReachedMutationsLimit) {
// @todo add the reached count
// TODO add the reached count
LoggerService.info(
`The limit of ${_.toLower(
this._itemType
Expand All @@ -164,7 +164,7 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
return false;
}

// @todo add the reached count versus reached count total
// TODO add the reached count versus reached count total
LoggerService.info(`The limit of API mutations calls count is not reached yet, continuing...`);

LoggerService.info(
Expand Down Expand Up @@ -195,7 +195,7 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
/**
* @description
* Allow to check if the items are issues or pull requests
* @todo find a better way to check that with pure typings
* TODO find a better way to check that with pure typings
* @param {IGithubApiGetIssues | IGithubApiGetPullRequests} _items The items to check
* @returns {boolean} Return true when the items are issues
* @private
Expand All @@ -204,6 +204,10 @@ export abstract class AbstractProcessingService<TItems extends IGithubApiGetIssu
return this._itemType === `issue`;
}

private _logItem(item: Readonly<IGithubApiIssue | IGithubApiPullRequest>): void {
LoggerService.debug(JSON.stringify(item));
}

/**
* @description
* Check if the limit of API queries calls count is reached
Expand Down
14 changes: 12 additions & 2 deletions src/core/processing/issues/issue-comments-processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IssueCommentsProcessor } from '@core/processing/issues/issue-comments-p
import { IssueProcessor } from '@core/processing/issues/issue-processor';
import { IssuesStatisticsService } from '@core/statistics/issues-statistics.service';
import { GithubApiIssueCommentsService } from '@github/api/comments/github-api-issue-comments.service';
import { ECommentType } from '@utils/enums/comment-type.enum';
import { ICommentHeaderOptions } from '@utils/interfaces/comment-header-options.interface';
import { IUuid } from '@utils/types/uuid';
import faker from 'faker';
import { createHydratedMock } from 'ts-auto-mock';
Expand Down Expand Up @@ -180,7 +182,7 @@ describe(`IssueCommentsProcessor`, (): void => {
});

it(`should add the stale comment on the issue`, async (): Promise<void> => {
expect.assertions(4);
expect.assertions(6);

await issueCommentsProcessor.processStaleComment();

Expand All @@ -192,6 +194,10 @@ describe(`IssueCommentsProcessor`, (): void => {
);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(3, `Adding the stale comment...`);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(4, `Stale comment added`);
expect(githubApiIssueCommentsServiceAddCommentSpy).toHaveBeenCalledTimes(1);
expect(githubApiIssueCommentsServiceAddCommentSpy).toHaveBeenCalledWith(issueId, `dummy-comment`, {
commentType: ECommentType.STALE,
} as ICommentHeaderOptions);
});

it(`should increase the added issues comments count by 1`, async (): Promise<void> => {
Expand Down Expand Up @@ -350,7 +356,7 @@ describe(`IssueCommentsProcessor`, (): void => {
});

it(`should add the close comment on the issue`, async (): Promise<void> => {
expect.assertions(4);
expect.assertions(6);

await issueCommentsProcessor.processCloseComment();

Expand All @@ -362,6 +368,10 @@ describe(`IssueCommentsProcessor`, (): void => {
);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(3, `Adding the close comment...`);
expect(issueProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(4, `Close comment added`);
expect(githubApiIssueCommentsServiceAddCommentSpy).toHaveBeenCalledTimes(1);
expect(githubApiIssueCommentsServiceAddCommentSpy).toHaveBeenCalledWith(issueId, `dummy-comment`, {
commentType: ECommentType.CLOSE,
} as ICommentHeaderOptions);
});

it(`should increase the added issues comments count by 1`, async (): Promise<void> => {
Expand Down
9 changes: 7 additions & 2 deletions src/core/processing/issues/issue-comments-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AbstractCommentsProcessor } from '@core/processing/abstract-comments-pr
import { IssueProcessor } from '@core/processing/issues/issue-processor';
import { IssuesStatisticsService } from '@core/statistics/issues-statistics.service';
import { GithubApiIssueCommentsService } from '@github/api/comments/github-api-issue-comments.service';
import { ICommentHeaderOptions } from '@utils/interfaces/comment-header-options.interface';
import { IComment } from '@utils/types/comment';
import { IUuid } from '@utils/types/uuid';

Expand Down Expand Up @@ -35,7 +36,11 @@ export class IssueCommentsProcessor extends AbstractCommentsProcessor<IssueProce
IssuesStatisticsService.getInstance().increaseAddedIssuesCommentsCount();
}

protected _addComment(itemId: Readonly<IUuid>, comment: Readonly<IComment>): Promise<void> {
return this.githubApiIssueCommentsService$$.addComment(itemId, comment);
protected _addComment(
itemId: Readonly<IUuid>,
comment: Readonly<IComment>,
commentHeaderOptions: Readonly<ICommentHeaderOptions>
): Promise<void> {
return this.githubApiIssueCommentsService$$.addComment(itemId, comment, commentHeaderOptions);
}
}
6 changes: 3 additions & 3 deletions src/core/processing/issues/issue-ignore-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class IssueIgnoreProcessor extends AbstractIgnoreProcessor<IssueProcessor

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.labels;

if (totalCount > GithubApiIssuesService.labelsPerIssue) {
Expand Down Expand Up @@ -241,7 +241,7 @@ export class IssueIgnoreProcessor extends AbstractIgnoreProcessor<IssueProcessor

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.assignees;

if (totalCount > GithubApiIssuesService.assigneesPerIssue) {
Expand Down Expand Up @@ -288,7 +288,7 @@ export class IssueIgnoreProcessor extends AbstractIgnoreProcessor<IssueProcessor

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.projectCards;

if (totalCount > GithubApiIssuesService.projectCardsPerIssue) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/issues/issue-include-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class IssueIncludeProcessor extends AbstractIncludeProcessor<IssueProcess

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.projectCards;

if (totalCount > GithubApiIssuesService.projectCardsPerIssue) {
Expand Down Expand Up @@ -227,7 +227,7 @@ export class IssueIncludeProcessor extends AbstractIncludeProcessor<IssueProcess

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.assignees;

if (totalCount > GithubApiIssuesService.assigneesPerIssue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { PullRequestCommentsProcessor } from '@core/processing/pull-requests/pul
import { PullRequestProcessor } from '@core/processing/pull-requests/pull-request-processor';
import { PullRequestsStatisticsService } from '@core/statistics/pull-requests-statistics.service';
import { GithubApiPullRequestCommentsService } from '@github/api/comments/github-api-pull-request-comments.service';
import { ECommentType } from '@utils/enums/comment-type.enum';
import { ICommentHeaderOptions } from '@utils/interfaces/comment-header-options.interface';
import { IUuid } from '@utils/types/uuid';
import faker from 'faker';
import { createHydratedMock } from 'ts-auto-mock';
Expand Down Expand Up @@ -187,7 +189,7 @@ describe(`PullRequestCommentsProcessor`, (): void => {
});

it(`should add the stale comment on the pull request`, async (): Promise<void> => {
expect.assertions(4);
expect.assertions(6);

await pullRequestCommentsProcessor.processStaleComment();

Expand All @@ -199,6 +201,14 @@ describe(`PullRequestCommentsProcessor`, (): void => {
);
expect(pullRequestProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(3, `Adding the stale comment...`);
expect(pullRequestProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(4, `Stale comment added`);
expect(githubApiPullRequestCommentsServiceAddCommentSpy).toHaveBeenCalledTimes(1);
expect(githubApiPullRequestCommentsServiceAddCommentSpy).toHaveBeenCalledWith(
pullRequestId,
`dummy-comment`,
{
commentType: ECommentType.STALE,
} as ICommentHeaderOptions
);
});

it(`should increase the added pull requests comments count by 1`, async (): Promise<void> => {
Expand Down Expand Up @@ -364,7 +374,7 @@ describe(`PullRequestCommentsProcessor`, (): void => {
});

it(`should add the close comment on the pull request`, async (): Promise<void> => {
expect.assertions(4);
expect.assertions(6);

await pullRequestCommentsProcessor.processCloseComment();

Expand All @@ -376,6 +386,14 @@ describe(`PullRequestCommentsProcessor`, (): void => {
);
expect(pullRequestProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(3, `Adding the close comment...`);
expect(pullRequestProcessorLoggerInfoSpy).toHaveBeenNthCalledWith(4, `Close comment added`);
expect(githubApiPullRequestCommentsServiceAddCommentSpy).toHaveBeenCalledTimes(1);
expect(githubApiPullRequestCommentsServiceAddCommentSpy).toHaveBeenCalledWith(
pullRequestId,
`dummy-comment`,
{
commentType: ECommentType.CLOSE,
} as ICommentHeaderOptions
);
});

it(`should increase the added pull requests comments count by 1`, async (): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AbstractCommentsProcessor } from '@core/processing/abstract-comments-pr
import { PullRequestProcessor } from '@core/processing/pull-requests/pull-request-processor';
import { PullRequestsStatisticsService } from '@core/statistics/pull-requests-statistics.service';
import { GithubApiPullRequestCommentsService } from '@github/api/comments/github-api-pull-request-comments.service';
import { ICommentHeaderOptions } from '@utils/interfaces/comment-header-options.interface';
import { IComment } from '@utils/types/comment';
import { IUuid } from '@utils/types/uuid';

Expand Down Expand Up @@ -35,7 +36,11 @@ export class PullRequestCommentsProcessor extends AbstractCommentsProcessor<Pull
PullRequestsStatisticsService.getInstance().increaseAddedPullRequestsCommentsCount();
}

protected _addComment(itemId: Readonly<IUuid>, comment: Readonly<IComment>): Promise<void> {
return this.githubApiPullRequestCommentsService$$.addComment(itemId, comment);
protected _addComment(
itemId: Readonly<IUuid>,
comment: Readonly<IComment>,
commentHeaderOptions: Readonly<ICommentHeaderOptions>
): Promise<void> {
return this.githubApiPullRequestCommentsService$$.addComment(itemId, comment, commentHeaderOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class PullRequestIgnoreProcessor extends AbstractIgnoreProcessor<PullRequ

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.labels;

if (totalCount > GithubApiPullRequestsService.labelsPerPullRequest) {
Expand Down Expand Up @@ -247,7 +247,7 @@ export class PullRequestIgnoreProcessor extends AbstractIgnoreProcessor<PullRequ

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.assignees;

if (totalCount > GithubApiPullRequestsService.assigneesPerPullRequest) {
Expand Down Expand Up @@ -294,7 +294,7 @@ export class PullRequestIgnoreProcessor extends AbstractIgnoreProcessor<PullRequ

this.processor.logger.debug(`Note: in case of issue, we may need to use a RegExp to ignore sensitivity`);

// @todo handle the pagination
// TODO handle the pagination
const { totalCount } = this.processor.item.projectCards;

if (totalCount > GithubApiPullRequestsService.projectCardsPerPullRequest) {
Expand Down
Loading