diff --git a/services/github/pod-github/src/sync/comments.ts b/services/github/pod-github/src/sync/comments.ts index b64b290a75..341e1bf19e 100644 --- a/services/github/pod-github/src/sync/comments.ts +++ b/services/github/pod-github/src/sync/comments.ts @@ -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' @@ -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({ @@ -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 { diff --git a/services/github/pod-github/src/sync/utils.ts b/services/github/pod-github/src/sync/utils.ts index 5feafce402..5667a6c9d9 100644 --- a/services/github/pod-github/src/sync/utils.ts +++ b/services/github/pod-github/src/sync/utils.ts @@ -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 */