Skip to content

UBERF-10471(staging): Fix github reopen due to slow startup and allow to reintegrate #8841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
showPopup
} from '@hcengineering/ui'
import DropdownLabelsPopup from '@hcengineering/ui/src/components/DropdownLabelsPopup.svelte'
import { GithubIntegration, GithubIntegrationRepository, githubPullRequestStates } from '@hcengineering/github'
import {
GithubIntegration,
GithubIntegrationRepository,
githubPullRequestStates,
type GithubProject
} from '@hcengineering/github'
import github from '../plugin'

export let integration: WithLookup<GithubIntegration>
export let repository: GithubIntegrationRepository
export let projects: Project[] = []
export let orphanProjects: GithubProject[] = []

/**
* @public
Expand Down Expand Up @@ -112,16 +118,23 @@

const githubProject = client.getHierarchy().as(projectInst, github.mixin.GithubProject)

void getClient().update(githubProject, {
if (githubProject.integration !== integration._id) {
await getClient().update(githubProject, {
integration: integration._id
})
}
await getClient().update(githubProject, {
$push: { repositories: repository._id }
})
void getClient().update(repository, { githubProject: githubProject._id, enabled: true })
await getClient().update(repository, { githubProject: githubProject._id, enabled: true })
}

$: allowedProjects = projects.filter(
(it) =>
(client.getHierarchy().asIf(it, github.mixin.GithubProject)?.integration ?? integration._id) === integration._id
)
$: allowedProjects = projects
.filter(
(it) =>
(client.getHierarchy().asIf(it, github.mixin.GithubProject)?.integration ?? integration._id) === integration._id
)
.concat(orphanProjects)
async function selectProject (event: MouseEvent): Promise<void> {
showPopup(
DropdownLabelsPopup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import GithubRepositories from './GithubRepositories.svelte'

import { WithLookup } from '@hcengineering/core'
import { toIdMap, WithLookup } from '@hcengineering/core'
import { GithubIntegration } from '@hcengineering/github'
import { getClient } from '@hcengineering/presentation'
import { Project } from '@hcengineering/tracker'
import { Scroller } from '@hcengineering/ui'
import { GithubIntegration } from '@hcengineering/github'
import github from '../plugin'

export let integrations: WithLookup<GithubIntegration>[] = []
Expand All @@ -14,6 +14,10 @@
const client = getClient()

$: githubProjects = client.getHierarchy().asIfArray(projects, github.mixin.GithubProject)

$: integerationsMap = toIdMap(integrations)

$: orphanProjects = githubProjects.filter((it) => !integerationsMap.has(it.integration))
</script>

{#if integrations.length > 0}
Expand All @@ -23,7 +27,7 @@
{@const giprj = githubProjects.filter((it) => it.integration === gi._id)}
<div class="flex flex-col mb-4">
<!-- svelte-ignore a11y-missing-attribute -->
<GithubRepositories integration={gi} giProjects={giprj} {projects} />
<GithubRepositories integration={gi} giProjects={giprj} {projects} {orphanProjects} />
</div>
{/each}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import ConnectProject from './ConnectProject.svelte'
import { githubLanguageColors } from './languageColors'
import { sendGHServiceRequest } from './utils'
import { BackgroundColor } from '@hcengineering/text'

export let integration: WithLookup<GithubIntegration>
export let projects: Project[] = []
export let giProjects: GithubProject[] = []
export let orphanProjects: GithubProject[] = []

const client = getClient()

Expand Down Expand Up @@ -235,7 +235,7 @@
/>
</div>
{:else}
<ConnectProject {integration} {repository} {projects} />
<ConnectProject {integration} {repository} {projects} {orphanProjects} />
{/if}
</div>
</div>
Expand Down
62 changes: 3 additions & 59 deletions services/github/github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@
import { ActivityMessage, ActivityMessageViewlet } from '@hcengineering/activity'
import { Attachment } from '@hcengineering/attachment'
import { Person } from '@hcengineering/contact'
import {
Account,
AnyAttribute,
AttachedDoc,
Class,
Data,
Doc,
Hyperlink,
Markup,
Mixin,
Ref,
Timestamp
} from '@hcengineering/core'
import { Account, AttachedDoc, Class, Data, Doc, Hyperlink, Markup, Mixin, Ref, Timestamp } from '@hcengineering/core'
import { Asset, IntlString, Metadata, Plugin, plugin } from '@hcengineering/platform'
import { Preference } from '@hcengineering/preference'
import task, { ProjectTypeDescriptor, TaskStatusFactory, TaskTypeDescriptor } from '@hcengineering/task'
import { ToDo } from '@hcengineering/time'
import { Component, Issue, Milestone, Project } from '@hcengineering/tracker'
import { Component, Issue, Project } from '@hcengineering/tracker'
import { AnyComponent } from '@hcengineering/ui'
import { PaletteColorIndexes } from '@hcengineering/ui/src/colors'

Expand Down Expand Up @@ -456,59 +444,16 @@ export interface GithubUserInfo extends Doc {
avatarUrl?: string
}

/**
* @public
*/
export interface GithubFieldMapping {
// Platform field
_id: Ref<AnyAttribute>
name: string
_class: Ref<Class<Doc>>

// Github information
githubId: string // It could be fieldName or fieldId
}

/**
* @public
*/
export interface GithubProjectSyncData {
// Project NodeId
projectNodeId?: string
projectNumber?: number

githubProjectName?: string

// Mapping of all fields in this project.
mappings: GithubFieldMapping[]

// Update mapping
githubUpdatedAt?: string
}

/**
* @public
*
* Mixin to ordinary project, to allow github repository mapping into it.
*/
export interface GithubProject extends Project, GithubProjectSyncData {
export interface GithubProject extends Project {
integration: Ref<GithubIntegration>

// A list of mapped repositories we synchronized into this project.
repositories: Ref<GithubIntegrationRepository>[]

// Mixin to store all github custom attributes in
mixinClass: Ref<Class<GithubIssue>>
}

/**
* @public
*
* Mixin for milestone to represent a github project for it.
*/
export interface GithubMilestone extends Milestone, GithubProjectSyncData {
// A link to github project.
url: Hyperlink
}

export interface GithubPullRequestReviewThread extends Doc {
Expand Down Expand Up @@ -566,7 +511,6 @@ export default plugin(githubId, {
mixin: {
GithubIssue: '' as Ref<Mixin<GithubIssue>>,
GithubProject: '' as Ref<Mixin<GithubProject>>,
GithubMilestone: '' as Ref<Mixin<GithubMilestone>>,
GithubComponent: '' as Ref<Mixin<GithubComponent>>,
GithubUser: '' as Ref<Mixin<GithubUser>>,
GithubTodo: '' as Ref<Mixin<GithubTodo>>
Expand Down
38 changes: 1 addition & 37 deletions services/github/model-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
import { type Person } from '@hcengineering/contact'
import contact, { TContact } from '@hcengineering/model-contact'
import presentation from '@hcengineering/model-presentation'
import tracker, { TComponent, TIssue, TMilestone, TProject, issuesOptions } from '@hcengineering/model-tracker'
import tracker, { TComponent, TIssue, TProject, issuesOptions } from '@hcengineering/model-tracker'
import view, { classPresenter } from '@hcengineering/model-view'
import workbench from '@hcengineering/model-workbench'
import { getEmbeddedLabel } from '@hcengineering/platform'
Expand All @@ -54,11 +54,9 @@ import {
type DocSyncInfo,
type GithubAuthentication,
type GithubComponent,
type GithubFieldMapping,
type GithubIntegration,
type GithubIntegrationRepository,
type GithubIssue,
type GithubMilestone,
type GithubPatch,
type GithubProject,
type GithubPullRequest,
Expand Down Expand Up @@ -374,16 +372,6 @@ export class TGithubProject extends TProject implements GithubProject {
@ReadOnly()
@Hidden()
projectNumber!: number

@Prop(TypeRef(core.class.Class), getEmbeddedLabel('Attribute Class'))
@ReadOnly()
@Hidden()
mixinClass!: Ref<Class<GithubIssue>>

@Prop(ArrOf(TypeRecord()), getEmbeddedLabel('Field mappings'))
@Hidden()
// Mapping of all fields in this project.
mappings!: GithubFieldMapping[]
}

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

@Mixin(github.mixin.GithubMilestone, tracker.class.Milestone)
@UX(github.string.GithubMilestone)
export class TGithubMilestone extends TMilestone implements GithubMilestone {
@Prop(TypeHyperlink(), getEmbeddedLabel('Github Project URL'))
@Index(IndexKind.FullText)
@ReadOnly()
url!: Hyperlink

@Prop(TypeString(), getEmbeddedLabel('NodeID'))
@Hidden()
@ReadOnly()
projectNodeId!: string

@Prop(TypeNumber(), getEmbeddedLabel('Number'))
@Hidden()
@ReadOnly()
projectNumber!: number

@Prop(ArrOf(TypeRecord()), getEmbeddedLabel('Field mappings'))
// Mapping of all fields in this project.
mappings!: GithubFieldMapping[]
}

@Model(github.class.GithubPullRequest, tracker.class.Issue)
@UX(github.string.PullRequest, github.icon.PullRequest, undefined, undefined, undefined, github.string.PullRequests)
export class TGithubPullRequest extends TIssue implements GithubPullRequest {
Expand Down Expand Up @@ -603,7 +568,6 @@ export function createModel (builder: Builder): void {
TGithubIntegrationRepository,
TGithubPatch,
TGithubUserInfo,
TGithubMilestone,
TGithubComponent,
TGithubUser,
TGithubTodo
Expand Down
20 changes: 8 additions & 12 deletions services/github/pod-github/src/sync/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { collectUpdate, deleteObjects, errorToObj, getSince, isGHWriteAllowed }
import { Analytics } from '@hcengineering/analytics'
import { IssueComment, IssueCommentCreatedEvent, IssueCommentEvent } from '@octokit/webhooks-types'
import config from '../config'
import { syncConfig } from './syncConfig'

interface MessageData {
message: string
Expand Down Expand Up @@ -89,14 +88,6 @@ export class CommentSyncManager implements DocSyncManager {
if (container === undefined) {
return false
}
if (
container?.container === undefined ||
((container.project.projectNodeId === undefined ||
!container.container.projectStructure.has(container.project._id)) &&
syncConfig.MainProject)
) {
return false
}

const commentExternal = info.external as CommentExternalData | undefined

Expand Down Expand Up @@ -531,7 +522,7 @@ export class CommentSyncManager implements DocSyncManager {
}
const syncInfo = await this.client.findAll<DocSyncInfo>(github.class.DocSyncInfo, {
space: repo.githubProject,
repository: repo._id,
// repository: repo._id, // If we skip repository, we will find orphaned comments, so we could connect them on.
objectClass: chunter.class.ChatMessage,
url: { $in: comments.map((it) => (it.url ?? '').toLowerCase()) }
})
Expand All @@ -553,14 +544,19 @@ export class CommentSyncManager implements DocSyncManager {
lastModified
})
} else {
if (!deepEqual(existing.external, comment) || existing.externalVersion !== githubExternalSyncVersion) {
if (
!deepEqual(existing.external, comment) ||
existing.externalVersion !== githubExternalSyncVersion ||
existing.repository !== repo._id
) {
await derivedClient.diffUpdate(
existing,
{
needSync: '',
external: comment,
externalVersion: githubExternalSyncVersion,
lastModified
lastModified,
repository: repo._id
},
lastModified
)
Expand Down
Loading