Skip to content

Commit

Permalink
refactor: move and rename the interfaces/classes
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Jan 23, 2021
1 parent e1ba62c commit efacf11
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 245 deletions.
189 changes: 95 additions & 94 deletions __tests__/main.test.ts

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,43 @@ module.exports =
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 4407:
/***/ 4783:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Issue = void 0;
const is_labeled_1 = __nccwpck_require__(6792);
const is_pull_request_1 = __nccwpck_require__(5400);
class Issue {
constructor(options, issue) {
this._options = options;
this.title = issue.title;
this.number = issue.number;
this.created_at = issue.created_at;
this.updated_at = issue.updated_at;
this.labels = issue.labels;
this.pull_request = issue.pull_request;
this.state = issue.state;
this.locked = issue.locked;
this.milestone = issue.milestone;
this.isPullRequest = is_pull_request_1.isPullRequest(this);
this.staleLabel = this._getStaleLabel();
this.isStale = is_labeled_1.isLabeled(this, this.staleLabel);
}
_getStaleLabel() {
return this.isPullRequest
? this._options.stalePrLabel
: this._options.staleIssueLabel;
}
}
exports.Issue = Issue;


/***/ }),

/***/ 3292:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -17,12 +53,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.IssueProcessor = void 0;
exports.IssuesProcessor = void 0;
const github_1 = __nccwpck_require__(5438);
const issue_1 = __nccwpck_require__(4783);
const issue_logger_1 = __nccwpck_require__(2984);
const logger_1 = __nccwpck_require__(6212);
const milestones_1 = __nccwpck_require__(4601);
const get_humanized_date_1 = __nccwpck_require__(965);
const is_date_more_recent_than_1 = __nccwpck_require__(1473);
const is_valid_date_1 = __nccwpck_require__(891);
Expand All @@ -31,10 +63,14 @@ const is_labeled_1 = __nccwpck_require__(6792);
const is_pull_request_1 = __nccwpck_require__(5400);
const should_mark_when_stale_1 = __nccwpck_require__(2461);
const words_to_list_1 = __nccwpck_require__(1883);
const issue_1 = __nccwpck_require__(4783);
const issue_logger_1 = __nccwpck_require__(2984);
const logger_1 = __nccwpck_require__(6212);
const milestones_1 = __nccwpck_require__(4601);
/***
* Handle processing of issues for staleness/closure.
*/
class IssueProcessor {
class IssuesProcessor {
constructor(options, getActor, getIssues, listIssueComments, getLabelCreationDate) {
this._logger = new logger_1.Logger();
this._operationsLeft = 0;
Expand Down Expand Up @@ -157,7 +193,7 @@ class IssueProcessor {
continue; // don't process exempt milestones
}
// should this issue be marked stale?
const shouldBeStale = !IssueProcessor._updatedSince(issue.updated_at, this.options.daysBeforeStale);
const shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, this.options.daysBeforeStale);
// determine if this issue needs to be marked stale first
if (!issue.isStale && shouldBeStale && shouldMarkAsStale) {
issueLogger.info(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
Expand Down Expand Up @@ -196,7 +232,7 @@ class IssueProcessor {
else {
issueLogger.info(`Days before issue close: ${daysBeforeClose}`);
}
const issueHasUpdate = IssueProcessor._updatedSince(issue.updated_at, daysBeforeClose);
const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose);
issueLogger.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
// should we un-stale this issue?
if (this.options.removeStaleWhenUpdated && issueHasComments) {
Expand Down Expand Up @@ -500,43 +536,7 @@ class IssueProcessor {
});
}
}
exports.IssueProcessor = IssueProcessor;


/***/ }),

/***/ 4783:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Issue = void 0;
const is_labeled_1 = __nccwpck_require__(6792);
const is_pull_request_1 = __nccwpck_require__(5400);
class Issue {
constructor(options, issue) {
this._options = options;
this.title = issue.title;
this.number = issue.number;
this.created_at = issue.created_at;
this.updated_at = issue.updated_at;
this.labels = issue.labels;
this.pull_request = issue.pull_request;
this.state = issue.state;
this.locked = issue.locked;
this.milestone = issue.milestone;
this.isPullRequest = is_pull_request_1.isPullRequest(this);
this.staleLabel = this._getStaleLabel();
this.isStale = is_labeled_1.isLabeled(this, this.staleLabel);
}
_getStaleLabel() {
return this.isPullRequest
? this._options.stalePrLabel
: this._options.staleIssueLabel;
}
}
exports.Issue = Issue;
exports.IssuesProcessor = IssuesProcessor;


/***/ }),
Expand Down Expand Up @@ -921,12 +921,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const is_valid_date_1 = __nccwpck_require__(891);
const IssueProcessor_1 = __nccwpck_require__(4407);
const issues_processor_1 = __nccwpck_require__(3292);
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const args = getAndValidateArgs();
const processor = new IssueProcessor_1.IssueProcessor(args);
const processor = new issues_processor_1.IssuesProcessor(args);
yield processor.processIssues();
}
catch (error) {
Expand Down
9 changes: 5 additions & 4 deletions src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone';
import {IssueProcessorOptions, Label} from '../IssueProcessor';
import {Issue} from './issue';

describe('Issue', (): void => {
let issue: Issue;
let optionsInterface: IssueProcessorOptions;
let optionsInterface: IIssuesProcessorOptions;
let issueInterface: IIssue;

beforeEach((): void => {
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('Issue', (): void => {
expect(issue.labels).toStrictEqual([
{
name: 'dummy-name'
} as Label
} as ILabel
]);
});

Expand Down Expand Up @@ -193,7 +194,7 @@ describe('Issue', (): void => {
issueInterface.labels = [
{
name: 'dummy-stale-issue-label'
} as Label
} as ILabel
];
issue = new Issue(optionsInterface, issueInterface);
});
Expand Down
9 changes: 5 additions & 4 deletions src/classes/issue.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {isLabeled} from '../functions/is-labeled';
import {isPullRequest} from '../functions/is-pull-request';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone';
import {IssueProcessorOptions, Label} from '../IssueProcessor';
import {IsoDateString} from '../types/iso-date-string';

export class Issue implements IIssue {
private readonly _options: IssueProcessorOptions;
private readonly _options: IIssuesProcessorOptions;
readonly title: string;
readonly number: number;
created_at: IsoDateString;
updated_at: IsoDateString;
readonly labels: Label[];
readonly labels: ILabel[];
readonly pull_request: Object | null | undefined;
readonly state: string;
readonly locked: boolean;
Expand All @@ -21,7 +22,7 @@ export class Issue implements IIssue {
isStale: boolean;

constructor(
options: Readonly<IssueProcessorOptions>,
options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<IIssue>
) {
this._options = options;
Expand Down
109 changes: 27 additions & 82 deletions src/IssueProcessor.ts → src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,29 @@
import {context, getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils';
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
import {Issue} from './classes/issue';
import {IssueLogger} from './classes/loggers/issue-logger';
import {Logger} from './classes/loggers/logger';
import {Milestones} from './classes/milestones';
import {IssueType} from './enums/issue-type';
import {getHumanizedDate} from './functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from './functions/dates/is-date-more-recent-than';
import {isValidDate} from './functions/dates/is-valid-date';
import {getIssueType} from './functions/get-issue-type';
import {isLabeled} from './functions/is-labeled';
import {isPullRequest} from './functions/is-pull-request';
import {shouldMarkWhenStale} from './functions/should-mark-when-stale';
import {IsoOrRfcDateString} from './types/iso-or-rfc-date-string';
import {wordsToList} from './functions/words-to-list';
import {IIssue} from './interfaces/issue';

export interface PullRequest {
number: number;
head: {
ref: string;
};
}

export interface User {
type: string;
login: string;
}

export interface Comment {
user: User;
}

export interface IssueEvent {
created_at: string;
event: string;
label: Label;
}

export interface Label {
name: string;
}

export interface IssueProcessorOptions {
repoToken: string;
staleIssueMessage: string;
stalePrMessage: string;
closeIssueMessage: string;
closePrMessage: string;
daysBeforeStale: number;
daysBeforeIssueStale: number; // Could be NaN
daysBeforePrStale: number; // Could be NaN
daysBeforeClose: number;
daysBeforeIssueClose: number; // Could be NaN
daysBeforePrClose: number; // Could be NaN
staleIssueLabel: string;
closeIssueLabel: string;
exemptIssueLabels: string;
stalePrLabel: string;
closePrLabel: string;
exemptPrLabels: string;
onlyLabels: string;
operationsPerRun: number;
removeStaleWhenUpdated: boolean;
debugOnly: boolean;
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string;
exemptIssueMilestones: string;
exemptPrMilestones: string;
}
import {IssueType} from '../enums/issue-type';
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
import {isValidDate} from '../functions/dates/is-valid-date';
import {getIssueType} from '../functions/get-issue-type';
import {isLabeled} from '../functions/is-labeled';
import {isPullRequest} from '../functions/is-pull-request';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list';
import {IComment} from '../interfaces/comment';
import {IIssue} from '../interfaces/issue';
import {IIssueEvent} from '../interfaces/issue-event';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IPullRequest} from '../interfaces/pull-request';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {Logger} from './loggers/logger';
import {Milestones} from './milestones';

/***
* Handle processing of issues for staleness/closure.
*/
export class IssueProcessor {
export class IssuesProcessor {
private static _updatedSince(timestamp: string, num_days: number): boolean {
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
const millisSinceLastUpdated =
Expand All @@ -90,20 +35,20 @@ export class IssueProcessor {
private readonly _logger: Logger = new Logger();
private _operationsLeft = 0;
readonly client: InstanceType<typeof GitHub>;
readonly options: IssueProcessorOptions;
readonly options: IIssuesProcessorOptions;
readonly staleIssues: Issue[] = [];
readonly closedIssues: Issue[] = [];
readonly deletedBranchIssues: Issue[] = [];
readonly removedLabelIssues: Issue[] = [];

constructor(
options: IssueProcessorOptions,
options: IIssuesProcessorOptions,
getActor?: () => Promise<string>,
getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: (
issueNumber: number,
sinceDate: string
) => Promise<Comment[]>,
) => Promise<IComment[]>,
getLabelCreationDate?: (
issue: Issue,
label: string
Expand Down Expand Up @@ -271,7 +216,7 @@ export class IssueProcessor {
}

// should this issue be marked stale?
const shouldBeStale = !IssueProcessor._updatedSince(
const shouldBeStale = !IssuesProcessor._updatedSince(
issue.updated_at,
this.options.daysBeforeStale
);
Expand Down Expand Up @@ -346,7 +291,7 @@ export class IssueProcessor {
issueLogger.info(`Days before issue close: ${daysBeforeClose}`);
}

const issueHasUpdate: boolean = IssueProcessor._updatedSince(
const issueHasUpdate: boolean = IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeClose
);
Expand Down Expand Up @@ -419,7 +364,7 @@ export class IssueProcessor {
private async _listIssueComments(
issueNumber: number,
sinceDate: string
): Promise<Comment[]> {
): Promise<IComment[]> {
// find any comments since date on the given issue
try {
const comments = await this.client.issues.listComments({
Expand Down Expand Up @@ -582,7 +527,7 @@ export class IssueProcessor {

private async _getPullRequest(
issue: Issue
): Promise<PullRequest | undefined> {
): Promise<IPullRequest | undefined> {
const issueLogger: IssueLogger = new IssueLogger(issue);
this._operationsLeft -= 1;

Expand Down Expand Up @@ -688,7 +633,7 @@ export class IssueProcessor {
issue_number: issue.number
});

const events: IssueEvent[] = await this.client.paginate(options);
const events: IIssueEvent[] = await this.client.paginate(options);
const reversedEvents = events.reverse();

const staleLabeledEvent = reversedEvents.find(
Expand Down
Loading

0 comments on commit efacf11

Please sign in to comment.