Compare commits

...

2 Commits

Author SHA1 Message Date
Ross Brodbeck
96b682d29f Fix an issue where the bot doesn't ignore its own comments (#73) 2020-05-18 20:33:59 -04:00
Ross Brodbeck
5ce6b77f2c Fix issue close/stale dates (#72)
Added tests to confirm behavior.
2020-05-18 20:08:31 -04:00
3 changed files with 1099 additions and 1098 deletions

View File

@@ -493,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: {type: 'User'}}], // return a fake comment so indicate there was an update
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
async (issue, label) => new Date().toDateString()
);
@@ -504,3 +504,94 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.staleIssues.length).toEqual(0);
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);
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 = 1; // closes after 6 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.staleIssues.length).toEqual(1);
});
test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => {
let lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 7);
const TestIssueList: Issue[] = [
generateIssue(
1,
'An issue that should be stale and closed',
lastUpdate.toString(),
false,
['Stale']
)
];
const opts = DefaultProcessorOptions;
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 1; // closes after 6 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(1);
expect(processor.staleIssues.length).toEqual(0);
});

2075
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@ export interface Issue {
export interface User {
type: string;
login: string;
}
export interface Comment {
@@ -67,7 +68,10 @@ export class IssueProcessor {
issueNumber: number,
sinceDate: string
) => Promise<Comment[]>,
getLabelCreationDate?: (issue: Issue, label: string) => Promise<string | undefined>
getLabelCreationDate?: (
issue: Issue,
label: string
) => Promise<string | undefined>
) {
this.options = options;
this.operationsLeft = options.operationsPerRun;
@@ -200,17 +204,20 @@ export class IssueProcessor {
);
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
issue.updated_at,
this.options.daysBeforeClose
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`);
} 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}`);
core.debug(
`Issue #${issue.number} has been commented on: ${issueHasComments}`
);
if (!issueHasComments && !issueHasUpdate) {
core.debug(
@@ -243,8 +250,14 @@ export class IssueProcessor {
// find any comments since the stale label
const comments = await this.listIssueComments(issue.number, sinceDate);
// if there are any user comments returned, issue is not stale anymore
return comments.filter(comment => comment.user.type === 'User').length > 0;
// if there are any user comments returned, and they were not by this bot, the issue is not stale anymore
return (
comments.filter(
comment =>
comment.user.type === 'User' &&
comment.user.login !== github.context.actor
).length > 0
);
}
// grab comments for an issue since a given date