Skip to content

Commit 7f3fd45

Browse files
authored
UBERF-10471(staging): Fix github reopen due to slow startup and allow to reintegrate (#8841)
Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 0be1f75 commit 7f3fd45

File tree

18 files changed

+133
-2495
lines changed

18 files changed

+133
-2495
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/github/src/index.ts

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@
44
import { ActivityMessage, ActivityMessageViewlet } from '@hcengineering/activity'
55
import { Attachment } from '@hcengineering/attachment'
66
import { Person } from '@hcengineering/contact'
7-
import {
8-
Account,
9-
AnyAttribute,
10-
AttachedDoc,
11-
Class,
12-
Data,
13-
Doc,
14-
Hyperlink,
15-
Markup,
16-
Mixin,
17-
Ref,
18-
Timestamp
19-
} from '@hcengineering/core'
7+
import { Account, AttachedDoc, Class, Data, Doc, Hyperlink, Markup, Mixin, Ref, Timestamp } from '@hcengineering/core'
208
import { Asset, IntlString, Metadata, Plugin, plugin } from '@hcengineering/platform'
219
import { Preference } from '@hcengineering/preference'
2210
import task, { ProjectTypeDescriptor, TaskStatusFactory, TaskTypeDescriptor } from '@hcengineering/task'
2311
import { ToDo } from '@hcengineering/time'
24-
import { Component, Issue, Milestone, Project } from '@hcengineering/tracker'
12+
import { Component, Issue, Project } from '@hcengineering/tracker'
2513
import { AnyComponent } from '@hcengineering/ui'
2614
import { PaletteColorIndexes } from '@hcengineering/ui/src/colors'
2715

@@ -456,59 +444,16 @@ export interface GithubUserInfo extends Doc {
456444
avatarUrl?: string
457445
}
458446

459-
/**
460-
* @public
461-
*/
462-
export interface GithubFieldMapping {
463-
// Platform field
464-
_id: Ref<AnyAttribute>
465-
name: string
466-
_class: Ref<Class<Doc>>
467-
468-
// Github information
469-
githubId: string // It could be fieldName or fieldId
470-
}
471-
472-
/**
473-
* @public
474-
*/
475-
export interface GithubProjectSyncData {
476-
// Project NodeId
477-
projectNodeId?: string
478-
projectNumber?: number
479-
480-
githubProjectName?: string
481-
482-
// Mapping of all fields in this project.
483-
mappings: GithubFieldMapping[]
484-
485-
// Update mapping
486-
githubUpdatedAt?: string
487-
}
488-
489447
/**
490448
* @public
491449
*
492450
* Mixin to ordinary project, to allow github repository mapping into it.
493451
*/
494-
export interface GithubProject extends Project, GithubProjectSyncData {
452+
export interface GithubProject extends Project {
495453
integration: Ref<GithubIntegration>
496454

497455
// A list of mapped repositories we synchronized into this project.
498456
repositories: Ref<GithubIntegrationRepository>[]
499-
500-
// Mixin to store all github custom attributes in
501-
mixinClass: Ref<Class<GithubIssue>>
502-
}
503-
504-
/**
505-
* @public
506-
*
507-
* Mixin for milestone to represent a github project for it.
508-
*/
509-
export interface GithubMilestone extends Milestone, GithubProjectSyncData {
510-
// A link to github project.
511-
url: Hyperlink
512457
}
513458

514459
export interface GithubPullRequestReviewThread extends Doc {
@@ -566,7 +511,6 @@ export default plugin(githubId, {
566511
mixin: {
567512
GithubIssue: '' as Ref<Mixin<GithubIssue>>,
568513
GithubProject: '' as Ref<Mixin<GithubProject>>,
569-
GithubMilestone: '' as Ref<Mixin<GithubMilestone>>,
570514
GithubComponent: '' as Ref<Mixin<GithubComponent>>,
571515
GithubUser: '' as Ref<Mixin<GithubUser>>,
572516
GithubTodo: '' as Ref<Mixin<GithubTodo>>

services/github/model-github/src/index.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
import { type Person } from '@hcengineering/contact'
4444
import contact, { TContact } from '@hcengineering/model-contact'
4545
import presentation from '@hcengineering/model-presentation'
46-
import tracker, { TComponent, TIssue, TMilestone, TProject, issuesOptions } from '@hcengineering/model-tracker'
46+
import tracker, { TComponent, TIssue, TProject, issuesOptions } from '@hcengineering/model-tracker'
4747
import view, { classPresenter } from '@hcengineering/model-view'
4848
import workbench from '@hcengineering/model-workbench'
4949
import { getEmbeddedLabel } from '@hcengineering/platform'
@@ -54,11 +54,9 @@ import {
5454
type DocSyncInfo,
5555
type GithubAuthentication,
5656
type GithubComponent,
57-
type GithubFieldMapping,
5857
type GithubIntegration,
5958
type GithubIntegrationRepository,
6059
type GithubIssue,
61-
type GithubMilestone,
6260
type GithubPatch,
6361
type GithubProject,
6462
type GithubPullRequest,
@@ -374,16 +372,6 @@ export class TGithubProject extends TProject implements GithubProject {
374372
@ReadOnly()
375373
@Hidden()
376374
projectNumber!: number
377-
378-
@Prop(TypeRef(core.class.Class), getEmbeddedLabel('Attribute Class'))
379-
@ReadOnly()
380-
@Hidden()
381-
mixinClass!: Ref<Class<GithubIssue>>
382-
383-
@Prop(ArrOf(TypeRecord()), getEmbeddedLabel('Field mappings'))
384-
@Hidden()
385-
// Mapping of all fields in this project.
386-
mappings!: GithubFieldMapping[]
387375
}
388376

389377
@Mixin(github.mixin.GithubIssue, tracker.class.Issue)
@@ -433,29 +421,6 @@ export class TGithubComponent extends TComponent implements GithubComponent {
433421
represent!: boolean
434422
}
435423

436-
@Mixin(github.mixin.GithubMilestone, tracker.class.Milestone)
437-
@UX(github.string.GithubMilestone)
438-
export class TGithubMilestone extends TMilestone implements GithubMilestone {
439-
@Prop(TypeHyperlink(), getEmbeddedLabel('Github Project URL'))
440-
@Index(IndexKind.FullText)
441-
@ReadOnly()
442-
url!: Hyperlink
443-
444-
@Prop(TypeString(), getEmbeddedLabel('NodeID'))
445-
@Hidden()
446-
@ReadOnly()
447-
projectNodeId!: string
448-
449-
@Prop(TypeNumber(), getEmbeddedLabel('Number'))
450-
@Hidden()
451-
@ReadOnly()
452-
projectNumber!: number
453-
454-
@Prop(ArrOf(TypeRecord()), getEmbeddedLabel('Field mappings'))
455-
// Mapping of all fields in this project.
456-
mappings!: GithubFieldMapping[]
457-
}
458-
459424
@Model(github.class.GithubPullRequest, tracker.class.Issue)
460425
@UX(github.string.PullRequest, github.icon.PullRequest, undefined, undefined, undefined, github.string.PullRequests)
461426
export class TGithubPullRequest extends TIssue implements GithubPullRequest {
@@ -603,7 +568,6 @@ export function createModel (builder: Builder): void {
603568
TGithubIntegrationRepository,
604569
TGithubPatch,
605570
TGithubUserInfo,
606-
TGithubMilestone,
607571
TGithubComponent,
608572
TGithubUser,
609573
TGithubTodo

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { collectUpdate, deleteObjects, errorToObj, getSince, isGHWriteAllowed }
2929
import { Analytics } from '@hcengineering/analytics'
3030
import { IssueComment, IssueCommentCreatedEvent, IssueCommentEvent } from '@octokit/webhooks-types'
3131
import config from '../config'
32-
import { syncConfig } from './syncConfig'
3332

3433
interface MessageData {
3534
message: string
@@ -89,14 +88,6 @@ export class CommentSyncManager implements DocSyncManager {
8988
if (container === undefined) {
9089
return false
9190
}
92-
if (
93-
container?.container === undefined ||
94-
((container.project.projectNodeId === undefined ||
95-
!container.container.projectStructure.has(container.project._id)) &&
96-
syncConfig.MainProject)
97-
) {
98-
return false
99-
}
10091

10192
const commentExternal = info.external as CommentExternalData | undefined
10293

@@ -531,7 +522,7 @@ export class CommentSyncManager implements DocSyncManager {
531522
}
532523
const syncInfo = await this.client.findAll<DocSyncInfo>(github.class.DocSyncInfo, {
533524
space: repo.githubProject,
534-
repository: repo._id,
525+
// repository: repo._id, // If we skip repository, we will find orphaned comments, so we could connect them on.
535526
objectClass: chunter.class.ChatMessage,
536527
url: { $in: comments.map((it) => (it.url ?? '').toLowerCase()) }
537528
})
@@ -553,14 +544,19 @@ export class CommentSyncManager implements DocSyncManager {
553544
lastModified
554545
})
555546
} else {
556-
if (!deepEqual(existing.external, comment) || existing.externalVersion !== githubExternalSyncVersion) {
547+
if (
548+
!deepEqual(existing.external, comment) ||
549+
existing.externalVersion !== githubExternalSyncVersion ||
550+
existing.repository !== repo._id
551+
) {
557552
await derivedClient.diffUpdate(
558553
existing,
559554
{
560555
needSync: '',
561556
external: comment,
562557
externalVersion: githubExternalSyncVersion,
563-
lastModified
558+
lastModified,
559+
repository: repo._id
564560
},
565561
lastModified
566562
)

0 commit comments

Comments
 (0)