Skip to content

Commit ceb0d57

Browse files
committed
UBERF-10494: Allow to reintegrate same project again
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
1 parent 8c87420 commit ceb0d57

File tree

6 files changed

+45
-28
lines changed

6 files changed

+45
-28
lines changed

services/github/github-resources/src/components/ConnectProject.svelte

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
showPopup
1414
} from '@hcengineering/ui'
1515
import DropdownLabelsPopup from '@hcengineering/ui/src/components/DropdownLabelsPopup.svelte'
16-
import { GithubIntegration, GithubIntegrationRepository, githubPullRequestStates } from '@hcengineering/github'
16+
import {
17+
GithubIntegration,
18+
GithubIntegrationRepository,
19+
githubPullRequestStates,
20+
type GithubProject
21+
} from '@hcengineering/github'
1722
import github from '../plugin'
1823
1924
export let integration: WithLookup<GithubIntegration>
2025
export let repository: GithubIntegrationRepository
2126
export let projects: Project[] = []
27+
export let orphanProjects: GithubProject[] = []
2228
2329
/**
2430
* @public
@@ -112,16 +118,23 @@
112118
113119
const githubProject = client.getHierarchy().as(projectInst, github.mixin.GithubProject)
114120
115-
void getClient().update(githubProject, {
121+
if (githubProject.integration !== integration._id) {
122+
await getClient().update(githubProject, {
123+
integration: integration._id
124+
})
125+
}
126+
await getClient().update(githubProject, {
116127
$push: { repositories: repository._id }
117128
})
118-
void getClient().update(repository, { githubProject: githubProject._id, enabled: true })
129+
await getClient().update(repository, { githubProject: githubProject._id, enabled: true })
119130
}
120131
121-
$: allowedProjects = projects.filter(
122-
(it) =>
123-
(client.getHierarchy().asIf(it, github.mixin.GithubProject)?.integration ?? integration._id) === integration._id
124-
)
132+
$: allowedProjects = projects
133+
.filter(
134+
(it) =>
135+
(client.getHierarchy().asIf(it, github.mixin.GithubProject)?.integration ?? integration._id) === integration._id
136+
)
137+
.concat(orphanProjects)
125138
async function selectProject (event: MouseEvent): Promise<void> {
126139
showPopup(
127140
DropdownLabelsPopup,

services/github/github-resources/src/components/GithubIntegerations.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import GithubRepositories from './GithubRepositories.svelte'
33
4-
import { WithLookup } from '@hcengineering/core'
4+
import { toIdMap, WithLookup } from '@hcengineering/core'
5+
import { GithubIntegration } from '@hcengineering/github'
56
import { getClient } from '@hcengineering/presentation'
67
import { Project } from '@hcengineering/tracker'
78
import { Scroller } from '@hcengineering/ui'
8-
import { GithubIntegration } from '@hcengineering/github'
99
import github from '../plugin'
1010
1111
export let integrations: WithLookup<GithubIntegration>[] = []
@@ -14,6 +14,10 @@
1414
const client = getClient()
1515
1616
$: githubProjects = client.getHierarchy().asIfArray(projects, github.mixin.GithubProject)
17+
18+
$: integerationsMap = toIdMap(integrations)
19+
20+
$: orphanProjects = githubProjects.filter((it) => !integerationsMap.has(it.integration))
1721
</script>
1822

1923
{#if integrations.length > 0}
@@ -23,7 +27,7 @@
2327
{@const giprj = githubProjects.filter((it) => it.integration === gi._id)}
2428
<div class="flex flex-col mb-4">
2529
<!-- svelte-ignore a11y-missing-attribute -->
26-
<GithubRepositories integration={gi} giProjects={giprj} {projects} />
30+
<GithubRepositories integration={gi} giProjects={giprj} {projects} {orphanProjects} />
2731
</div>
2832
{/each}
2933
</div>

services/github/github-resources/src/components/GithubRepositories.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import ConnectProject from './ConnectProject.svelte'
2727
import { githubLanguageColors } from './languageColors'
2828
import { sendGHServiceRequest } from './utils'
29-
import { BackgroundColor } from '@hcengineering/text'
3029
3130
export let integration: WithLookup<GithubIntegration>
3231
export let projects: Project[] = []
3332
export let giProjects: GithubProject[] = []
33+
export let orphanProjects: GithubProject[] = []
3434
3535
const client = getClient()
3636
@@ -235,7 +235,7 @@
235235
/>
236236
</div>
237237
{:else}
238-
<ConnectProject {integration} {repository} {projects} />
238+
<ConnectProject {integration} {repository} {projects} {orphanProjects} />
239239
{/if}
240240
</div>
241241
</div>

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export class CommentSyncManager implements DocSyncManager {
531531
}
532532
const syncInfo = await this.client.findAll<DocSyncInfo>(github.class.DocSyncInfo, {
533533
space: repo.githubProject,
534-
repository: repo._id,
534+
// repository: repo._id, // If we skip repository, we will find orphaned comments, so we could connect them on.
535535
objectClass: chunter.class.ChatMessage,
536536
url: { $in: comments.map((it) => (it.url ?? '').toLowerCase()) }
537537
})
@@ -553,14 +553,19 @@ export class CommentSyncManager implements DocSyncManager {
553553
lastModified
554554
})
555555
} else {
556-
if (!deepEqual(existing.external, comment) || existing.externalVersion !== githubExternalSyncVersion) {
556+
if (
557+
!deepEqual(existing.external, comment) ||
558+
existing.externalVersion !== githubExternalSyncVersion ||
559+
existing.repository !== repo._id
560+
) {
557561
await derivedClient.diffUpdate(
558562
existing,
559563
{
560564
needSync: '',
561565
external: comment,
562566
externalVersion: githubExternalSyncVersion,
563-
lastModified
567+
lastModified,
568+
repository: repo._id
564569
},
565570
lastModified
566571
)

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,7 @@ export abstract class IssueSyncManagerBase {
11121112
update.assignee = assignees?.[0]?.person ?? null
11131113
}
11141114
if (Object.keys(update).length > 0) {
1115-
await this.handleUpdate(
1116-
issueExternal,
1117-
derivedClient,
1118-
update,
1119-
account,
1120-
container.project,
1121-
false
1122-
)
1115+
await this.handleUpdate(issueExternal, derivedClient, update, account, container.project, false)
11231116
}
11241117
}
11251118

@@ -1137,7 +1130,7 @@ export abstract class IssueSyncManagerBase {
11371130
syncDocs ??
11381131
(await this.client.findAll<DocSyncInfo>(github.class.DocSyncInfo, {
11391132
space: repo.githubProject,
1140-
repository: repo._id,
1133+
// repository: repo._id, // If we skip repository, we will find orphaned issues, so we could connect them on.
11411134
objectClass: _class,
11421135
url: { $in: issues.map((it) => (it.url ?? '').toLowerCase()) }
11431136
}))
@@ -1171,15 +1164,15 @@ export abstract class IssueSyncManagerBase {
11711164
if (syncDocs !== undefined) {
11721165
syncDocs = syncDocs.filter((it) => it._id !== existing._id)
11731166
}
1174-
const externalEqual = deepEqual(existing.external, issue)
1167+
const externalEqual = deepEqual(existing.external, issue) && existing.repository === repo._id
11751168
if (!externalEqual || existing.externalVersion !== githubExternalSyncVersion) {
11761169
this.ctx.info('Update sync doc(extarnal changes)', {
11771170
url: issue.url,
11781171
workspace: this.provider.getWorkspaceId().name
11791172
})
11801173

1181-
if (existing.needSync === githubSyncVersion) {
1182-
// Sync external if and only if no changes from platform.
1174+
if (existing.needSync === githubSyncVersion || existing.repository !== repo._id) {
1175+
// Sync external if and only if no changes from platform or we do resync from github.
11831176
// We need to apply changes from Github, while service was offline.
11841177
await this.performDocumentExternalSync(this.ctx, existing, existing.external, issue, derivedClient)
11851178
}
@@ -1192,6 +1185,7 @@ export abstract class IssueSyncManagerBase {
11921185
externalVersion: githubExternalSyncVersion,
11931186
derivedVersion: '', // Clear derived state to recalculate it.
11941187
externalVersionSince: '',
1188+
repository: repo._id,
11951189
lastModified: new Date(issue.updatedAt).getTime()
11961190
},
11971191
Date.now()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,13 @@ export async function syncDerivedDocuments<T extends { url: string }> (
370370
})
371371
} else {
372372
processed.add(existing._id)
373-
if (!deepEqual(existing.external, r)) {
373+
if (!deepEqual(existing.external, r) || existing.repository !== repo._id) {
374374
// Only update if had changes.
375375
await derivedClient.update(existing, {
376376
external: r,
377377
needSync: '', // We need to check if we had any changes.
378378
derivedVersion: '',
379+
repository: repo._id,
379380
externalVersion: githubExternalSyncVersion,
380381
lastModified: new Date(r.updatedAt ?? r.createdAt).getTime(),
381382
...extra

0 commit comments

Comments
 (0)