Skip to content

Commit 8c87420

Browse files
committed
UBERF-10481: Fix external changes are missed
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
1 parent 2d2ae87 commit 8c87420

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

services/github/pod-github/src/sync/issueBase.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
errorToObj,
7070
getCreateStatus,
7171
getType,
72+
guessStatus,
7273
isGHWriteAllowed
7374
} from './utils'
7475

@@ -1070,6 +1071,58 @@ export abstract class IssueSyncManagerBase {
10701071
return issueUpdate
10711072
}
10721073

1074+
async performDocumentExternalSync (
1075+
ctx: MeasureContext,
1076+
info: DocSyncInfo,
1077+
previousExternal: IssueExternalData,
1078+
issueExternal: IssueExternalData,
1079+
derivedClient: TxOperations
1080+
): Promise<void> {
1081+
// TODO: Since Github integeration need to be re-written to use cards, so this is quick fix to not loose data in case of external sync while service was offline.
1082+
1083+
const update: IssueUpdate = {}
1084+
const du: DocumentUpdate<DocSyncInfo> = {}
1085+
const account = (await this.provider.getAccount(issueExternal.author))?._id ?? core.account.System
1086+
1087+
const container = await this.provider.getContainer(info.space)
1088+
if (container == null) {
1089+
return
1090+
}
1091+
const type = await this.provider.getTaskTypeOf(container.project.type, tracker.class.Issue)
1092+
const statuses = await this.provider.getStatuses(type?._id)
1093+
1094+
if (previousExternal.state !== issueExternal.state) {
1095+
update.status = (
1096+
await guessStatus({ state: issueExternal.state, stateReason: issueExternal.stateReason }, statuses)
1097+
)._id
1098+
}
1099+
if (previousExternal.title !== issueExternal.title) {
1100+
update.title = issueExternal.title
1101+
}
1102+
if (previousExternal.body !== issueExternal.body) {
1103+
update.description = await this.provider.getMarkupSafe(
1104+
container.container,
1105+
issueExternal.body,
1106+
this.stripGuestLink
1107+
)
1108+
du.markdown = await this.provider.getMarkdown(update.description)
1109+
}
1110+
if (!deepEqual(previousExternal.assignees, issueExternal.assignees)) {
1111+
const assignees = await this.getAssignees(issueExternal)
1112+
update.assignee = assignees?.[0]?.person ?? null
1113+
}
1114+
if (Object.keys(update).length > 0) {
1115+
await this.handleUpdate(
1116+
issueExternal,
1117+
derivedClient,
1118+
update,
1119+
account,
1120+
container.project,
1121+
false
1122+
)
1123+
}
1124+
}
1125+
10731126
async syncIssues (
10741127
_class: Ref<Class<Doc>>,
10751128
repo: GithubIntegrationRepository,
@@ -1120,7 +1173,17 @@ export abstract class IssueSyncManagerBase {
11201173
}
11211174
const externalEqual = deepEqual(existing.external, issue)
11221175
if (!externalEqual || existing.externalVersion !== githubExternalSyncVersion) {
1123-
this.ctx.info('Update sync doc', { url: issue.url, workspace: this.provider.getWorkspaceId().name })
1176+
this.ctx.info('Update sync doc(extarnal changes)', {
1177+
url: issue.url,
1178+
workspace: this.provider.getWorkspaceId().name
1179+
})
1180+
1181+
if (existing.needSync === githubSyncVersion) {
1182+
// Sync external if and only if no changes from platform.
1183+
// We need to apply changes from Github, while service was offline.
1184+
await this.performDocumentExternalSync(this.ctx, existing, existing.external, issue, derivedClient)
1185+
}
1186+
11241187
await ops.diffUpdate(
11251188
existing,
11261189
{

0 commit comments

Comments
 (0)