Skip to content

Commit

Permalink
refactor(issue): change the way to count the operations
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Apr 30, 2021
1 parent 7fae5fa commit 4cf12ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ exports.Issue = void 0;
const is_labeled_1 = __nccwpck_require__(6792);
const is_pull_request_1 = __nccwpck_require__(5400);
const operations_1 = __nccwpck_require__(7957);
class Issue extends operations_1.Operations {
class Issue {
constructor(options, issue) {
super();
this.operations = new operations_1.Operations();
this._options = options;
this.title = issue.title;
this.number = issue.number;
Expand Down Expand Up @@ -274,7 +274,7 @@ class IssuesProcessor {
return millisSinceLastUpdated <= daysInMillis;
}
static _endIssueProcessing(issue) {
const consumedOperationsCount = issue.getConsumedOperationsCount();
const consumedOperationsCount = issue.operations.getConsumedOperationsCount();
if (consumedOperationsCount > 0) {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(chalk_1.default.cyan(consumedOperationsCount), `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`);
Expand Down Expand Up @@ -518,7 +518,7 @@ class IssuesProcessor {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`Checking for label on $$type`);
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({
owner: github_1.context.repo.owner,
Expand Down Expand Up @@ -607,7 +607,7 @@ class IssuesProcessor {
if (!skipMessage) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
yield this.client.issues.createComment({
owner: github_1.context.repo.owner,
Expand All @@ -622,7 +622,7 @@ class IssuesProcessor {
}
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
(_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue);
yield this.client.issues.addLabels({
Expand Down Expand Up @@ -650,7 +650,7 @@ class IssuesProcessor {
if (closeMessage) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
yield this.client.issues.createComment({
owner: github_1.context.repo.owner,
Expand All @@ -666,7 +666,7 @@ class IssuesProcessor {
if (closeLabel) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
yield this.client.issues.addLabels({
owner: github_1.context.repo.owner,
Expand All @@ -681,7 +681,7 @@ class IssuesProcessor {
}
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue);
yield this.client.issues.update({
owner: github_1.context.repo.owner,
Expand All @@ -704,7 +704,7 @@ class IssuesProcessor {
}
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount();
const pullRequest = yield this.client.pulls.get({
owner: github_1.context.repo.owner,
Expand Down Expand Up @@ -736,7 +736,7 @@ class IssuesProcessor {
issueLogger.info(`Deleting the branch "${chalk_1.default.cyan(branch)}" from closed $$type`);
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
yield this.client.git.deleteRef({
owner: github_1.context.repo.owner,
Expand All @@ -761,7 +761,7 @@ class IssuesProcessor {
}
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue);
yield this.client.issues.removeLabel({
owner: github_1.context.repo.owner,
Expand Down
4 changes: 2 additions & 2 deletions src/classes/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IMilestone} from '../interfaces/milestone';
import {IsoDateString} from '../types/iso-date-string';
import {Operations} from './operations';

export class Issue extends Operations implements IIssue {
export class Issue implements IIssue {
private readonly _options: IIssuesProcessorOptions;
readonly title: string;
readonly number: number;
Expand All @@ -21,6 +21,7 @@ export class Issue extends Operations implements IIssue {
readonly milestone: IMilestone | undefined;
readonly assignees: IAssignee[];
isStale: boolean;
operations = new Operations();

get isPullRequest(): boolean {
return isPullRequest(this);
Expand All @@ -38,7 +39,6 @@ export class Issue extends Operations implements IIssue {
options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<IIssue>
) {
super();
this._options = options;
this.title = issue.title;
this.number = issue.number;
Expand Down
20 changes: 10 additions & 10 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class IssuesProcessor {
}

private static _endIssueProcessing(issue: Issue): void {
const consumedOperationsCount: number = issue.getConsumedOperationsCount();
const consumedOperationsCount: number = issue.operations.getConsumedOperationsCount();

if (consumedOperationsCount > 0) {
const issueLogger: IssueLogger = new IssueLogger(issue);
Expand Down Expand Up @@ -448,7 +448,7 @@ export class IssuesProcessor {
issueLogger.info(`Checking for label on $$type`);

this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({
owner: context.repo.owner,
Expand Down Expand Up @@ -593,7 +593,7 @@ export class IssuesProcessor {
if (!skipMessage) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementAddedItemsComment(issue);
await this.client.issues.createComment({
owner: context.repo.owner,
Expand All @@ -608,7 +608,7 @@ export class IssuesProcessor {

try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementStaleItemsCount(issue);
await this.client.issues.addLabels({
Expand Down Expand Up @@ -640,7 +640,7 @@ export class IssuesProcessor {
if (closeMessage) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementAddedItemsComment(issue);
await this.client.issues.createComment({
owner: context.repo.owner,
Expand All @@ -656,7 +656,7 @@ export class IssuesProcessor {
if (closeLabel) {
try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementAddedItemsLabel(issue);
await this.client.issues.addLabels({
owner: context.repo.owner,
Expand All @@ -671,7 +671,7 @@ export class IssuesProcessor {

try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementClosedItemsCount(issue);
await this.client.issues.update({
owner: context.repo.owner,
Expand All @@ -695,7 +695,7 @@ export class IssuesProcessor {

try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
Expand Down Expand Up @@ -735,7 +735,7 @@ export class IssuesProcessor {

try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementDeletedBranchesCount();
await this.client.git.deleteRef({
owner: context.repo.owner,
Expand Down Expand Up @@ -766,7 +766,7 @@ export class IssuesProcessor {

try {
this._operations.consumeOperation();
issue.consumeOperation();
issue.operations.consumeOperation();
this._statistics?.incrementDeletedItemsLabelsCount(issue);
await this.client.issues.removeLabel({
owner: context.repo.owner,
Expand Down

0 comments on commit 4cf12ba

Please sign in to comment.