mirror of
https://github.com/actions/stale.git
synced 2025-12-10 12:07:09 +00:00
Add support for adding & removing labels when no longer stale (#468)
* Add support for adding & removing labels when no longer stale * Add remove/addLabelsWhenUpdatedFromStale to relevant spec files. Modify arguments to remove ambiguity in 'labels' var & parameter * Change parameters for clarity, let autoformat do its thing * PR feedback: More useful logging when removing labels * Wrap client calls in try catches * Use Unstale in variable names * Don't run add label logic under debug * Add test for labels added to unstale issues * PR Feedback: logging * Update README * Rename vars to labels-to-add/remove-when-unstale * Apply doc suggestions from code review Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com> * PR Feedback Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
This commit is contained in:
58
dist/index.js
vendored
58
dist/index.js
vendored
@@ -253,6 +253,7 @@ class IssuesProcessor {
|
||||
this.closedIssues = [];
|
||||
this.deletedBranchIssues = [];
|
||||
this.removedLabelIssues = [];
|
||||
this.addedLabelIssues = [];
|
||||
this.options = options;
|
||||
this.client = github_1.getOctokit(this.options.repoToken);
|
||||
this.operations = new stale_operations_1.StaleOperations(this.options);
|
||||
@@ -299,6 +300,8 @@ class IssuesProcessor {
|
||||
else {
|
||||
this._logger.info(`${logger_service_1.LoggerService.yellow('Processing the batch of issues')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.yellow('containing')} ${logger_service_1.LoggerService.cyan(issues.length)} ${logger_service_1.LoggerService.yellow(`issue${issues.length > 1 ? 's' : ''}...`)}`);
|
||||
}
|
||||
const labelsToAddWhenUnstale = words_to_list_1.wordsToList(this.options.labelsToAddWhenUnstale);
|
||||
const labelsToRemoveWhenUnstale = words_to_list_1.wordsToList(this.options.labelsToRemoveWhenUnstale);
|
||||
for (const issue of issues.values()) {
|
||||
// Stop the processing if no more operations remains
|
||||
if (!this.operations.hasRemainingOperations()) {
|
||||
@@ -306,7 +309,7 @@ class IssuesProcessor {
|
||||
}
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
yield issueLogger.grouping(`$$type #${issue.number}`, () => __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.processIssue(issue, actor);
|
||||
yield this.processIssue(issue, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale);
|
||||
}));
|
||||
}
|
||||
if (!this.operations.hasRemainingOperations()) {
|
||||
@@ -320,7 +323,7 @@ class IssuesProcessor {
|
||||
return this.processIssues(page + 1);
|
||||
});
|
||||
}
|
||||
processIssue(issue, actor) {
|
||||
processIssue(issue, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementProcessedItemsCount(issue);
|
||||
@@ -469,7 +472,7 @@ class IssuesProcessor {
|
||||
// Process the issue if it was marked stale
|
||||
if (issue.isStale) {
|
||||
issueLogger.info(`This $$type is already stale`);
|
||||
yield this._processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel);
|
||||
yield this._processStaleIssue(issue, staleLabel, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel);
|
||||
}
|
||||
IssuesProcessor._endIssueProcessing(issue);
|
||||
});
|
||||
@@ -561,7 +564,7 @@ class IssuesProcessor {
|
||||
});
|
||||
}
|
||||
// handle all of the stale issue logic when we find a stale issue
|
||||
_processStaleIssue(issue, staleLabel, actor, closeMessage, closeLabel) {
|
||||
_processStaleIssue(issue, staleLabel, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||
@@ -586,6 +589,9 @@ class IssuesProcessor {
|
||||
if (shouldRemoveStaleWhenUpdated && issueHasComments) {
|
||||
issueLogger.info(`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated`);
|
||||
yield this._removeStaleLabel(issue, staleLabel);
|
||||
// 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
|
||||
}
|
||||
@@ -854,6 +860,44 @@ class IssuesProcessor {
|
||||
}
|
||||
return this.options.removeStaleWhenUpdated;
|
||||
}
|
||||
_removeLabelsWhenUnstale(issue, removeLabels) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!removeLabels.length) {
|
||||
return;
|
||||
}
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Removing all the labels specified via the ${this._logger.createOptionLink(option_1.Option.LabelsToRemoveWhenUnstale)} option.`);
|
||||
for (const label of removeLabels.values()) {
|
||||
yield this._removeLabel(issue, label);
|
||||
}
|
||||
});
|
||||
}
|
||||
_addLabelsWhenUnstale(issue, labelsToAdd) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!labelsToAdd.length) {
|
||||
return;
|
||||
}
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Adding all the labels specified via the ${this._logger.createOptionLink(option_1.Option.LabelsToAddWhenUnstale)} option.`);
|
||||
this.addedLabelIssues.push(issue);
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsLabel(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.addLabels({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
labels: labelsToAdd
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this._logger.error(`Error when adding labels after updated from stale: ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
_removeStaleLabel(issue, staleLabel) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -1692,6 +1736,8 @@ var Option;
|
||||
Option["ExemptAllIssueAssignees"] = "exempt-all-issue-assignees";
|
||||
Option["ExemptAllPrAssignees"] = "exempt-all-pr-assignees";
|
||||
Option["EnableStatistics"] = "enable-statistics";
|
||||
Option["LabelsToRemoveWhenUnstale"] = "labels-to-remove-when-unstale";
|
||||
Option["LabelsToAddWhenUnstale"] = "labels-to-add-when-unstale";
|
||||
})(Option = exports.Option || (exports.Option = {}));
|
||||
|
||||
|
||||
@@ -1975,7 +2021,9 @@ function _getAndValidateArgs() {
|
||||
exemptAllAssignees: core.getInput('exempt-all-assignees') === 'true',
|
||||
exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'),
|
||||
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
|
||||
enableStatistics: core.getInput('enable-statistics') === 'true'
|
||||
enableStatistics: core.getInput('enable-statistics') === 'true',
|
||||
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
|
||||
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale')
|
||||
};
|
||||
for (const numberInput of [
|
||||
'days-before-stale',
|
||||
|
||||
Reference in New Issue
Block a user