Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bots/bugbuster/src/linear-lint-issue.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isIssueTitleFormatValid } from './issue-title-format-validator'
import { Issue } from './utils/graphql-queries'
import { StateKey } from './utils/linear-utils'

export type IssueLint = {
message: string
}

export const lintIssue = async (issue: Issue, status: string): Promise<IssueLint[]> => {
export const lintIssue = async (issue: Issue, status: StateKey): Promise<IssueLint[]> => {
const lints: string[] = []

if (!_hasLabelOfCategory(issue, 'type')) {
Expand Down
32 changes: 24 additions & 8 deletions bots/bugbuster/src/utils/linear-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const STATE_KEYS = [
'STALE',
] as const
export type StateKey = (typeof STATE_KEYS)[number]
type State = { state: lin.WorkflowState; key: StateKey }

const RESULTS_PER_PAGE = 200

Expand All @@ -26,7 +27,7 @@ export class LinearApi {
private _client: lin.LinearClient,
private _viewer: lin.User,
private _teams: lin.Team[],
private _states: lin.WorkflowState[]
private _states: State[]
) {}

public static async create(): Promise<LinearApi> {
Expand All @@ -39,7 +40,7 @@ export class LinearApi {
const states = await this._listAllStates(client)
const teams = await this._listAllTeams(client)

return new LinearApi(client, me, teams, states)
return new LinearApi(client, me, teams, this._toStateObjects(states))
}

public get client(): lin.LinearClient {
Expand Down Expand Up @@ -84,11 +85,19 @@ export class LinearApi {
return { issues: [] }
}

const stateNamesToOmit = statusesToOmit?.map((key) => {
const matchingStates = this._states.filter((state) => state.key === key)
if (matchingStates[0]) {
return matchingStates[0].state.name
}
return ''
})

const queryInput: GRAPHQL_QUERIES['listIssues'][QUERY_INPUT] = {
filter: {
team: { key: { in: teamKeys } },
...(issueNumber && { number: { eq: issueNumber } }),
...(statusesToOmit && { state: { name: { nin: statusesToOmit } } }),
...(stateNamesToOmit && { state: { name: { nin: stateNamesToOmit } } }),
},
...(nextPage && { after: nextPage }),
first: RESULTS_PER_PAGE,
Expand All @@ -113,11 +122,11 @@ export class LinearApi {
}

public issueStatus(issue: Issue): StateKey {
const state = this._states.find((s) => s.id === issue.state.id)
const state = this._states.find((s) => s.state.id === issue.state.id)
if (!state) {
throw new Error(`State with ID "${issue.state.id}" not found.`)
}
return utils.string.toScreamingSnakeCase(state.name) as StateKey
return state.key
}

public async resolveComments(issue: Issue): Promise<void> {
Expand Down Expand Up @@ -154,9 +163,7 @@ export class LinearApi {

return new Proxy({} as Record<StateKey, lin.WorkflowState>, {
get: (_, stateKey: StateKey) => {
const state = this._states.find(
(s) => utils.string.toScreamingSnakeCase(s.name) === stateKey && s.teamId === teamId
)
const state = this._states.find((s) => s.key === stateKey && s.state.teamId === teamId)

if (!state) {
throw new Error(`State with key "${stateKey}" not found.`)
Expand Down Expand Up @@ -190,6 +197,15 @@ export class LinearApi {
return states
}

private static _toStateObjects(states: lin.WorkflowState[]): State[] {
const stateObjects: State[] = []
for (const state of states) {
const key = utils.string.toScreamingSnakeCase(state.name) as StateKey
stateObjects.push({ key, state })
}
return stateObjects
}

private async _executeGraphqlQuery<K extends keyof GRAPHQL_QUERIES>(
queryName: K,
variables: GRAPHQL_QUERIES[K][QUERY_INPUT]
Expand Down
2 changes: 1 addition & 1 deletion integrations/googlecalendar/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { actions, entities, configuration, configurations, identifier, events, s

export default new sdk.IntegrationDefinition({
name: 'googlecalendar',
version: '2.0.0',
version: '2.0.1',
description: 'Sync with your calendar to manage events, appointments, and schedules directly within the chatbot.',
title: 'Google Calendar',
readme: 'hub.md',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class GoogleClient {
requestBody: {
timeMin,
timeMax,
items: [{ id: this._calendarId }],
},
})

Expand Down
Loading