Filter comments by content instead of actor (#519)

* Filter comments by content instead of actor

* Remove dead actor code

* WIP fix tests

* Fix test
This commit is contained in:
Luke Tomlinson
2021-07-12 10:37:47 -04:00
committed by GitHub
parent 678bfc7a59
commit d901397e11
11 changed files with 122 additions and 160 deletions

View File

@@ -105,7 +105,6 @@ export class IssuesProcessor {
async processIssues(page: Readonly<number> = 1): Promise<number> {
// get the next batch of issues
const issues: Issue[] = await this.getIssues(page);
const actor: string = await this.getActor();
if (issues.length <= 0) {
this._logger.info(
@@ -145,7 +144,6 @@ export class IssuesProcessor {
await issueLogger.grouping(`$$type #${issue.number}`, async () => {
await this.processIssue(
issue,
actor,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale
);
@@ -184,7 +182,6 @@ export class IssuesProcessor {
async processIssue(
issue: Issue,
actor: string,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[]
): Promise<void> {
@@ -455,7 +452,7 @@ export class IssuesProcessor {
await this._processStaleIssue(
issue,
staleLabel,
actor,
staleMessage,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale,
closeMessage,
@@ -488,20 +485,6 @@ export class IssuesProcessor {
}
}
// get the actor from the GitHub token or context
async getActor(): Promise<string> {
let actor;
try {
this.operations.consumeOperation();
actor = await this.client.users.getAuthenticated();
} catch (error) {
return context.actor;
}
return actor.data.login;
}
// grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> {
// generate type for response
@@ -568,7 +551,7 @@ export class IssuesProcessor {
private async _processStaleIssue(
issue: Issue,
staleLabel: string,
actor: string,
staleMessage: string,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[],
closeMessage?: string,
@@ -584,7 +567,7 @@ export class IssuesProcessor {
const issueHasComments: boolean = await this._hasCommentsSince(
issue,
markedStaleOn,
actor
staleMessage
);
issueLogger.info(
`$$type has been commented on: ${LoggerService.cyan(issueHasComments)}`
@@ -672,7 +655,7 @@ export class IssuesProcessor {
private async _hasCommentsSince(
issue: Issue,
sinceDate: string,
actor: string
staleMessage: string
): Promise<boolean> {
const issueLogger: IssueLogger = new IssueLogger(issue);
@@ -688,11 +671,13 @@ export class IssuesProcessor {
const comments = await this.listIssueComments(issue.number, sinceDate);
const filteredComments = comments.filter(
comment => comment.user.type === 'User' && comment.user.login !== actor
comment =>
comment.user.type === 'User' &&
comment.body.toLowerCase() !== staleMessage.toLowerCase()
);
issueLogger.info(
`Comments not made by actor or another bot: ${LoggerService.cyan(
`Comments that are not the stale comment or another bot: ${LoggerService.cyan(
filteredComments.length
)}`
);

View File

@@ -2,4 +2,5 @@ import {IUser} from './user';
export interface IComment {
user: IUser;
body: string;
}