Compare commits

..

4 Commits

Author SHA1 Message Date
Ross Brodbeck
6e01d91097 Fix operation counting 2020-05-26 09:13:49 -04:00
Ross Brodbeck
55ac880ddb Add ( 2020-05-26 09:06:01 -04:00
Ross Brodbeck
bb7acbc692 Fix un-stale logic in processor 2020-05-26 08:43:40 -04:00
Ross Brodbeck
6d710eccec Update dits 2020-05-26 05:27:59 -04:00
3 changed files with 1070 additions and 1266 deletions

View File

@@ -62,36 +62,11 @@ test('empty issue list results in 1 operation', async () => {
expect(operationsLeft).toEqual(99); 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[] = [ const TestIssueList: Issue[] = [
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z') 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( const processor = new IssueProcessor(
DefaultProcessorOptions, DefaultProcessorOptions,
async p => (p == 1 ? TestIssueList : []), 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); await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(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 () => { test('processing an issue with no label will make it stale but not close it', async () => {

2188
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -203,7 +203,7 @@ export class IssueProcessor {
const issueHasUpdate: boolean = IssueProcessor.updatedSince( const issueHasUpdate: boolean = IssueProcessor.updatedSince(
issue.updated_at, issue.updated_at,
this.options.daysBeforeClose this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
); );
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`); core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
@@ -268,38 +268,28 @@ export class IssueProcessor {
sinceDate: string sinceDate: string
): Promise<Comment[]> { ): Promise<Comment[]> {
// find any comments since date on the given issue // find any comments since date on the given issue
try { const comments = await this.client.issues.listComments({
const comments = await this.client.issues.listComments({ owner: github.context.repo.owner,
owner: github.context.repo.owner, repo: github.context.repo.repo,
repo: github.context.repo.repo, issue_number: issueNumber,
issue_number: issueNumber, since: sinceDate
since: sinceDate });
});
return comments.data; return comments.data;
} catch (error) {
core.error(`List issue comments error: ${error.message}`);
return Promise.resolve([]);
}
} }
// grab issues from github in baches of 100 // grab issues from github in baches of 100
private async getIssues(page: number): Promise<Issue[]> { private async getIssues(page: number): Promise<Issue[]> {
try { const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo( owner: github.context.repo.owner,
{ repo: github.context.repo.repo,
owner: github.context.repo.owner, state: 'open',
repo: github.context.repo.repo, labels: this.options.onlyLabels,
state: 'open', per_page: 100,
labels: this.options.onlyLabels, page
per_page: 100, });
page
} return issueResult.data;
);
return issueResult.data;
} catch (error) {
core.error(`Get issues for repo error: ${error.message}`);
return Promise.resolve([]);
}
} }
// Mark an issue as stale with a comment and a label // Mark an issue as stale with a comment and a label
@@ -314,36 +304,23 @@ export class IssueProcessor {
this.operationsLeft -= 2; this.operationsLeft -= 2;
// 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();
if (this.options.debugOnly) { if (this.options.debugOnly) {
return; return;
} }
try { await this.client.issues.createComment({
await this.client.issues.createComment({ owner: github.context.repo.owner,
owner: github.context.repo.owner, repo: github.context.repo.repo,
repo: github.context.repo.repo, issue_number: issue.number,
issue_number: issue.number, body: staleMessage
body: staleMessage });
});
} catch (error) {
core.error(`Error creating a comment: ${error.message}`);
}
try { await this.client.issues.addLabels({
await this.client.issues.addLabels({ owner: github.context.repo.owner,
owner: github.context.repo.owner, repo: github.context.repo.repo,
repo: github.context.repo.repo, issue_number: issue.number,
issue_number: issue.number, labels: [staleLabel]
labels: [staleLabel] });
});
} catch (error) {
core.error(`Error adding a label: ${error.message}`);
}
} }
// Close an issue based on staleness // Close an issue based on staleness
@@ -360,16 +337,12 @@ export class IssueProcessor {
return; return;
} }
try { await this.client.issues.update({
await this.client.issues.update({ owner: github.context.repo.owner,
owner: github.context.repo.owner, repo: github.context.repo.repo,
repo: github.context.repo.repo, issue_number: issue.number,
issue_number: issue.number, state: 'closed'
state: 'closed' });
});
} catch (error) {
core.error(`Error updating an issue: ${error.message}`);
}
} }
// Remove a label from an issue // Remove a label from an issue
@@ -386,16 +359,12 @@ export class IssueProcessor {
return; return;
} }
try { await this.client.issues.removeLabel({
await this.client.issues.removeLabel({ owner: github.context.repo.owner,
owner: github.context.repo.owner, repo: github.context.repo.repo,
repo: github.context.repo.repo, issue_number: issue.number,
issue_number: issue.number, name: encodeURIComponent(label) // A label can have a "?" in the name
name: encodeURIComponent(label) // A label can have a "?" in the name });
});
} catch (error) {
core.error(`Error removing a label: ${error.message}`);
}
} }
// returns the creation date of a given label on an issue (or nothing if no label existed) // returns the creation date of a given label on an issue (or nothing if no label existed)
@@ -441,7 +410,7 @@ export class IssueProcessor {
const millisSinceLastUpdated = const millisSinceLastUpdated =
new Date().getTime() - new Date(timestamp).getTime(); new Date().getTime() - new Date(timestamp).getTime();
return millisSinceLastUpdated <= daysInMillis; return millisSinceLastUpdated < daysInMillis;
} }
private static parseCommaSeparatedString(s: string): string[] { private static parseCommaSeparatedString(s: string): string[] {