mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 21:27:46 +02:00
qfix: Rework span creation (#9613)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -1007,7 +1007,7 @@ export class PlatformWorker {
|
||||
}
|
||||
try {
|
||||
const branding = Object.values(this.brandingMap).find((b) => b.key === workspaceInfo?.branding) ?? null
|
||||
const workerCtx = this.ctx.newChild('worker', { workspace: workspaceInfo.uuid }, {})
|
||||
const workerCtx = this.ctx.newChild('worker', { workspace: workspaceInfo.uuid }, { span: false })
|
||||
|
||||
connecting.set(workspaceInfo.uuid, {
|
||||
time: Date.now(),
|
||||
@@ -1157,8 +1157,10 @@ export class PlatformWorker {
|
||||
const webhook = this.ctx.newChild(
|
||||
'webhook',
|
||||
{},
|
||||
{},
|
||||
new SplitLogger('webhook', { root: join(process.cwd(), 'logs'), pretty: true, enableConsole: false })
|
||||
{
|
||||
logger: new SplitLogger('webhook', { root: join(process.cwd(), 'logs'), pretty: true, enableConsole: false }),
|
||||
span: false
|
||||
}
|
||||
)
|
||||
webhook.info('Register webhook')
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ export abstract class IssueSyncManagerBase {
|
||||
): Promise<DocumentUpdate<DocSyncInfo>> {
|
||||
let needUpdate = false
|
||||
if (!this.client.getHierarchy().hasMixin(existing, github.mixin.GithubIssue)) {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'create mixin issue: GithubIssue',
|
||||
{},
|
||||
async () => {
|
||||
@@ -288,7 +288,8 @@ export abstract class IssueSyncManagerBase {
|
||||
)
|
||||
await this.notifyConnected(container, info, existing, issueExternal)
|
||||
},
|
||||
{ identifier: existing.identifier, url: issueExternal.url }
|
||||
{ identifier: existing.identifier, url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
// Re iterate to have existing value with mixin inside.
|
||||
needUpdate = true
|
||||
|
||||
@@ -339,24 +339,31 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
return { needSync: githubSyncVersion }
|
||||
}
|
||||
|
||||
const description = await this.ctx.withLog('query collaborative description', {}, async () => {
|
||||
const collabId = makeDocCollabId(existing, 'description')
|
||||
return await this.collaborator.getMarkup(collabId, (existing as Issue).description)
|
||||
})
|
||||
const description = await this.ctx.with(
|
||||
'query collaborative description',
|
||||
{},
|
||||
async () => {
|
||||
const collabId = makeDocCollabId(existing, 'description')
|
||||
return await this.collaborator.getMarkup(collabId, (existing as Issue).description)
|
||||
},
|
||||
{},
|
||||
{ log: true }
|
||||
)
|
||||
|
||||
this.ctx.info('create github issue', {
|
||||
title: (existing as Issue).title,
|
||||
number: (existing as Issue).number,
|
||||
workspace: this.provider.getWorkspaceId()
|
||||
})
|
||||
const createdIssueData = await this.ctx.withLog(
|
||||
const createdIssueData = await this.ctx.with(
|
||||
'create github issue',
|
||||
{},
|
||||
async () => {
|
||||
this.createPromise = this.createGithubIssue(container, { ...(existing as Issue), description }, repository)
|
||||
return await this.createPromise
|
||||
},
|
||||
{ id: (existing as Issue).identifier, workspace: this.provider.getWorkspaceId() }
|
||||
{ id: (existing as Issue).identifier, workspace: this.provider.getWorkspaceId() },
|
||||
{ log: true }
|
||||
)
|
||||
if (createdIssueData === undefined) {
|
||||
this.ctx.error('Error create issue', { url: info.url })
|
||||
@@ -476,7 +483,7 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
// No repository, it probable deleted
|
||||
return { needSync: githubSyncVersion }
|
||||
}
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'create platform issue',
|
||||
{},
|
||||
async () => {
|
||||
@@ -499,7 +506,8 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
!markdownCompatible
|
||||
)
|
||||
},
|
||||
{ url: issueExternal.url }
|
||||
{ url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
// We need reiterate to update all sync data.
|
||||
return {
|
||||
@@ -518,17 +526,18 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const description = await this.ctx.withLog(
|
||||
const description = await this.ctx.with(
|
||||
'query collaborative description',
|
||||
{},
|
||||
async () => {
|
||||
const collabId = makeDocCollabId(existing, 'description')
|
||||
return await this.collaborator.getMarkup(collabId, (existing as Issue).description)
|
||||
},
|
||||
{ url: issueExternal.url }
|
||||
{ url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
|
||||
const updateResult = await this.ctx.withLog(
|
||||
const updateResult = await this.ctx.with(
|
||||
'diff update',
|
||||
{},
|
||||
async () =>
|
||||
@@ -541,7 +550,8 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
account,
|
||||
accountGH
|
||||
),
|
||||
{ url: issueExternal.url }
|
||||
{ url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
return {
|
||||
...updateResult,
|
||||
@@ -620,7 +630,7 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
|
||||
if (hasFieldStateChanges || body !== undefined) {
|
||||
if (body !== undefined && !isLocked) {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'==> updateIssue',
|
||||
{},
|
||||
async () => {
|
||||
@@ -656,11 +666,12 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
}
|
||||
}
|
||||
},
|
||||
{ url: issueExternal.url, id: existing._id }
|
||||
{ url: issueExternal.url, id: existing._id },
|
||||
{ log: true }
|
||||
)
|
||||
issueData.description = await this.provider.getMarkupSafe(container.container, body, this.stripGuestLink)
|
||||
} else if (hasFieldStateChanges) {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'==> updateIssue',
|
||||
{},
|
||||
async () => {
|
||||
@@ -693,7 +704,8 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
|
||||
}
|
||||
}
|
||||
},
|
||||
{ url: issueExternal.url }
|
||||
{ url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -415,7 +415,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
|
||||
if (existing === undefined) {
|
||||
try {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'retrieve pull request patch',
|
||||
{},
|
||||
() =>
|
||||
@@ -431,7 +431,8 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
lastModified,
|
||||
accountGH
|
||||
),
|
||||
{ url: pullRequestExternal.url }
|
||||
{ url: pullRequestExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
const { markdownCompatible, markdown } = await this.provider.checkMarkdownConversion(
|
||||
container.container,
|
||||
@@ -441,7 +442,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
let op = this.client.apply()
|
||||
let createdPullRequest: GithubPullRequest | undefined
|
||||
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'create pull request in platform',
|
||||
{},
|
||||
async () => {
|
||||
@@ -461,7 +462,8 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
!markdownCompatible
|
||||
)
|
||||
},
|
||||
{ url: pullRequestExternal.url }
|
||||
{ url: pullRequestExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
|
||||
await op.commit()
|
||||
@@ -499,7 +501,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
} else {
|
||||
try {
|
||||
if (info.updatePatch === true) {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'update pull request patch',
|
||||
{},
|
||||
() =>
|
||||
@@ -515,21 +517,23 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
lastModified,
|
||||
accountGH
|
||||
),
|
||||
{ url: pullRequestExternal.url }
|
||||
{ url: pullRequestExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
}
|
||||
|
||||
const description = await this.ctx.withLog(
|
||||
const description = await this.ctx.with(
|
||||
'query collaborative pull request description',
|
||||
{},
|
||||
async () => {
|
||||
const collabId = makeDocCollabId(existing, 'description')
|
||||
return await this.collaborator.getMarkup(collabId, (existing as GithubPullRequest).description)
|
||||
},
|
||||
{ url: pullRequestExternal.url }
|
||||
{ url: pullRequestExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
|
||||
const update = await this.ctx.withLog(
|
||||
const update = await this.ctx.with(
|
||||
'perform pull request diff update',
|
||||
{},
|
||||
() =>
|
||||
@@ -542,7 +546,8 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
account,
|
||||
accountGH
|
||||
),
|
||||
{ url: pullRequestExternal.url }
|
||||
{ url: pullRequestExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
return {
|
||||
...update,
|
||||
@@ -950,7 +955,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
|
||||
if (hasFieldsUpdate || body !== undefined) {
|
||||
if (body !== undefined && !isLocked) {
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'==> updatePullRequest',
|
||||
{},
|
||||
async () => {
|
||||
@@ -980,19 +985,23 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
)
|
||||
}
|
||||
},
|
||||
{ url: issueExternal.url }
|
||||
{ url: issueExternal.url },
|
||||
{ log: true }
|
||||
)
|
||||
issueData.description = await this.provider.getMarkupSafe(container.container, body, this.stripGuestLink)
|
||||
} else if (hasFieldsUpdate) {
|
||||
await this.ctx.withLog('==> updatePullRequest:', {}, async () => {
|
||||
this.ctx.info('update-fields', {
|
||||
url: issueExternal.url,
|
||||
...issueUpdate,
|
||||
workspace: this.provider.getWorkspaceId()
|
||||
})
|
||||
if (isGHWriteAllowed()) {
|
||||
await okit?.graphql(
|
||||
`
|
||||
await this.ctx.with(
|
||||
'==> updatePullRequest:',
|
||||
{},
|
||||
async () => {
|
||||
this.ctx.info('update-fields', {
|
||||
url: issueExternal.url,
|
||||
...issueUpdate,
|
||||
workspace: this.provider.getWorkspaceId()
|
||||
})
|
||||
if (isGHWriteAllowed()) {
|
||||
await okit?.graphql(
|
||||
`
|
||||
mutation updatePullRequest($issue: ID!) {
|
||||
updatePullRequest(input: {
|
||||
pullRequestId: $issue,
|
||||
@@ -1005,10 +1014,13 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{ issue: issueExternal.id }
|
||||
)
|
||||
}
|
||||
})
|
||||
{ issue: issueExternal.id }
|
||||
)
|
||||
}
|
||||
},
|
||||
{ issue: issueExternal.id },
|
||||
{ log: true }
|
||||
)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1266,7 +1278,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
}
|
||||
const idsp = idsPart.map((it) => `"${it}"`).join(', ')
|
||||
try {
|
||||
const response: any = await this.ctx.withLog(
|
||||
const response: any = await this.ctx.with(
|
||||
'fetch pull request updates',
|
||||
{},
|
||||
async () =>
|
||||
@@ -1283,7 +1295,8 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
|
||||
prj: prj.name,
|
||||
repo: repo.name,
|
||||
ids: idsp
|
||||
}
|
||||
},
|
||||
{ log: true }
|
||||
)
|
||||
const issues: PullRequestExternalData[] = response.nodes
|
||||
|
||||
|
||||
@@ -398,22 +398,35 @@ export class GithubWorker implements IntegrationManager {
|
||||
this._client = new TxOperations(this.client, core.account.System)
|
||||
this.liveQuery = new LiveQuery(client)
|
||||
|
||||
this.repositoryManager = new RepositorySyncMapper(this.ctx.newChild('repository', {}), this._client, this.app)
|
||||
this.repositoryManager = new RepositorySyncMapper(
|
||||
this.ctx.newChild('repository', {}, { span: false }),
|
||||
this._client,
|
||||
this.app
|
||||
)
|
||||
|
||||
this.collaborator = createCollaboratorClient(this.workspace.uuid)
|
||||
|
||||
this.personMapper = new UsersSyncManager(this.ctx.newChild('users', {}), this._client, this.liveQuery)
|
||||
this.personMapper = new UsersSyncManager(
|
||||
this.ctx.newChild('users', {}, { span: false }),
|
||||
this._client,
|
||||
this.liveQuery
|
||||
)
|
||||
|
||||
this.mappers = [
|
||||
{ _class: [github.mixin.GithubProject], mapper: this.repositoryManager },
|
||||
{
|
||||
_class: [tracker.class.Issue],
|
||||
mapper: new IssueSyncManager(this.ctx.newChild('issue', {}), this._client, this.liveQuery, this.collaborator)
|
||||
mapper: new IssueSyncManager(
|
||||
this.ctx.newChild('issue', {}, { span: false }),
|
||||
this._client,
|
||||
this.liveQuery,
|
||||
this.collaborator
|
||||
)
|
||||
},
|
||||
{
|
||||
_class: [github.class.GithubPullRequest],
|
||||
mapper: new PullRequestSyncManager(
|
||||
this.ctx.newChild('pullRequest', {}),
|
||||
this.ctx.newChild('pullRequest', {}, { span: false }),
|
||||
this._client,
|
||||
this.liveQuery,
|
||||
this.collaborator
|
||||
@@ -421,7 +434,7 @@ export class GithubWorker implements IntegrationManager {
|
||||
},
|
||||
{
|
||||
_class: [chunter.class.ChatMessage],
|
||||
mapper: new CommentSyncManager(this.ctx.newChild('comment', {}), this._client, this.liveQuery)
|
||||
mapper: new CommentSyncManager(this.ctx.newChild('comment', {}, { span: false }), this._client, this.liveQuery)
|
||||
},
|
||||
// {
|
||||
// _class: [contact.class.PersonAccount],
|
||||
@@ -429,15 +442,23 @@ export class GithubWorker implements IntegrationManager {
|
||||
// },
|
||||
{
|
||||
_class: [github.class.GithubReview],
|
||||
mapper: new ReviewSyncManager(this.ctx.newChild('review', {}), this._client, this.liveQuery)
|
||||
mapper: new ReviewSyncManager(this.ctx.newChild('review', {}, { span: false }), this._client, this.liveQuery)
|
||||
},
|
||||
{
|
||||
_class: [github.class.GithubReviewThread],
|
||||
mapper: new ReviewThreadSyncManager(this.ctx.newChild('review-thread', {}), this._client, this.liveQuery)
|
||||
mapper: new ReviewThreadSyncManager(
|
||||
this.ctx.newChild('review-thread', {}, { span: false }),
|
||||
this._client,
|
||||
this.liveQuery
|
||||
)
|
||||
},
|
||||
{
|
||||
_class: [github.class.GithubReviewComment],
|
||||
mapper: new ReviewCommentSyncManager(this.ctx.newChild('review-comment', {}), this._client, this.liveQuery)
|
||||
mapper: new ReviewCommentSyncManager(
|
||||
this.ctx.newChild('review-comment', {}, { span: false }),
|
||||
this._client,
|
||||
this.liveQuery
|
||||
)
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1479,7 +1500,7 @@ export class GithubWorker implements IntegrationManager {
|
||||
return
|
||||
}
|
||||
|
||||
const docUpdate = await this.ctx.withLog(
|
||||
const docUpdate = await this.ctx.with(
|
||||
'sync doc',
|
||||
{},
|
||||
(ctx) => mapper.sync(existing, info, parent, derivedClient),
|
||||
@@ -1488,7 +1509,8 @@ export class GithubWorker implements IntegrationManager {
|
||||
workspace: this.workspace.uuid,
|
||||
existing: existing !== undefined,
|
||||
objectClass: info.objectClass
|
||||
}
|
||||
},
|
||||
{ log: true }
|
||||
)
|
||||
if (docUpdate !== undefined) {
|
||||
await derivedClient.update(info, docUpdate)
|
||||
@@ -1571,7 +1593,7 @@ export class GithubWorker implements IntegrationManager {
|
||||
if (this.closing) {
|
||||
break
|
||||
}
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'external sync',
|
||||
{},
|
||||
async () => {
|
||||
@@ -1666,17 +1688,19 @@ export class GithubWorker implements IntegrationManager {
|
||||
if (this.closing) {
|
||||
break
|
||||
}
|
||||
await this.ctx.withLog(
|
||||
await this.ctx.with(
|
||||
'external sync',
|
||||
{ _class: _class.join(', ') },
|
||||
async () => {
|
||||
await mapper.externalFullSync(integration, derivedClient, _projects, _repositories)
|
||||
},
|
||||
{ installation: integration.installationName, workspace: this.workspace.uuid }
|
||||
{ installation: integration.installationName, workspace: this.workspace.uuid },
|
||||
{ log: true }
|
||||
)
|
||||
}
|
||||
},
|
||||
{ installation: integration.installationName, workspace: this.workspace.uuid }
|
||||
{ installation: integration.installationName, workspace: this.workspace.uuid },
|
||||
{ log: true }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user