Fix failing tests (#266)

This commit is contained in:
Ross Brodbeck
2021-01-15 07:35:41 -05:00
committed by GitHub
parent b5b956deb3
commit 546a4e9fd6
3 changed files with 106 additions and 45 deletions

63
dist/index.js vendored
View File

@@ -49,6 +49,7 @@ class IssueProcessor {
this.operationsLeft = 0;
this.staleIssues = [];
this.closedIssues = [];
this.deletedBranchIssues = [];
this.removedLabelIssues = [];
this.options = options;
this.operationsLeft = options.operationsPerRun;
@@ -119,6 +120,12 @@ class IssueProcessor {
}
// does this issue have a stale label?
let isStale = is_labeled_1.isLabeled(issue, staleLabel);
if (isStale) {
core.info(`This issue has a stale label`);
}
else {
core.info(`This issue hasn't a stale label`);
}
// should this issue be marked stale?
const shouldBeStale = !IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale);
// determine if this issue needs to be marked stale first
@@ -162,6 +169,11 @@ class IssueProcessor {
if (!issueHasComments && !issueHasUpdate) {
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
yield this.closeIssue(issue, closeMessage, closeLabel);
if (this.options.deleteBranch && issue.pull_request) {
core.info(`Deleting branch for #${issue.number} as delete-branch option was specified`);
yield this.deleteBranch(issue);
this.deletedBranchIssues.push(issue);
}
}
else {
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`);
@@ -325,12 +337,56 @@ class IssueProcessor {
}
});
}
getPullRequest(pullNumber) {
return __awaiter(this, void 0, void 0, function* () {
this.operationsLeft -= 1;
try {
const pullRequest = yield this.client.pulls.get({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
pull_number: pullNumber
});
return pullRequest.data;
}
catch (error) {
core.error(`Error getting pull request ${pullNumber}: ${error.message}`);
}
});
}
// Delete the branch on closed pull request
deleteBranch(issue) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Delete branch from closed issue #${issue.number} - ${issue.title}`);
if (this.options.debugOnly) {
return;
}
const pullRequest = yield this.getPullRequest(issue.number);
if (!pullRequest) {
core.info(`Not deleting branch as pull request not found for issue ${issue.number}`);
return;
}
const branch = pullRequest.head.ref;
core.info(`Deleting branch ${branch} from closed issue #${issue.number}`);
this.operationsLeft -= 1;
try {
yield this.client.git.deleteRef({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
ref: `heads/${branch}`
});
}
catch (error) {
core.error(`Error deleting branch ${branch} from issue #${issue.number}: ${error.message}`);
}
});
}
// Remove a label from an issue
removeLabel(issue, label) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Removing label from issue #${issue.number}`);
core.info(`Removing label "${label}" from issue #${issue.number}`);
this.removedLabelIssues.push(issue);
this.operationsLeft -= 1;
// @todo remove the debug only to be able to test the code below
if (this.options.debugOnly) {
return;
}
@@ -339,7 +395,7 @@ class IssueProcessor {
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
issue_number: issue.number,
name: encodeURIComponent(label) // A label can have a "?" in the name
name: label
});
}
catch (error) {
@@ -517,7 +573,8 @@ function getAndValidateArgs() {
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true'
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
deleteBranch: core.getInput('delete-branch') === 'true'
};
for (const numberInput of [
'days-before-stale',