Files
botpress--botpress/bots/bugbuster/src/services/issue-state-checker.ts
T
2026-07-13 13:34:48 +08:00

45 lines
1.3 KiB
TypeScript

import * as sdk from '@botpress/sdk'
import * as types from '../types'
import * as lin from '../utils/linear-utils'
import * as sts from './state-service'
export class IssueStateChecker {
public constructor(
private _linear: lin.LinearApi,
private _stateService: sts.StateService,
private _logger: sdk.BotLogger,
private _botId: string
) {}
public async processIssues(props: { stateAttributes: types.StateAttributes; teams: string[] }) {
const { stateAttributes, teams } = props
const stateIdsToInclude = await this._stateService.mapToStateIds([stateAttributes.commonStateName])
let hasNextPage = false
let endCursor: string | undefined = undefined
do {
const { issues, pagination } = await this._linear.listIssues(
{
teamKeys: teams,
stateIdsToInclude,
updatedBefore: stateAttributes.maxTimeSinceLastUpdate,
},
endCursor
)
for (const issue of issues) {
await this._linear.createComment({
issueId: issue.id,
botId: this._botId,
body: stateAttributes.warningComment,
})
this._logger.warn(stateAttributes.buildWarningReason(issue.identifier))
}
hasNextPage = pagination?.hasNextPage ?? false
endCursor = pagination?.endCursor
} while (hasNextPage)
}
}