mirror of
https://github.com/actions/stale.git
synced 2025-12-24 01:18:17 +00:00
Compare commits
1 Commits
v3.0.5
...
fix_closur
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83823d7068 |
@@ -62,36 +62,11 @@ test('empty issue list results in 1 operation', async () => {
|
||||
expect(operationsLeft).toEqual(99);
|
||||
});
|
||||
|
||||
test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to 0', async () => {
|
||||
test('processing an issue with no label will make it stale and close it, if it is old enough', async () => {
|
||||
const TestIssueList: Issue[] = [
|
||||
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||
];
|
||||
|
||||
const opts = {...DefaultProcessorOptions};
|
||||
opts.daysBeforeClose = 0;
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.staleIssues.length).toEqual(1);
|
||||
expect(processor.closedIssues.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => {
|
||||
const TestIssueList: Issue[] = [
|
||||
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||
];
|
||||
|
||||
const opts = {...DefaultProcessorOptions};
|
||||
opts.daysBeforeClose = 15;
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
@@ -103,7 +78,7 @@ test('processing an issue with no label will make it stale and not close it if d
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.staleIssues.length).toEqual(1);
|
||||
expect(processor.closedIssues.length).toEqual(0);
|
||||
expect(processor.closedIssues.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('processing an issue with no label will make it stale but not close it', async () => {
|
||||
@@ -451,7 +426,6 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
||||
|
||||
expect(processor.staleIssues.length).toEqual(0);
|
||||
expect(processor.closedIssues.length).toEqual(0);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
});
|
||||
|
||||
test('exempt pr labels will not be marked stale', async () => {
|
||||
@@ -500,7 +474,6 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.closedIssues.length).toEqual(0);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
});
|
||||
|
||||
test('stale label should be removed if a comment was added to a stale issue', async () => {
|
||||
@@ -520,7 +493,7 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
||||
async (num, dt) => [{user: {type: 'User'}}], // return a fake comment so indicate there was an update
|
||||
async (issue, label) => new Date().toDateString()
|
||||
);
|
||||
|
||||
@@ -532,36 +505,6 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
||||
expect(processor.removedLabelIssues.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
|
||||
github.context.actor = 'abot';
|
||||
const TestIssueList: Issue[] = [
|
||||
generateIssue(
|
||||
1,
|
||||
'An issue that should stay stale',
|
||||
'2020-01-01T17:00:00Z',
|
||||
false,
|
||||
['Stale']
|
||||
)
|
||||
];
|
||||
|
||||
const opts = DefaultProcessorOptions;
|
||||
opts.removeStaleWhenUpdated = true;
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [{user: {login: 'abot', type: 'User'}}], // return a fake comment to indicate there was an update by the bot
|
||||
async (issue, label) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.closedIssues.length).toEqual(1);
|
||||
expect(processor.staleIssues.length).toEqual(0);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
});
|
||||
|
||||
test('stale issues should not be closed until after the closed number of days', async () => {
|
||||
let lastUpdate = new Date();
|
||||
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
||||
@@ -589,7 +532,6 @@ test('stale issues should not be closed until after the closed number of days',
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.closedIssues.length).toEqual(0);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
expect(processor.staleIssues.length).toEqual(1);
|
||||
});
|
||||
|
||||
@@ -621,37 +563,5 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.closedIssues.length).toEqual(1);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
expect(processor.staleIssues.length).toEqual(0);
|
||||
});
|
||||
|
||||
test('stale issues should not be closed until after the closed number of days (long)', async () => {
|
||||
let lastUpdate = new Date();
|
||||
lastUpdate.setDate(lastUpdate.getDate() - 10);
|
||||
const TestIssueList: Issue[] = [
|
||||
generateIssue(
|
||||
1,
|
||||
'An issue that should be marked stale but not closed',
|
||||
lastUpdate.toString(),
|
||||
false
|
||||
)
|
||||
];
|
||||
|
||||
const opts = DefaultProcessorOptions;
|
||||
opts.daysBeforeStale = 5; // stale after 5 days
|
||||
opts.daysBeforeClose = 20; // closes after 25 days
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
await processor.processIssues(1);
|
||||
|
||||
expect(processor.closedIssues.length).toEqual(0);
|
||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||
expect(processor.staleIssues.length).toEqual(1);
|
||||
});
|
||||
|
||||
86
dist/index.js
vendored
86
dist/index.js
vendored
@@ -8471,16 +8471,20 @@ class IssueProcessor {
|
||||
}
|
||||
processIssues(page = 1) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (this.operationsLeft <= 0) {
|
||||
core.warning('Reached max number of operations to process. Exiting.');
|
||||
return 0;
|
||||
}
|
||||
// get the next batch of issues
|
||||
const issues = yield this.getIssues(page);
|
||||
this.operationsLeft -= 1;
|
||||
if (issues.length <= 0) {
|
||||
core.info('No more issues found to process. Exiting.');
|
||||
core.debug('No more issues found to process. Exiting.');
|
||||
return this.operationsLeft;
|
||||
}
|
||||
for (const issue of issues.values()) {
|
||||
const isPr = !!issue.pull_request;
|
||||
core.info(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
||||
core.debug(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
||||
// calculate string based messages for this issue
|
||||
const staleMessage = isPr
|
||||
? this.options.stalePrMessage
|
||||
@@ -8491,41 +8495,37 @@ class IssueProcessor {
|
||||
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
||||
const issueType = isPr ? 'pr' : 'issue';
|
||||
if (!staleMessage) {
|
||||
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
||||
continue;
|
||||
}
|
||||
if (issue.state === 'closed') {
|
||||
core.info(`Skipping ${issueType} because it is closed`);
|
||||
core.debug(`Skipping ${issueType} because it is closed`);
|
||||
continue; // don't process closed issues
|
||||
}
|
||||
if (issue.locked) {
|
||||
core.info(`Skipping ${issueType} because it is locked`);
|
||||
core.debug(`Skipping ${issueType} because it is locked`);
|
||||
continue; // don't process locked issues
|
||||
}
|
||||
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
|
||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||
continue; // don't process exempt issues
|
||||
}
|
||||
// does this issue have a stale label?
|
||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||
// 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
|
||||
if (!isStale && shouldBeStale) {
|
||||
core.info(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
||||
if (!isStale &&
|
||||
!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
|
||||
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
||||
yield this.markStale(issue, staleMessage, staleLabel);
|
||||
this.operationsLeft -= 2;
|
||||
isStale = true; // this issue is now considered stale
|
||||
}
|
||||
// process the issue if it was marked stale
|
||||
// process any issues marked stale (including the issue above, if it was marked)
|
||||
if (isStale) {
|
||||
core.info(`Found a stale ${issueType}`);
|
||||
core.debug(`Found a stale ${issueType}`);
|
||||
yield this.processStaleIssue(issue, issueType, staleLabel);
|
||||
}
|
||||
}
|
||||
if (this.operationsLeft <= 0) {
|
||||
core.warning('Reached max number of operations to process. Exiting.');
|
||||
return 0;
|
||||
}
|
||||
// do the next batch
|
||||
return this.processIssues(page + 1);
|
||||
});
|
||||
@@ -8534,44 +8534,44 @@ class IssueProcessor {
|
||||
processStaleIssue(issue, issueType, staleLabel) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||
const issueHasComments = yield this.hasCommentsSince(issue, markedStaleOn);
|
||||
core.info(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose + ((_a = this.options.daysBeforeStale) !== null && _a !== void 0 ? _a : 0));
|
||||
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||
// should we un-stale this issue?
|
||||
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||
core.info(`Issue #${issue.number} is no longer stale. Removing stale label.`);
|
||||
yield this.removeLabel(issue, staleLabel);
|
||||
}
|
||||
// now start closing logic
|
||||
if (this.options.daysBeforeClose < 0) {
|
||||
return; // nothing to do because we aren't closing stale issues
|
||||
}
|
||||
const markedStaleOn = yield this.getLabelCreationDate(issue, staleLabel);
|
||||
const issueHasComments = yield this.isIssueStillStale(issue, markedStaleOn || issue.updated_at);
|
||||
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose + ((_a = this.options.daysBeforeStale) !== null && _a !== void 0 ? _a : 0));
|
||||
if (markedStaleOn) {
|
||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||
}
|
||||
else {
|
||||
core.debug(`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`);
|
||||
}
|
||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||
core.debug(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||
if (!issueHasComments && !issueHasUpdate) {
|
||||
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||
core.debug(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||
yield this.closeIssue(issue);
|
||||
}
|
||||
else {
|
||||
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`);
|
||||
if (this.options.removeStaleWhenUpdated) {
|
||||
yield this.removeLabel(issue, staleLabel);
|
||||
}
|
||||
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
||||
}
|
||||
});
|
||||
}
|
||||
// checks to see if a given issue is still stale (has had activity on it)
|
||||
hasCommentsSince(issue, sinceDate) {
|
||||
isIssueStillStale(issue, sinceDate) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Checking for comments on issue #${issue.number} since ${sinceDate}`);
|
||||
core.debug(`Checking for comments on issue #${issue.number} since ${sinceDate} to see if it is still stale`);
|
||||
if (!sinceDate) {
|
||||
return true;
|
||||
return true; // if no date was provided then the issue was marked stale a long time ago
|
||||
}
|
||||
// find any comments since the date
|
||||
this.operationsLeft -= 1;
|
||||
// find any comments since the stale label
|
||||
const comments = yield this.listIssueComments(issue.number, sinceDate);
|
||||
const filteredComments = comments.filter(comment => comment.user.type === 'User' &&
|
||||
comment.user.login !== github.context.actor);
|
||||
core.info(`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}`);
|
||||
// if there are any user comments returned
|
||||
return filteredComments.length > 0;
|
||||
// if there are any user comments returned, issue is not stale anymore
|
||||
return comments.filter(comment => comment.user.type === 'User').length > 0;
|
||||
});
|
||||
}
|
||||
// grab comments for an issue since a given date
|
||||
@@ -8604,7 +8604,7 @@ class IssueProcessor {
|
||||
// Mark an issue as stale with a comment and a label
|
||||
markStale(issue, staleMessage, staleLabel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||
this.staleIssues.push(issue);
|
||||
this.operationsLeft -= 2;
|
||||
if (this.options.debugOnly) {
|
||||
@@ -8627,7 +8627,7 @@ class IssueProcessor {
|
||||
// Close an issue based on staleness
|
||||
closeIssue(issue) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
||||
core.debug(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
||||
this.closedIssues.push(issue);
|
||||
this.operationsLeft -= 1;
|
||||
if (this.options.debugOnly) {
|
||||
@@ -8644,7 +8644,7 @@ class IssueProcessor {
|
||||
// Remove a label from an issue
|
||||
removeLabel(issue, label) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Removing label ${label} from issue #${issue.number} - ${issue.title}`);
|
||||
core.debug(`Removing label ${label} from issue #${issue.number} - ${issue.title}`);
|
||||
this.removedLabelIssues.push(issue);
|
||||
this.operationsLeft -= 1;
|
||||
if (this.options.debugOnly) {
|
||||
@@ -8662,7 +8662,7 @@ class IssueProcessor {
|
||||
///see https://developer.github.com/v3/activity/events/
|
||||
getLabelCreationDate(issue, label) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
||||
this.operationsLeft -= 1;
|
||||
const options = this.client.issues.listEvents.endpoint.merge({
|
||||
owner: github.context.repo.owner,
|
||||
|
||||
@@ -16,7 +16,6 @@ export interface Issue {
|
||||
|
||||
export interface User {
|
||||
type: string;
|
||||
login: string;
|
||||
}
|
||||
|
||||
export interface Comment {
|
||||
@@ -97,19 +96,24 @@ export class IssueProcessor {
|
||||
}
|
||||
|
||||
async processIssues(page: number = 1): Promise<number> {
|
||||
if (this.operationsLeft <= 0) {
|
||||
core.warning('Reached max number of operations to process. Exiting.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get the next batch of issues
|
||||
const issues: Issue[] = await this.getIssues(page);
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
if (issues.length <= 0) {
|
||||
core.info('No more issues found to process. Exiting.');
|
||||
core.debug('No more issues found to process. Exiting.');
|
||||
return this.operationsLeft;
|
||||
}
|
||||
|
||||
for (const issue of issues.values()) {
|
||||
const isPr = !!issue.pull_request;
|
||||
|
||||
core.info(
|
||||
core.debug(
|
||||
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
||||
);
|
||||
|
||||
@@ -126,17 +130,17 @@ export class IssueProcessor {
|
||||
const issueType: string = isPr ? 'pr' : 'issue';
|
||||
|
||||
if (!staleMessage) {
|
||||
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (issue.state === 'closed') {
|
||||
core.info(`Skipping ${issueType} because it is closed`);
|
||||
core.debug(`Skipping ${issueType} because it is closed`);
|
||||
continue; // don't process closed issues
|
||||
}
|
||||
|
||||
if (issue.locked) {
|
||||
core.info(`Skipping ${issueType} because it is locked`);
|
||||
core.debug(`Skipping ${issueType} because it is locked`);
|
||||
continue; // don't process locked issues
|
||||
}
|
||||
|
||||
@@ -145,40 +149,36 @@ export class IssueProcessor {
|
||||
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||
)
|
||||
) {
|
||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||
continue; // don't process exempt issues
|
||||
}
|
||||
|
||||
// does this issue have a stale label?
|
||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||
|
||||
// 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
|
||||
if (!isStale && shouldBeStale) {
|
||||
core.info(
|
||||
if (
|
||||
!isStale &&
|
||||
!IssueProcessor.updatedSince(
|
||||
issue.updated_at,
|
||||
this.options.daysBeforeStale
|
||||
)
|
||||
) {
|
||||
core.debug(
|
||||
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
||||
);
|
||||
await this.markStale(issue, staleMessage, staleLabel);
|
||||
this.operationsLeft -= 2;
|
||||
isStale = true; // this issue is now considered stale
|
||||
}
|
||||
|
||||
// process the issue if it was marked stale
|
||||
// process any issues marked stale (including the issue above, if it was marked)
|
||||
if (isStale) {
|
||||
core.info(`Found a stale ${issueType}`);
|
||||
core.debug(`Found a stale ${issueType}`);
|
||||
await this.processStaleIssue(issue, issueType, staleLabel);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.operationsLeft <= 0) {
|
||||
core.warning('Reached max number of operations to process. Exiting.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
// do the next batch
|
||||
return this.processIssues(page + 1);
|
||||
}
|
||||
@@ -189,77 +189,68 @@ export class IssueProcessor {
|
||||
issueType: string,
|
||||
staleLabel: string
|
||||
) {
|
||||
const markedStaleOn: string =
|
||||
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||
|
||||
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||
issue,
|
||||
markedStaleOn
|
||||
);
|
||||
core.info(
|
||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||
);
|
||||
|
||||
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||
issue.updated_at,
|
||||
this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
|
||||
);
|
||||
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||
|
||||
// should we un-stale this issue?
|
||||
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||
core.info(
|
||||
`Issue #${issue.number} is no longer stale. Removing stale label.`
|
||||
);
|
||||
await this.removeLabel(issue, staleLabel);
|
||||
}
|
||||
|
||||
// now start closing logic
|
||||
if (this.options.daysBeforeClose < 0) {
|
||||
return; // nothing to do because we aren't closing stale issues
|
||||
}
|
||||
|
||||
const markedStaleOn: string | undefined = await this.getLabelCreationDate(
|
||||
issue,
|
||||
staleLabel
|
||||
);
|
||||
const issueHasComments: boolean = await this.isIssueStillStale(
|
||||
issue,
|
||||
markedStaleOn || issue.updated_at
|
||||
);
|
||||
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||
issue.updated_at,
|
||||
this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
|
||||
);
|
||||
|
||||
if (markedStaleOn) {
|
||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||
} else {
|
||||
core.debug(
|
||||
`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`
|
||||
);
|
||||
}
|
||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||
core.debug(
|
||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||
);
|
||||
|
||||
if (!issueHasComments && !issueHasUpdate) {
|
||||
core.info(
|
||||
core.debug(
|
||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||
);
|
||||
await this.closeIssue(issue);
|
||||
} else {
|
||||
core.info(
|
||||
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
||||
);
|
||||
if (this.options.removeStaleWhenUpdated) {
|
||||
await this.removeLabel(issue, staleLabel);
|
||||
}
|
||||
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
||||
}
|
||||
}
|
||||
|
||||
// checks to see if a given issue is still stale (has had activity on it)
|
||||
private async hasCommentsSince(
|
||||
private async isIssueStillStale(
|
||||
issue: Issue,
|
||||
sinceDate: string
|
||||
): Promise<boolean> {
|
||||
core.info(
|
||||
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||
core.debug(
|
||||
`Checking for comments on issue #${issue.number} since ${sinceDate} to see if it is still stale`
|
||||
);
|
||||
|
||||
if (!sinceDate) {
|
||||
return true;
|
||||
return true; // if no date was provided then the issue was marked stale a long time ago
|
||||
}
|
||||
|
||||
// find any comments since the date
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
// find any comments since the stale label
|
||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
comment =>
|
||||
comment.user.type === 'User' &&
|
||||
comment.user.login !== github.context.actor
|
||||
);
|
||||
|
||||
core.info(
|
||||
`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}`
|
||||
);
|
||||
|
||||
// if there are any user comments returned
|
||||
return filteredComments.length > 0;
|
||||
// if there are any user comments returned, issue is not stale anymore
|
||||
return comments.filter(comment => comment.user.type === 'User').length > 0;
|
||||
}
|
||||
|
||||
// grab comments for an issue since a given date
|
||||
@@ -298,26 +289,12 @@ export class IssueProcessor {
|
||||
staleMessage: string,
|
||||
staleLabel: string
|
||||
): Promise<void> {
|
||||
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||
|
||||
this.staleIssues.push(issue);
|
||||
|
||||
this.operationsLeft -= 2;
|
||||
|
||||
// We are about to modify the issue by adding a comment and applying a label, so update the modification timestamp
|
||||
// to `days-before-stale` days ago to simulate as if we marked this issue stale on the very first day it actually
|
||||
// became stale. This has the effect of respecting `days-before-close` no matter what value it is set to. The user
|
||||
// can request to close the issue immediately by using `days-before-close` === 0, or they can set it to any number
|
||||
// of days to wait before actually closing the issue.
|
||||
const daysBeforeStaleInMillis =
|
||||
1000 * 60 * 60 * 24 * this.options.daysBeforeStale;
|
||||
const newUpdatedAtDate: Date = new Date();
|
||||
newUpdatedAtDate.setTime(
|
||||
newUpdatedAtDate.getTime() - daysBeforeStaleInMillis
|
||||
);
|
||||
|
||||
issue.updated_at = newUpdatedAtDate.toString();
|
||||
|
||||
if (this.options.debugOnly) {
|
||||
return;
|
||||
}
|
||||
@@ -339,7 +316,7 @@ export class IssueProcessor {
|
||||
|
||||
// Close an issue based on staleness
|
||||
private async closeIssue(issue: Issue): Promise<void> {
|
||||
core.info(
|
||||
core.debug(
|
||||
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||
);
|
||||
|
||||
@@ -361,7 +338,7 @@ export class IssueProcessor {
|
||||
|
||||
// Remove a label from an issue
|
||||
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||
core.info(
|
||||
core.debug(
|
||||
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||
);
|
||||
|
||||
@@ -387,7 +364,7 @@ export class IssueProcessor {
|
||||
issue: Issue,
|
||||
label: string
|
||||
): Promise<string | undefined> {
|
||||
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
||||
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
@@ -424,7 +401,7 @@ export class IssueProcessor {
|
||||
const millisSinceLastUpdated =
|
||||
new Date().getTime() - new Date(timestamp).getTime();
|
||||
|
||||
return millisSinceLastUpdated <= daysInMillis;
|
||||
return millisSinceLastUpdated < daysInMillis;
|
||||
}
|
||||
|
||||
private static parseCommaSeparatedString(s: string): string[] {
|
||||
|
||||
Reference in New Issue
Block a user