mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-30 11:49:42 +02:00
feat: Pass tracing info with websocket (#9627)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -9,7 +9,8 @@ import core, {
|
||||
DocumentUpdate,
|
||||
MeasureContext,
|
||||
Ref,
|
||||
TxOperations
|
||||
TxOperations,
|
||||
withContext
|
||||
} from '@hcengineering/core'
|
||||
import github, {
|
||||
DocSyncInfo,
|
||||
@@ -44,7 +45,6 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
externalDerivedSync = false
|
||||
|
||||
constructor (
|
||||
readonly ctx: MeasureContext,
|
||||
readonly client: TxOperations,
|
||||
readonly lq: LiveQuery
|
||||
) {}
|
||||
@@ -54,7 +54,14 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
|
||||
eventSync = new Map<string, Promise<void>>()
|
||||
async handleEvent<T>(integration: IntegrationContainer, derivedClient: TxOperations, evt: T): Promise<void> {
|
||||
|
||||
@withContext('review-comments-handleEvent')
|
||||
async handleEvent<T>(
|
||||
ctx: MeasureContext,
|
||||
integration: IntegrationContainer,
|
||||
derivedClient: TxOperations,
|
||||
evt: T
|
||||
): Promise<void> {
|
||||
await this.createCommentPromise
|
||||
const event = evt as PullRequestReviewCommentEvent
|
||||
|
||||
@@ -65,27 +72,28 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
return
|
||||
}
|
||||
}
|
||||
this.ctx.info('reviewComments:handleEvent', {
|
||||
ctx.info('reviewComments:handleEvent', {
|
||||
action: event.action,
|
||||
login: event.sender.login,
|
||||
workspace: this.provider.getWorkspaceId()
|
||||
})
|
||||
const { project, repository } = await this.provider.getProjectAndRepository(event.repository.node_id)
|
||||
if (project === undefined || repository === undefined) {
|
||||
this.ctx.info('No project for repository', {
|
||||
ctx.info('No project for repository', {
|
||||
name: event.repository.name,
|
||||
workspace: this.provider.getWorkspaceId()
|
||||
})
|
||||
return
|
||||
}
|
||||
await this.eventSync.get(event.comment.html_url)
|
||||
const promise = this.processEvent(event, derivedClient, repository, integration)
|
||||
const promise = this.processEvent(ctx, event, derivedClient, repository, integration)
|
||||
this.eventSync.set(event.comment.html_url, promise)
|
||||
await promise
|
||||
this.eventSync.delete(event.comment.html_url)
|
||||
}
|
||||
|
||||
async handleDelete (
|
||||
ctx: MeasureContext,
|
||||
existing: Doc | undefined,
|
||||
info: DocSyncInfo,
|
||||
derivedClient: TxOperations,
|
||||
@@ -108,7 +116,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
|
||||
if (commentExternal !== undefined) {
|
||||
try {
|
||||
await this.deleteGithubDocument(container, account, commentExternal.node_id, derivedClient, parent)
|
||||
await this.deleteGithubDocument(ctx, container, account, commentExternal.node_id, derivedClient, parent)
|
||||
} catch (err: any) {
|
||||
let cnt = false
|
||||
if (Array.isArray(err.errors)) {
|
||||
@@ -121,7 +129,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
}
|
||||
if (!cnt) {
|
||||
this.ctx.error('Error', { err })
|
||||
ctx.error('Error', { err })
|
||||
Analytics.handleError(err)
|
||||
await derivedClient.update(info, { error: errorToObj(err) })
|
||||
}
|
||||
@@ -129,19 +137,20 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
|
||||
if (existing !== undefined && deleteExisting) {
|
||||
await deleteObjects(this.ctx, this.client, [existing], account)
|
||||
await deleteObjects(ctx, this.client, [existing], account)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async deleteGithubDocument (
|
||||
ctx: MeasureContext,
|
||||
container: ContainerFocus,
|
||||
account: PersonId,
|
||||
id: string,
|
||||
derivedClient: TxOperations,
|
||||
parent?: DocSyncInfo
|
||||
): Promise<void> {
|
||||
const okit = (await this.provider.getOctokit(account)) ?? container.container.octokit
|
||||
const okit = (await this.provider.getOctokit(ctx, account)) ?? container.container.octokit
|
||||
const q = `mutation deleteReviewComment($reviewID: ID!) {
|
||||
deletePullRequestReviewComment(input: {
|
||||
id: $reviewID
|
||||
@@ -163,6 +172,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
|
||||
private async processEvent (
|
||||
ctx: MeasureContext,
|
||||
event: PullRequestReviewCommentEvent,
|
||||
derivedClient: TxOperations,
|
||||
repo: GithubIntegrationRepository,
|
||||
@@ -188,7 +198,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
)
|
||||
externalData = response.node
|
||||
} catch (err: any) {
|
||||
this.ctx.error('Error', { err })
|
||||
ctx.error('Error', { err })
|
||||
Analytics.handleError(err)
|
||||
return
|
||||
}
|
||||
@@ -292,7 +302,9 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
}
|
||||
|
||||
@withContext('review-comments-sync')
|
||||
async sync (
|
||||
ctx: MeasureContext,
|
||||
existing: Doc | undefined,
|
||||
info: DocSyncInfo,
|
||||
parent: DocSyncInfo | undefined,
|
||||
@@ -314,7 +326,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
|
||||
// If no external document, we need to create it.
|
||||
this.createCommentPromise = this.createGithubReviewComment(container, existing, info, parent, derivedClient)
|
||||
this.createCommentPromise = this.createGithubReviewComment(ctx, container, existing, info, parent, derivedClient)
|
||||
return await this.createCommentPromise
|
||||
}
|
||||
const reviewComment = info.external as ReviewCommentExternalData
|
||||
@@ -355,17 +367,28 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
await this.createReviewComment(info, messageData, parent, reviewComment, account)
|
||||
return { needSync: githubSyncVersion, current: messageData }
|
||||
} catch (err: any) {
|
||||
this.ctx.error('Error', { err })
|
||||
ctx.error('Error', { err })
|
||||
Analytics.handleError(err)
|
||||
return { needSync: githubSyncVersion, error: errorToObj(err) }
|
||||
}
|
||||
} else {
|
||||
await this.handleDiffUpdate(existing, info, messageData, container, parent, reviewComment, account, derivedClient)
|
||||
await this.handleDiffUpdate(
|
||||
ctx,
|
||||
existing,
|
||||
info,
|
||||
messageData,
|
||||
container,
|
||||
parent,
|
||||
reviewComment,
|
||||
account,
|
||||
derivedClient
|
||||
)
|
||||
}
|
||||
return { current: messageData, needSync: githubSyncVersion }
|
||||
}
|
||||
|
||||
private async handleDiffUpdate (
|
||||
ctx: MeasureContext,
|
||||
existing: Doc,
|
||||
info: DocSyncInfo,
|
||||
reviewCommentData: ReviewCommentData,
|
||||
@@ -406,7 +429,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
if (Object.keys(platformUpdate).length > 0) {
|
||||
if (platformUpdate.body !== undefined) {
|
||||
const body = await this.provider.getMarkupSafe(container.container, platformUpdate.body)
|
||||
const okit = (await this.provider.getOctokit(account)) ?? container.container.octokit
|
||||
const okit = (await this.provider.getOctokit(ctx, account)) ?? container.container.octokit
|
||||
const q = `mutation updateReviewComment($commentID: ID!, $body: String!) {
|
||||
updatePullRequestReviewComment(input: {
|
||||
threadId: $threadID
|
||||
@@ -460,6 +483,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
|
||||
async createGithubReviewComment (
|
||||
ctx: MeasureContext,
|
||||
container: ContainerFocus,
|
||||
existing: Doc | undefined,
|
||||
info: DocSyncInfo,
|
||||
@@ -477,7 +501,7 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
return {}
|
||||
}
|
||||
const existingReview = existing as GithubReviewComment
|
||||
const okit = (await this.provider.getOctokit(existingReview.modifiedBy)) ?? container.container.octokit
|
||||
const okit = (await this.provider.getOctokit(ctx, existingReview.modifiedBy)) ?? container.container.octokit
|
||||
|
||||
// No external version yet, create it.
|
||||
try {
|
||||
@@ -540,13 +564,15 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
}
|
||||
return {}
|
||||
} catch (err: any) {
|
||||
this.ctx.error('Error', { err })
|
||||
ctx.error('Error', { err })
|
||||
Analytics.handleError(err)
|
||||
return { needSync: githubSyncVersion, error: errorToObj(err) }
|
||||
}
|
||||
}
|
||||
|
||||
@withContext('review-comments-externalSync')
|
||||
async externalSync (
|
||||
ctx: MeasureContext,
|
||||
integration: IntegrationContainer,
|
||||
derivedClient: TxOperations,
|
||||
kind: ExternalSyncField,
|
||||
@@ -563,9 +589,11 @@ export class ReviewCommentSyncManager implements DocSyncManager {
|
||||
this.provider.sync()
|
||||
}
|
||||
|
||||
repositoryDisabled (integration: IntegrationContainer, repo: GithubIntegrationRepository): void {}
|
||||
repositoryDisabled (ctx: MeasureContext, integration: IntegrationContainer, repo: GithubIntegrationRepository): void {}
|
||||
|
||||
@withContext('review-comments-externalFullSync')
|
||||
async externalFullSync (
|
||||
ctx: MeasureContext,
|
||||
integration: IntegrationContainer,
|
||||
derivedClient: TxOperations,
|
||||
projects: GithubProject[],
|
||||
|
||||
Reference in New Issue
Block a user