From fec66ab1318ae7e3a059657173e383e84b4e9023 Mon Sep 17 00:00:00 2001 From: TESTELIN Geoffrey Date: Tue, 9 Mar 2021 19:28:20 +0100 Subject: [PATCH] feat(statistics): split closed issues and prs --- dist/index.js | 46 +++++++++++++++++++++-------- src/classes/issues-processor.ts | 8 +++--- src/classes/statistics.ts | 51 +++++++++++++++++++++++++++------ 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/dist/index.js b/dist/index.js index c69952651..28fc72904 100644 --- a/dist/index.js +++ b/dist/index.js @@ -256,7 +256,7 @@ class IssuesProcessor { } for (const issue of issues.values()) { const issueLogger = new issue_logger_1.IssueLogger(issue); - (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementProcessedItemsCount(issue, 1); + (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementProcessedItemsCount(issue); issueLogger.info(`Found this $$type last updated ${issue.updated_at}`); // calculate string based messages for this issue const staleMessage = issue.isPullRequest @@ -553,7 +553,7 @@ class IssuesProcessor { try { this._operationsLeft -= 1; (_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedLabel(); - (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue, 1); + (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue); yield this.client.issues.addLabels({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, @@ -608,7 +608,7 @@ class IssuesProcessor { } try { this._operationsLeft -= 1; - (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedIssuesCount(); + (_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue); yield this.client.issues.update({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, @@ -738,7 +738,7 @@ class IssuesProcessor { const issueLogger = new issue_logger_1.IssueLogger(issue); issueLogger.info(`The $$type is no longer stale. Removing the stale label...`); yield this._removeLabel(issue, staleLabel); - (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue, 1); + (_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue); }); } _removeCloseLabel(issue, closeLabel) { @@ -982,6 +982,7 @@ class Statistics { this._undoStalePullRequestsCount = 0; this._operationsCount = 0; this._closedIssuesCount = 0; + this._closedPullRequestsCount = 0; this._deletedLabelsCount = 0; this._deletedCloseLabelsCount = 0; this._deletedBranchesCount = 0; @@ -1015,9 +1016,11 @@ class Statistics { this._operationsCount = this._options.operationsPerRun - operationsLeft; return this; } - incrementClosedIssuesCount(increment = 1) { - this._closedIssuesCount += increment; - return this; + incrementClosedItemsCount(issue, increment = 1) { + if (issue.isPullRequest) { + return this._incrementClosedPullRequestsCount(increment); + } + return this._incrementClosedIssuesCount(increment); } incrementDeletedLabelsCount(increment = 1) { this._deletedLabelsCount += increment; @@ -1060,7 +1063,7 @@ class Statistics { this._logProcessedIssuesAndPullRequestsCount(); this._logStaleIssuesAndPullRequestsCount(); this._logUndoStaleIssuesAndPullRequestsCount(); - this._logClosedIssuesCount(); + this._logClosedIssuesAndPullRequestsCount(); this._logDeletedLabelsCount(); this._logDeletedCloseLabelsCount(); this._logDeletedBranchesCount(); @@ -1098,6 +1101,14 @@ class Statistics { this._undoStalePullRequestsCount += increment; return this; } + _incrementClosedIssuesCount(increment = 1) { + this._closedIssuesCount += increment; + return this; + } + _incrementClosedPullRequestsCount(increment = 1) { + this._closedPullRequestsCount += increment; + return this; + } _logProcessedIssuesAndPullRequestsCount() { this._logGroup('Processed items', [ { @@ -1134,8 +1145,17 @@ class Statistics { } ]); } - _logClosedIssuesCount() { - this._logCount('Closed issues', this._closedIssuesCount); + _logClosedIssuesAndPullRequestsCount() { + this._logGroup('Closed items', [ + { + name: 'Closed issues', + count: this._closedIssuesCount + }, + { + name: 'Closed PRs', + count: this._closedPullRequestsCount + } + ]); } _logDeletedLabelsCount() { this._logCount('Deleted labels', this._deletedLabelsCount); @@ -1193,9 +1213,11 @@ class Statistics { * @param {IGroupValue[]} values The list of group values to check */ _isGroupValuesPartiallySet(values) { - return (values.map((value) => { + return (values + .map((value) => { return value.count > 0; - }).length >= 2); + }) + .filter((isSet) => isSet).length >= 2); } _getGroupValuesTotalCount(values) { return values.reduce((count, value) => { diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index cc22119fd..716aba562 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -73,7 +73,7 @@ export class IssuesProcessor { for (const issue of issues.values()) { const issueLogger: IssueLogger = new IssueLogger(issue); - this._statistics?.incrementProcessedItemsCount(issue, 1); + this._statistics?.incrementProcessedItemsCount(issue); issueLogger.info(`Found this $$type last updated ${issue.updated_at}`); @@ -507,7 +507,7 @@ export class IssuesProcessor { try { this._operationsLeft -= 1; this._statistics?.incrementAddedLabel(); - this._statistics?.incrementStaleItemsCount(issue, 1); + this._statistics?.incrementStaleItemsCount(issue); await this.client.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, @@ -566,7 +566,7 @@ export class IssuesProcessor { try { this._operationsLeft -= 1; - this._statistics?.incrementClosedIssuesCount(); + this._statistics?.incrementClosedItemsCount(issue); await this.client.issues.update({ owner: context.repo.owner, repo: context.repo.repo, @@ -714,7 +714,7 @@ export class IssuesProcessor { ); await this._removeLabel(issue, staleLabel); - this._statistics?.incrementUndoStaleItemsCount(issue, 1); + this._statistics?.incrementUndoStaleItemsCount(issue); } private async _removeCloseLabel( diff --git a/src/classes/statistics.ts b/src/classes/statistics.ts index 76d449acc..5b3d8307d 100644 --- a/src/classes/statistics.ts +++ b/src/classes/statistics.ts @@ -18,6 +18,7 @@ export class Statistics { private _undoStalePullRequestsCount = 0; private _operationsCount = 0; private _closedIssuesCount = 0; + private _closedPullRequestsCount = 0; private _deletedLabelsCount = 0; private _deletedCloseLabelsCount = 0; private _deletedBranchesCount = 0; @@ -71,10 +72,15 @@ export class Statistics { return this; } - incrementClosedIssuesCount(increment: Readonly = 1): Statistics { - this._closedIssuesCount += increment; + incrementClosedItemsCount( + issue: Readonly, + increment: Readonly = 1 + ): Statistics { + if (issue.isPullRequest) { + return this._incrementClosedPullRequestsCount(increment); + } - return this; + return this._incrementClosedIssuesCount(increment); } incrementDeletedLabelsCount(increment: Readonly = 1): Statistics { @@ -144,7 +150,7 @@ export class Statistics { this._logProcessedIssuesAndPullRequestsCount(); this._logStaleIssuesAndPullRequestsCount(); this._logUndoStaleIssuesAndPullRequestsCount(); - this._logClosedIssuesCount(); + this._logClosedIssuesAndPullRequestsCount(); this._logDeletedLabelsCount(); this._logDeletedCloseLabelsCount(); this._logDeletedBranchesCount(); @@ -208,6 +214,22 @@ export class Statistics { return this; } + private _incrementClosedIssuesCount( + increment: Readonly = 1 + ): Statistics { + this._closedIssuesCount += increment; + + return this; + } + + private _incrementClosedPullRequestsCount( + increment: Readonly = 1 + ): Statistics { + this._closedPullRequestsCount += increment; + + return this; + } + private _logProcessedIssuesAndPullRequestsCount(): void { this._logGroup('Processed items', [ { @@ -247,8 +269,17 @@ export class Statistics { ]); } - private _logClosedIssuesCount(): void { - this._logCount('Closed issues', this._closedIssuesCount); + private _logClosedIssuesAndPullRequestsCount(): void { + this._logGroup('Closed items', [ + { + name: 'Closed issues', + count: this._closedIssuesCount + }, + { + name: 'Closed PRs', + count: this._closedPullRequestsCount + } + ]); } private _logDeletedLabelsCount(): void { @@ -320,9 +351,11 @@ export class Statistics { */ private _isGroupValuesPartiallySet(values: IGroupValue[]): boolean { return ( - values.map((value: Readonly): boolean => { - return value.count > 0; - }).length >= 2 + values + .map((value: Readonly): boolean => { + return value.count > 0; + }) + .filter((isSet: Readonly): boolean => isSet).length >= 2 ); }