docs(stale-issue-comment): update the docs to remove that omitting the option will not send a message (#522)

* chore(assignees): add logs

* docs(stale-issue-comment): update the docs to remove that omitting will not send a message

To be sure, what would be even better is to add a test using the default config (because the main issue is that the default options of the specs are not matching the ones from the action).

Closes #521

* test(comment): add more coverage to test the stale issue message

* docs(readme): improve the wording

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>

* refactor: simplify the code to use the stats for the specs

* chore(rebase): fix rebase issue

* chore(statistics): fix issue due to rebase

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>
This commit is contained in:
Geoffrey Testelin
2021-09-22 15:18:19 +02:00
committed by GitHub
parent 9912fa74d1
commit b98591d49e
5 changed files with 258 additions and 176 deletions

View File

@@ -69,8 +69,9 @@ export class IssuesProcessor {
readonly deletedBranchIssues: Issue[] = [];
readonly removedLabelIssues: Issue[] = [];
readonly addedLabelIssues: Issue[] = [];
readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger();
private readonly _statistics: Statistics | undefined;
constructor(options: IIssuesProcessorOptions) {
this.options = options;
@@ -93,7 +94,7 @@ export class IssuesProcessor {
}
if (this.options.enableStatistics) {
this._statistics = new Statistics();
this.statistics = new Statistics();
}
}
@@ -105,7 +106,7 @@ export class IssuesProcessor {
this._logger.info(
LoggerService.green(`No more issues found to process. Exiting...`)
);
this._statistics
this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -158,7 +159,7 @@ export class IssuesProcessor {
'option which is currently set to'
)} ${LoggerService.cyan(this.options.operationsPerRun)}`
);
this._statistics
this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -180,7 +181,7 @@ export class IssuesProcessor {
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[]
): Promise<void> {
this._statistics?.incrementProcessedItemsCount(issue);
this.statistics?.incrementProcessedItemsCount(issue);
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(
@@ -515,7 +516,7 @@ export class IssuesProcessor {
// Find any comments since date on the given issue
try {
this.operations.consumeOperation();
this._statistics?.incrementFetchedItemsCommentsCount();
this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -546,7 +547,7 @@ export class IssuesProcessor {
direction: this.options.ascending ? 'asc' : 'desc',
page
});
this._statistics?.incrementFetchedItemsCount(issueResult.data.length);
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
return issueResult.data.map(
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue)
@@ -568,7 +569,7 @@ export class IssuesProcessor {
issueLogger.info(`Checking for label on this $$type`);
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedItemsEventsCount();
this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -598,7 +599,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedPullRequestsCount();
this.statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
@@ -771,7 +772,7 @@ export class IssuesProcessor {
if (!skipMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
this.statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) {
await this.client.issues.createComment({
@@ -788,8 +789,8 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementStaleItemsCount(issue);
this.statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
@@ -818,7 +819,8 @@ export class IssuesProcessor {
if (closeMessage) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue);
this.statistics?.incrementAddedItemsComment(issue);
this.addedCloseCommentIssues.push(issue);
if (!this.options.debugOnly) {
await this.client.issues.createComment({
@@ -836,7 +838,7 @@ export class IssuesProcessor {
if (closeLabel) {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
@@ -853,7 +855,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementClosedItemsCount(issue);
this.statistics?.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.update({
@@ -872,7 +874,11 @@ export class IssuesProcessor {
private async _deleteBranch(issue: Issue): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(`Delete branch from closed $$type - ${issue.title}`);
issueLogger.info(`Delete
branch from closed $
$type
-
${issue.title}`);
const pullRequest: IPullRequest | undefined | void =
await this.getPullRequest(issue);
@@ -891,7 +897,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedBranchesCount();
this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.git.deleteRef({
@@ -926,7 +932,7 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedItemsLabelsCount(issue);
this.statistics?.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) {
await this.client.issues.removeLabel({
@@ -1060,7 +1066,7 @@ export class IssuesProcessor {
try {
this.operations.consumeOperation();
this._statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.issues.addLabels({
owner: context.repo.owner,
@@ -1087,7 +1093,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, staleLabel);
this._statistics?.incrementUndoStaleItemsCount(issue);
this.statistics?.incrementUndoStaleItemsCount(issue);
}
private async _removeCloseLabel(
@@ -1124,7 +1130,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, closeLabel, true);
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
this.statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else {
issueLogger.info(
LoggerService.white('└──'),

View File

@@ -9,28 +9,28 @@ interface IGroupValue {
export class Statistics {
private readonly _logger: Logger = new Logger();
private _processedIssuesCount = 0;
private _processedPullRequestsCount = 0;
private _staleIssuesCount = 0;
private _stalePullRequestsCount = 0;
private _undoStaleIssuesCount = 0;
private _undoStalePullRequestsCount = 0;
private _operationsCount = 0;
private _closedIssuesCount = 0;
private _closedPullRequestsCount = 0;
private _deletedIssuesLabelsCount = 0;
private _deletedPullRequestsLabelsCount = 0;
private _deletedCloseIssuesLabelsCount = 0;
private _deletedClosePullRequestsLabelsCount = 0;
private _deletedBranchesCount = 0;
private _addedIssuesLabelsCount = 0;
private _addedPullRequestsLabelsCount = 0;
private _addedIssuesCommentsCount = 0;
private _addedPullRequestsCommentsCount = 0;
private _fetchedItemsCount = 0;
private _fetchedItemsEventsCount = 0;
private _fetchedItemsCommentsCount = 0;
private _fetchedPullRequestsCount = 0;
processedIssuesCount = 0;
processedPullRequestsCount = 0;
staleIssuesCount = 0;
stalePullRequestsCount = 0;
undoStaleIssuesCount = 0;
undoStalePullRequestsCount = 0;
operationsCount = 0;
closedIssuesCount = 0;
closedPullRequestsCount = 0;
deletedIssuesLabelsCount = 0;
deletedPullRequestsLabelsCount = 0;
deletedCloseIssuesLabelsCount = 0;
deletedClosePullRequestsLabelsCount = 0;
deletedBranchesCount = 0;
addedIssuesLabelsCount = 0;
addedPullRequestsLabelsCount = 0;
addedIssuesCommentsCount = 0;
addedPullRequestsCommentsCount = 0;
fetchedItemsCount = 0;
fetchedItemsEventsCount = 0;
fetchedItemsCommentsCount = 0;
fetchedPullRequestsCount = 0;
incrementProcessedItemsCount(
issue: Readonly<Issue>,
@@ -66,7 +66,7 @@ export class Statistics {
}
setOperationsCount(operationsCount: Readonly<number>): Statistics {
this._operationsCount = operationsCount;
this.operationsCount = operationsCount;
return this;
}
@@ -105,7 +105,7 @@ export class Statistics {
}
incrementDeletedBranchesCount(increment: Readonly<number> = 1): Statistics {
this._deletedBranchesCount += increment;
this.deletedBranchesCount += increment;
return this;
}
@@ -133,7 +133,7 @@ export class Statistics {
}
incrementFetchedItemsCount(increment: Readonly<number> = 1): Statistics {
this._fetchedItemsCount += increment;
this.fetchedItemsCount += increment;
return this;
}
@@ -141,7 +141,7 @@ export class Statistics {
incrementFetchedItemsEventsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedItemsEventsCount += increment;
this.fetchedItemsEventsCount += increment;
return this;
}
@@ -149,7 +149,7 @@ export class Statistics {
incrementFetchedItemsCommentsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedItemsCommentsCount += increment;
this.fetchedItemsCommentsCount += increment;
return this;
}
@@ -157,7 +157,7 @@ export class Statistics {
incrementFetchedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedPullRequestsCount += increment;
this.fetchedPullRequestsCount += increment;
return this;
}
@@ -185,7 +185,7 @@ export class Statistics {
private _incrementProcessedIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._processedIssuesCount += increment;
this.processedIssuesCount += increment;
return this;
}
@@ -193,7 +193,7 @@ export class Statistics {
private _incrementProcessedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._processedPullRequestsCount += increment;
this.processedPullRequestsCount += increment;
return this;
}
@@ -201,7 +201,7 @@ export class Statistics {
private _incrementStaleIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._staleIssuesCount += increment;
this.staleIssuesCount += increment;
return this;
}
@@ -209,7 +209,7 @@ export class Statistics {
private _incrementStalePullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._stalePullRequestsCount += increment;
this.stalePullRequestsCount += increment;
return this;
}
@@ -217,7 +217,7 @@ export class Statistics {
private _incrementUndoStaleIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._undoStaleIssuesCount += increment;
this.undoStaleIssuesCount += increment;
return this;
}
@@ -225,7 +225,7 @@ export class Statistics {
private _incrementUndoStalePullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._undoStalePullRequestsCount += increment;
this.undoStalePullRequestsCount += increment;
return this;
}
@@ -233,7 +233,7 @@ export class Statistics {
private _incrementClosedIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._closedIssuesCount += increment;
this.closedIssuesCount += increment;
return this;
}
@@ -241,7 +241,7 @@ export class Statistics {
private _incrementClosedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._closedPullRequestsCount += increment;
this.closedPullRequestsCount += increment;
return this;
}
@@ -249,7 +249,7 @@ export class Statistics {
private _incrementDeletedIssuesLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedIssuesLabelsCount += increment;
this.deletedIssuesLabelsCount += increment;
return this;
}
@@ -257,7 +257,7 @@ export class Statistics {
private _incrementDeletedPullRequestsLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedPullRequestsLabelsCount += increment;
this.deletedPullRequestsLabelsCount += increment;
return this;
}
@@ -265,7 +265,7 @@ export class Statistics {
private _incrementDeletedCloseIssuesLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedCloseIssuesLabelsCount += increment;
this.deletedCloseIssuesLabelsCount += increment;
return this;
}
@@ -273,7 +273,7 @@ export class Statistics {
private _incrementDeletedClosePullRequestsLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedClosePullRequestsLabelsCount += increment;
this.deletedClosePullRequestsLabelsCount += increment;
return this;
}
@@ -281,7 +281,7 @@ export class Statistics {
private _incrementAddedIssuesLabel(
increment: Readonly<number> = 1
): Statistics {
this._addedIssuesLabelsCount += increment;
this.addedIssuesLabelsCount += increment;
return this;
}
@@ -289,7 +289,7 @@ export class Statistics {
private _incrementAddedPullRequestsLabel(
increment: Readonly<number> = 1
): Statistics {
this._addedPullRequestsLabelsCount += increment;
this.addedPullRequestsLabelsCount += increment;
return this;
}
@@ -297,7 +297,7 @@ export class Statistics {
private _incrementAddedIssuesComment(
increment: Readonly<number> = 1
): Statistics {
this._addedIssuesCommentsCount += increment;
this.addedIssuesCommentsCount += increment;
return this;
}
@@ -305,7 +305,7 @@ export class Statistics {
private _incrementAddedPullRequestsComment(
increment: Readonly<number> = 1
): Statistics {
this._addedPullRequestsCommentsCount += increment;
this.addedPullRequestsCommentsCount += increment;
return this;
}
@@ -314,11 +314,11 @@ export class Statistics {
this._logGroup('Processed items', [
{
name: 'Processed issues',
count: this._processedIssuesCount
count: this.processedIssuesCount
},
{
name: 'Processed PRs',
count: this._processedPullRequestsCount
count: this.processedPullRequestsCount
}
]);
}
@@ -327,11 +327,11 @@ export class Statistics {
this._logGroup('New stale items', [
{
name: 'New stale issues',
count: this._staleIssuesCount
count: this.staleIssuesCount
},
{
name: 'New stale PRs',
count: this._stalePullRequestsCount
count: this.stalePullRequestsCount
}
]);
}
@@ -340,11 +340,11 @@ export class Statistics {
this._logGroup('No longer stale items', [
{
name: 'No longer stale issues',
count: this._undoStaleIssuesCount
count: this.undoStaleIssuesCount
},
{
name: 'No longer stale PRs',
count: this._undoStalePullRequestsCount
count: this.undoStalePullRequestsCount
}
]);
}
@@ -353,11 +353,11 @@ export class Statistics {
this._logGroup('Closed items', [
{
name: 'Closed issues',
count: this._closedIssuesCount
count: this.closedIssuesCount
},
{
name: 'Closed PRs',
count: this._closedPullRequestsCount
count: this.closedPullRequestsCount
}
]);
}
@@ -366,11 +366,11 @@ export class Statistics {
this._logGroup('Deleted items labels', [
{
name: 'Deleted issues labels',
count: this._deletedIssuesLabelsCount
count: this.deletedIssuesLabelsCount
},
{
name: 'Deleted PRs labels',
count: this._deletedPullRequestsLabelsCount
count: this.deletedPullRequestsLabelsCount
}
]);
}
@@ -379,28 +379,28 @@ export class Statistics {
this._logGroup('Deleted close items labels', [
{
name: 'Deleted close issues labels',
count: this._deletedCloseIssuesLabelsCount
count: this.deletedCloseIssuesLabelsCount
},
{
name: 'Deleted close PRs labels',
count: this._deletedClosePullRequestsLabelsCount
count: this.deletedClosePullRequestsLabelsCount
}
]);
}
private _logDeletedBranchesCount(): void {
this._logCount('Deleted branches', this._deletedBranchesCount);
this._logCount('Deleted branches', this.deletedBranchesCount);
}
private _logAddedIssuesAndPullRequestsLabelsCount(): void {
this._logGroup('Added items labels', [
{
name: 'Added issues labels',
count: this._addedIssuesLabelsCount
count: this.addedIssuesLabelsCount
},
{
name: 'Added PRs labels',
count: this._addedPullRequestsLabelsCount
count: this.addedPullRequestsLabelsCount
}
]);
}
@@ -409,33 +409,33 @@ export class Statistics {
this._logGroup('Added items comments', [
{
name: 'Added issues comments',
count: this._addedIssuesCommentsCount
count: this.addedIssuesCommentsCount
},
{
name: 'Added PRs comments',
count: this._addedPullRequestsCommentsCount
count: this.addedPullRequestsCommentsCount
}
]);
}
private _logFetchedItemsCount(): void {
this._logCount('Fetched items', this._fetchedItemsCount);
this._logCount('Fetched items', this.fetchedItemsCount);
}
private _logFetchedItemsEventsCount(): void {
this._logCount('Fetched items events', this._fetchedItemsEventsCount);
this._logCount('Fetched items events', this.fetchedItemsEventsCount);
}
private _logFetchedItemsCommentsCount(): void {
this._logCount('Fetched items comments', this._fetchedItemsCommentsCount);
this._logCount('Fetched items comments', this.fetchedItemsCommentsCount);
}
private _logFetchedPullRequestsCount(): void {
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount);
this._logCount('Fetched pull requests', this.fetchedPullRequestsCount);
}
private _logOperationsCount(): void {
this._logCount('Operations performed', this._operationsCount);
this._logCount('Operations performed', this.operationsCount);
}
private _logCount(name: Readonly<string>, count: Readonly<number>): void {