mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-02 14:29:03 +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 {
|
||||
|
||||
Reference in New Issue
Block a user