Skip to content

Commit

Permalink
feat(statistics): split closed issues and prs
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Mar 9, 2021
1 parent c34d448 commit fec66ab
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 25 deletions.
46 changes: 34 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1060,7 +1063,7 @@ class Statistics {
this._logProcessedIssuesAndPullRequestsCount();
this._logStaleIssuesAndPullRequestsCount();
this._logUndoStaleIssuesAndPullRequestsCount();
this._logClosedIssuesCount();
this._logClosedIssuesAndPullRequestsCount();
this._logDeletedLabelsCount();
this._logDeletedCloseLabelsCount();
this._logDeletedBranchesCount();
Expand Down Expand Up @@ -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', [
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -714,7 +714,7 @@ export class IssuesProcessor {
);

await this._removeLabel(issue, staleLabel);
this._statistics?.incrementUndoStaleItemsCount(issue, 1);
this._statistics?.incrementUndoStaleItemsCount(issue);
}

private async _removeCloseLabel(
Expand Down
51 changes: 42 additions & 9 deletions src/classes/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,10 +72,15 @@ export class Statistics {
return this;
}

incrementClosedIssuesCount(increment: Readonly<number> = 1): Statistics {
this._closedIssuesCount += increment;
incrementClosedItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementClosedPullRequestsCount(increment);
}

return this;
return this._incrementClosedIssuesCount(increment);
}

incrementDeletedLabelsCount(increment: Readonly<number> = 1): Statistics {
Expand Down Expand Up @@ -144,7 +150,7 @@ export class Statistics {
this._logProcessedIssuesAndPullRequestsCount();
this._logStaleIssuesAndPullRequestsCount();
this._logUndoStaleIssuesAndPullRequestsCount();
this._logClosedIssuesCount();
this._logClosedIssuesAndPullRequestsCount();
this._logDeletedLabelsCount();
this._logDeletedCloseLabelsCount();
this._logDeletedBranchesCount();
Expand Down Expand Up @@ -208,6 +214,22 @@ export class Statistics {
return this;
}

private _incrementClosedIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._closedIssuesCount += increment;

return this;
}

private _incrementClosedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._closedPullRequestsCount += increment;

return this;
}

private _logProcessedIssuesAndPullRequestsCount(): void {
this._logGroup('Processed items', [
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -320,9 +351,11 @@ export class Statistics {
*/
private _isGroupValuesPartiallySet(values: IGroupValue[]): boolean {
return (
values.map((value: Readonly<IGroupValue>): boolean => {
return value.count > 0;
}).length >= 2
values
.map((value: Readonly<IGroupValue>): boolean => {
return value.count > 0;
})
.filter((isSet: Readonly<boolean>): boolean => isSet).length >= 2
);
}

Expand Down

0 comments on commit fec66ab

Please sign in to comment.