Files
supabase/apps/studio/lib/github.ts
Jordi Enric 6e91494b16 Add coveralls integration (#35424)
* update gh action, update vitest config

* debug

* debug cov

* idk try something different

* test2

* test3

* add base path

* rm debug

* add apiAuthenticate tests

* supabaseClient tests

* apiWrappers tests

* add apiHelpers tests

* add configcat tests

* add formatSql tests

* add github tests

* add cloudprovider utils tests

* add helpers tests

* fix typeerr

* add missing readonly err

* fix typeerrrs

* fix type errors in apiWrapper tests

* fix apiHelpers test

* add packages/ui tests

* add coveralls flags

* try coveralls parallel config

* fix coveralls parallel config

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-05-08 12:23:37 +02:00

70 lines
2.5 KiB
TypeScript

import { LOCAL_STORAGE_KEYS } from 'common'
import { makeRandomString } from './helpers'
const GITHUB_INTEGRATION_APP_NAME =
process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod'
? `supabase`
: process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
? `supabase-staging`
: `supabase-local-testing`
const GITHUB_INTEGRATION_CLIENT_ID =
process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod'
? `Iv1.b91a6d8eaa272168`
: process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
? `Iv1.2681ab9a0360d8ad`
: `Iv1.5022a3b44d150fbf`
const GITHUB_INTEGRATION_AUTHORIZATION_URL = `https://github.com/login/oauth/authorize?client_id=${GITHUB_INTEGRATION_CLIENT_ID}`
export const GITHUB_INTEGRATION_INSTALLATION_URL = `https://github.com/apps/${GITHUB_INTEGRATION_APP_NAME}/installations/new`
export const GITHUB_INTEGRATION_REVOKE_AUTHORIZATION_URL = `https://github.com/settings/connections/applications/${GITHUB_INTEGRATION_CLIENT_ID}`
export function openInstallGitHubIntegrationWindow(type: 'install' | 'authorize') {
const w = 600
const h = 800
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY
const width = window.innerWidth
? window.innerWidth
: document.documentElement.clientWidth
? document.documentElement.clientWidth
: screen.width
const height = window.innerHeight
? window.innerHeight
: document.documentElement.clientHeight
? document.documentElement.clientHeight
: screen.height
let windowUrl
if (type === 'install') {
windowUrl = GITHUB_INTEGRATION_INSTALLATION_URL
} else if (type === 'authorize') {
const state = makeRandomString(32)
localStorage.setItem(LOCAL_STORAGE_KEYS.GITHUB_AUTHORIZATION_STATE, state)
windowUrl = `${GITHUB_INTEGRATION_AUTHORIZATION_URL}&state=${state}`
}
const systemZoom = width / window.screen.availWidth
const left = (width - w) / 2 / systemZoom + dualScreenLeft
const top = (height - h) / 2 / systemZoom + dualScreenTop
const newWindow = window.open(
windowUrl,
'GitHub',
`scrollbars=yes,resizable=no,status=no,location=no,toolbar=no,menubar=no,
width=${w / systemZoom},
height=${h / systemZoom},
top=${top},
left=${left}
`
)
if (newWindow) {
newWindow.focus()
}
}
export const getGitHubProfileImgUrl = (username: string) => {
return `https://github.com/${username}.png?size=96`
}