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
12 changes: 9 additions & 3 deletions services/github/pod-github/src/sync/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
githubExternalSyncVersion,
githubSyncVersion
} from '../types'
import { collectUpdate, deleteObjects, ensureGraphQLOctokit, errorToObj, getSince, isGHWriteAllowed } from './utils'
import { collectUpdate, deleteObjects, ensureGraphQLOctokit, ensureRESTOctokit, errorToObj, getSince, isGHWriteAllowed } from './utils'

import { Analytics } from '@hcengineering/analytics'
import { IssueComment, IssueCommentCreatedEvent, IssueCommentEvent } from '@octokit/webhooks-types'
Expand Down Expand Up @@ -353,7 +353,10 @@ export class CommentSyncManager implements DocSyncManager {

if (Object.keys(platformUpdate).length > 0) {
// Check and update body with external
const okit = (await this.provider.getOctokit(ctx, existing.modifiedBy)) ?? container.container.octokit
const okit = ensureRESTOctokit(
(await this.provider.getOctokit(ctx, existing.modifiedBy)) ?? container.container.octokit,
container
)
const mdown = await this.provider.getMarkdown(existingComment.message)
if (mdown.trim().length > 0) {
await okit.rest.issues.updateComment({
Expand Down Expand Up @@ -426,7 +429,10 @@ export class CommentSyncManager implements DocSyncManager {
return {}
}
const chatMessage = existing as ChatMessage
const okit = (await this.provider.getOctokit(ctx, chatMessage.modifiedBy)) ?? container.container.octokit
const okit = ensureRESTOctokit(
(await this.provider.getOctokit(ctx, chatMessage.modifiedBy)) ?? container.container.octokit,
container
)

// No external version yet, create it.
try {
Expand Down
11 changes: 11 additions & 0 deletions services/github/pod-github/src/sync/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ export function ensureGraphQLOctokit (okit: Octokit | undefined, container: Cont
return container.container.octokit
}

/**
* Ensures an Octokit instance has the REST API available.
* If the provided okit doesn't have rest.issues, falls back to container.octokit which is guaranteed to have it.
*/
export function ensureRESTOctokit (okit: Octokit | undefined, container: ContainerFocus): Octokit {
if (okit !== undefined && typeof (okit as any).rest?.issues?.createComment === 'function') {
return okit
}
return container.container.octokit
}

/**
* @public
*/
Expand Down
Loading