Skip to content

Commit

Permalink
fix(logs): fix logs regarding updates and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Jul 18, 2021
1 parent b5276d4 commit 70890e5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 49 deletions.
50 changes: 26 additions & 24 deletions dist/index.js
Expand Up @@ -565,36 +565,34 @@ class IssuesProcessor {
issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`);
const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue);
issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenUpdatedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`);
if (shouldRemoveStaleWhenUpdated) {
if (!shouldRemoveStaleWhenUpdated) {
issueLogger.info(`The stale label should not be removed due to an update`);
}
else {
issueLogger.info(`The stale label should be removed if all conditions met`);
}
const shouldRemoveStaleWhenCommented = this._shouldRemoveStaleWhenCommented(issue);
issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenCommentedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenCommented)}`);
if (shouldRemoveStaleWhenCommented) {
if (!shouldRemoveStaleWhenCommented) {
issueLogger.info(`The stale label should not be removed due to a comment`);
}
else {
issueLogger.info(`The stale label should be removed if all conditions met`);
}
issueLogger.info(`Checking if the stale label should be removed...`);
// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
issueLogger.info(`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`);
yield this._removeStaleLabel(issue, staleLabel);
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
issueLogger.info(logger_service_1.LoggerService.white('├── '), `Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`);
yield this._removeStaleLabel(issue, staleLabel, true);
issueLogger.info(logger_service_1.LoggerService.white('└── '), `Skipping the process since the $$type is now un-stale`);
return; // Nothing to do because it is no longer stale
}
else if (shouldRemoveStaleWhenCommented && issueHasComments) {
issueLogger.info(`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`);
yield this._removeStaleLabel(issue, staleLabel);
issueLogger.info(logger_service_1.LoggerService.white('├── '), `Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`);
yield this._removeStaleLabel(issue, staleLabel, true);
issueLogger.info(logger_service_1.LoggerService.white('└── '), `Skipping the process since the $$type is now un-stale`);
// Are there labels to remove or add when an issue is no longer stale?
yield this._removeLabelsWhenUnstale(issue, labelsToRemoveWhenUnstale);
yield this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
return; // Nothing to do because it is no longer stale
}
else {
issueLogger.info(logger_service_1.LoggerService.white('└── '), `The stale label should not be removed`);
}
// Now start closing logic
if (daysBeforeClose < 0) {
return; // Nothing to do because we aren't closing stale issues
Expand Down Expand Up @@ -637,8 +635,8 @@ class IssuesProcessor {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`Marking this $$type as stale`);
this.staleIssues.push(issue);
// if the issue is being marked stale, the updated date should be changed to right now
// so that close calculations work correctly
// If the issue is being marked stale, the updated date should be changed to right now
// So that close calculations work correctly
const newUpdatedAtDate = new Date();
issue.updated_at = newUpdatedAtDate.toString();
if (!skipMessage) {
Expand Down Expand Up @@ -783,11 +781,11 @@ class IssuesProcessor {
});
}
// Remove a label from an issue or a pull request
_removeLabel(issue, label, isSubStep = false) {
_removeLabel(issue, label, stepType = 'normal') {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const issueLogger = new issue_logger_1.IssueLogger(issue);
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('├── ') : ''}Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`);
issueLogger.info(`${stepType !== 'normal' ? logger_service_1.LoggerService.white('├── ') : ''}Removing the label "${logger_service_1.LoggerService.cyan(label)}" from this $$type...`);
this.removedLabelIssues.push(issue);
try {
this._consumeIssueOperation(issue);
Expand All @@ -800,10 +798,14 @@ class IssuesProcessor {
name: label
});
}
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('└── ') : ''}The label "${logger_service_1.LoggerService.cyan(label)}" was removed`);
issueLogger.info(`${stepType !== 'normal'
? logger_service_1.LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''}The label "${logger_service_1.LoggerService.cyan(label)}" was removed`);
}
catch (error) {
issueLogger.error(`${isSubStep ? logger_service_1.LoggerService.white('└── ') : ''}Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`);
issueLogger.error(`${stepType !== 'normal'
? logger_service_1.LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''}Error when removing the label: "${logger_service_1.LoggerService.cyan(error.message)}"`);
}
});
}
Expand Down Expand Up @@ -915,12 +917,12 @@ class IssuesProcessor {
}
return this.options.removeStaleWhenCommented;
}
_removeStaleLabel(issue, staleLabel) {
_removeStaleLabel(issue, staleLabel, isSubStep = false) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
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);
issueLogger.info(`${isSubStep ? logger_service_1.LoggerService.white('├── ') : ''}The $$type is no longer stale. Removing the stale label...`);
yield this._removeLabel(issue, staleLabel, 'sub');
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue);
});
}
Expand All @@ -936,7 +938,7 @@ class IssuesProcessor {
}
if (is_labeled_1.isLabeled(issue, closeLabel)) {
issueLogger.info(logger_service_1.LoggerService.white('├──'), `The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`);
yield this._removeLabel(issue, closeLabel, true);
yield this._removeLabel(issue, closeLabel, 'last');
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue);
}
else {
Expand Down
64 changes: 39 additions & 25 deletions src/classes/issues-processor.ts
Expand Up @@ -599,14 +599,10 @@ export class IssuesProcessor {
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`
);

if (shouldRemoveStaleWhenUpdated) {
if (!shouldRemoveStaleWhenUpdated) {
issueLogger.info(
`The stale label should not be removed due to an update`
);
} else {
issueLogger.info(
`The stale label should be removed if all conditions met`
);
}

const shouldRemoveStaleWhenCommented: boolean =
Expand All @@ -618,39 +614,50 @@ export class IssuesProcessor {
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenCommented)}`
);

if (shouldRemoveStaleWhenCommented) {
if (!shouldRemoveStaleWhenCommented) {
issueLogger.info(
`The stale label should not be removed due to a comment`
);
} else {
issueLogger.info(
`The stale label should be removed if all conditions met`
);
}

issueLogger.info(`Checking if the stale label should be removed...`);

// Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`
);
await this._removeStaleLabel(issue, staleLabel);
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(`Skipping the process since the $$type is now un-stale`);
issueLogger.info(
LoggerService.white('└── '),
`Skipping the process since the $$type is now un-stale`
);

return; // Nothing to do because it is no longer stale
} else if (shouldRemoveStaleWhenCommented && issueHasComments) {
issueLogger.info(
LoggerService.white('├── '),
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`
);
await this._removeStaleLabel(issue, staleLabel);
await this._removeStaleLabel(issue, staleLabel, true);

issueLogger.info(
LoggerService.white('└── '),
`Skipping the process since the $$type is now un-stale`
);

// Are there labels to remove or add when an issue is no longer stale?
await this._removeLabelsWhenUnstale(issue, labelsToRemoveWhenUnstale);
await this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);

issueLogger.info(`Skipping the process since the $$type is now un-stale`);

return; // Nothing to do because it is no longer stale
} else {
issueLogger.info(
LoggerService.white('└── '),
`The stale label should not be removed`
);
}

// Now start closing logic
Expand Down Expand Up @@ -729,8 +736,8 @@ export class IssuesProcessor {
issueLogger.info(`Marking this $$type as stale`);
this.staleIssues.push(issue);

// if the issue is being marked stale, the updated date should be changed to right now
// so that close calculations work correctly
// If the issue is being marked stale, the updated date should be changed to right now
// So that close calculations work correctly
const newUpdatedAtDate: Date = new Date();
issue.updated_at = newUpdatedAtDate.toString();

Expand Down Expand Up @@ -899,13 +906,13 @@ export class IssuesProcessor {
private async _removeLabel(
issue: Issue,
label: string,
isSubStep: Readonly<boolean> = false
stepType: Readonly<'normal' | 'sub' | 'last'> = 'normal'
): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);

issueLogger.info(
`${
isSubStep ? LoggerService.white('├── ') : ''
stepType !== 'normal' ? LoggerService.white('├── ') : ''
}Removing the label "${LoggerService.cyan(label)}" from this $$type...`
);
this.removedLabelIssues.push(issue);
Expand All @@ -925,13 +932,17 @@ export class IssuesProcessor {

issueLogger.info(
`${
isSubStep ? LoggerService.white('└── ') : ''
stepType !== 'normal'
? LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''
}The label "${LoggerService.cyan(label)}" was removed`
);
} catch (error) {
issueLogger.error(
`${
isSubStep ? LoggerService.white('└── ') : ''
stepType !== 'normal'
? LoggerService.white(stepType === 'last' ? '└── ' : '├── ')
: ''
}Error when removing the label: "${LoggerService.cyan(error.message)}"`
);
}
Expand Down Expand Up @@ -1080,15 +1091,18 @@ export class IssuesProcessor {

private async _removeStaleLabel(
issue: Issue,
staleLabel: Readonly<string>
staleLabel: Readonly<string>,
isSubStep: Readonly<boolean> = false
): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);

issueLogger.info(
`The $$type is no longer stale. Removing the stale label...`
`${
isSubStep ? LoggerService.white('├── ') : ''
}The $$type is no longer stale. Removing the stale label...`
);

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

Expand Down Expand Up @@ -1125,7 +1139,7 @@ export class IssuesProcessor {
)}". Removing the close label...`
);

await this._removeLabel(issue, closeLabel, true);
await this._removeLabel(issue, closeLabel, 'last');
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else {
issueLogger.info(
Expand Down

0 comments on commit 70890e5

Please sign in to comment.