diff --git a/services/github/github-resources/src/components/Configure.svelte b/services/github/github-resources/src/components/Configure.svelte
index e674473c62..902a3d519f 100644
--- a/services/github/github-resources/src/components/Configure.svelte
+++ b/services/github/github-resources/src/components/Configure.svelte
@@ -1,8 +1,8 @@
diff --git a/services/github/github-resources/src/components/Connect.svelte b/services/github/github-resources/src/components/Connect.svelte
index c567972ca6..e4f1053b3a 100644
--- a/services/github/github-resources/src/components/Connect.svelte
+++ b/services/github/github-resources/src/components/Connect.svelte
@@ -8,20 +8,19 @@
import GithubPersonProfile from './GithubPersonProfile.svelte'
+ import type { Integration as AccountIntegration } from '@hcengineering/account-client'
import { Analytics } from '@hcengineering/analytics'
import { WithLookup, getCurrentAccount } from '@hcengineering/core'
import { GithubAuthentication, GithubIntegration } from '@hcengineering/github'
import { getEmbeddedLabel, getMetadata, translate } from '@hcengineering/platform'
- import presentation, { Card, HTMLViewer, NavLink, createQuery, getClient } from '@hcengineering/presentation'
- import { Integration } from '@hcengineering/setting'
+ import presentation, { Card, HTMLViewer, NavLink, createQuery } from '@hcengineering/presentation'
import tracker, { Project } from '@hcengineering/tracker'
import ui, { Button, Label, Loading, TabItem, TabList, location, ticker } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import github from '../plugin'
- import { onAuthorize } from './utils'
- import { clientId } from '@hcengineering/client'
+ import { onAuthorize, updateGithubAccountIntegrationLogin } from './utils'
- export let integration: Integration
+ export let integration: AccountIntegration | undefined
const dispatch = createEventDispatcher()
@@ -59,10 +58,7 @@
})
function save (): void {
- void getClient().diffUpdate(integration, {
- value: auth?.login ?? ''
- })
- dispatch('close', { value: auth?.login ?? '-' })
+ void updateGithubAccountIntegrationLogin(auth?.login ?? '', integration)
}
function onConnect (): void {
const state = btoa(
diff --git a/services/github/github-resources/src/components/utils.ts b/services/github/github-resources/src/components/utils.ts
index 840db2c3d7..013b4f4987 100644
--- a/services/github/github-resources/src/components/utils.ts
+++ b/services/github/github-resources/src/components/utils.ts
@@ -1,11 +1,18 @@
+import {
+ getClient as getAccountClientRaw,
+ type AccountClient,
+ type Integration as AccountIntegration
+} from '@hcengineering/account-client'
import { Analytics } from '@hcengineering/analytics'
import { concatLink, getCurrentAccount, toIdMap, type IdMap } from '@hcengineering/core'
import {
+ githubIntegrationKind,
makeQuery,
type GithubAuthentication,
type GithubIntegrationRepository,
type GithubProject
} from '@hcengineering/github'
+import login from '@hcengineering/login'
import { PlatformError, getMetadata, unknownError } from '@hcengineering/platform'
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
import { location } from '@hcengineering/ui'
@@ -41,6 +48,41 @@ export async function onAuthorize (login?: string): Promise {
window.open(url)
}
+export function getAccountClient (): AccountClient | undefined {
+ const accountsUrl = getMetadata(login.metadata.AccountsUrl)
+ const token = getMetadata(presentation.metadata.Token)
+ if (accountsUrl == null || token == null) {
+ return undefined
+ }
+ return getAccountClientRaw(accountsUrl, token)
+}
+
+export async function updateGithubAccountIntegrationLogin (
+ loginVal: string,
+ integration: AccountIntegration | undefined
+): Promise {
+ try {
+ const accountClient = getAccountClient()
+ if (accountClient === undefined) {
+ throw new Error('Account client is not defined')
+ }
+ const socialId = integration?.socialId ?? getCurrentAccount().primarySocialId
+ const workspaceUuid = integration?.workspaceUuid ?? null
+
+ const key = { socialId, kind: githubIntegrationKind, workspaceUuid }
+ const existing = await accountClient.getIntegration(key)
+ const mergedData = { ...(existing?.data ?? {}), login: loginVal }
+
+ if (existing == null) {
+ throw new Error('Integration not found')
+ }
+ await accountClient.updateIntegration({ ...existing, data: mergedData })
+ } catch (err: any) {
+ console.error('Error updating github account integration login', err)
+ Analytics.handleError(err)
+ }
+}
+
const repositoryQuery = createQuery(true)
/**