feat: remove the ignore-updates option

BREAKING CHANGE:
The option ignore-updates was removed
This commit is contained in:
TESTELIN Geoffrey
2021-10-08 18:06:39 +02:00
parent b98591d49e
commit 3021a55a47
10 changed files with 410 additions and 823 deletions

View File

@@ -1,251 +1,163 @@
import {DefaultProcessorOptions} from '../../__tests__/constants/default-processor-options';
import {generateIIssue} from '../../__tests__/functions/generate-iissue';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IgnoreUpdates} from './ignore-updates';
import {Issue} from './issue';
describe('IgnoreUpdates', (): void => {
let ignoreUpdates: IgnoreUpdates;
let optionsInterface: IIssuesProcessorOptions;
let issue: Issue;
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {
...DefaultProcessorOptions,
ignoreIssueUpdates: true
};
issueInterface = generateIIssue();
});
describe('shouldIgnoreUpdates()', (): void => {
describe('when the given issue is not a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = false;
});
describe('when the given options are not configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignoreIssueUpdates;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = true;
});
describe('when the given options are not configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignoreIssueUpdates;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
});
describe('when the given issue is a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = {};
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = false;
});
describe('when the given options are not configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignorePrUpdates;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
describe('when the given options are configured to not reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = true;
});
describe('when the given options are not configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignorePrUpdates;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
});
});
});
import {DefaultProcessorOptions} from '../../__tests__/constants/default-processor-options';
import {generateIIssue} from '../../__tests__/functions/generate-iissue';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IgnoreUpdates} from './ignore-updates';
import {Issue} from './issue';
describe('IgnoreUpdates', (): void => {
let ignoreUpdates: IgnoreUpdates;
let optionsInterface: IIssuesProcessorOptions;
let issue: Issue;
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {
...DefaultProcessorOptions,
ignoreIssueUpdates: true
};
issueInterface = generateIIssue();
});
describe('shouldIgnoreUpdates()', (): void => {
describe('when the given issue is not a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
describe('when the given issue is a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = {};
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
});
});

View File

@@ -1,90 +1,66 @@
import {Option} from '../enums/option';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
export class IgnoreUpdates {
private readonly _options: IIssuesProcessorOptions;
private readonly _issue: Issue;
private readonly _issueLogger: IssueLogger;
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
this._options = options;
this._issue = issue;
this._issueLogger = new IssueLogger(issue);
}
shouldIgnoreUpdates(): boolean {
return this._shouldIgnoreUpdates();
}
private _shouldIgnoreUpdates(): boolean {
return this._issue.isPullRequest
? this._shouldIgnorePullRequestUpdates()
: this._shouldIgnoreIssueUpdates();
}
private _shouldIgnorePullRequestUpdates(): boolean {
if (this._options.ignorePrUpdates === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
} else if (this._options.ignorePrUpdates === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
this._logIgnoreUpdates();
return this._options.ignoreUpdates;
}
private _shouldIgnoreIssueUpdates(): boolean {
if (this._options.ignoreIssueUpdates === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
} else if (this._options.ignoreIssueUpdates === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
this._logIgnoreUpdates();
return this._options.ignoreUpdates;
}
private _logIgnoreUpdates(): void {
if (this._options.ignoreUpdates) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
} else {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
}
}
}
import {Option} from '../enums/option';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
export class IgnoreUpdates {
private readonly _options: IIssuesProcessorOptions;
private readonly _issue: Issue;
private readonly _issueLogger: IssueLogger;
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
this._options = options;
this._issue = issue;
this._issueLogger = new IssueLogger(issue);
}
shouldIgnoreUpdates(): boolean {
return this._shouldIgnoreUpdates();
}
private _shouldIgnoreUpdates(): boolean {
return this._issue.isPullRequest
? this._shouldIgnorePullRequestUpdates()
: this._shouldIgnoreIssueUpdates();
}
private _shouldIgnorePullRequestUpdates(): boolean {
if (this._options.ignorePrUpdates) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
}
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
private _shouldIgnoreIssueUpdates(): boolean {
if (this._options.ignoreIssueUpdates) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
}
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
}

View File

@@ -58,9 +58,8 @@ describe('Issue', (): void => {
enableStatistics: false,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
ignoreIssueUpdates: false,
ignorePrUpdates: false,
exemptDraftPr: false
};
issueInterface = {

View File

@@ -43,7 +43,6 @@ export enum Option {
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates',
ExemptDraftPr = 'exempt-draft-pr'

View File

@@ -47,8 +47,7 @@ export interface IIssuesProcessorOptions {
enableStatistics: boolean;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
ignoreUpdates: boolean;
ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined;
ignoreIssueUpdates: boolean;
ignorePrUpdates: boolean;
exemptDraftPr: boolean;
}

View File

@@ -84,9 +84,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
ignoreIssueUpdates: core.getInput('ignore-issue-updates') === 'true',
ignorePrUpdates: core.getInput('ignore-pr-updates') === 'true',
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true'
};