mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-26 14:22:23 +02:00
fix(github): guard REST octokit in comment sync to prevent createComment crash (#10692)
Same class of bug fixed in #10442 for graphql calls. The user-scoped Octokit returned by getOctokit() may lack the .rest plugin, causing "okit.rest.issues.createComment is not a function". Add ensureRESTOctokit() guard to both createGithubComment and updateComment paths. Fixes #10691 Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user