Files
supabase/apps/studio/lib/github.tsx
Alaister Young 74563fbeba chore(branching): GitHub integration 2.0 (#21008)
* start new github integration

* query/mutation updates

* progress

* branch management

* update codegen

* progress

* progress

* Refactor GitHub integration URLs

* Refactor GitHubIntegrationAuthorize component

* Updates

* Do not remove GitHub connection when creating new one

* Deleting a GH connection when branching is enabled for the project, will also disable branching for that project

* Add link to configure connection from org integration settings page

* Slight refactor

* Support updating CWD path

* Change cwd_path to workdir and disallow empty values

* Allow for triggering branches on supabase directory changes only

* Pass missing supabaseChangesOnly value

* Small style fix

* Add Authorization GitHub step

* Small change

* Fix supabase integrations form in project settings

* Revert URLa nd client ID

* Fix UI issues

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
2024-03-04 18:17:26 +11:00

54 lines
1.9 KiB
TypeScript

const GITHUB_INTEGRATION_INSTALLATION_URL =
process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod'
? `https://github.com/apps/supabase/installations/new`
: process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
? `https://github.com/apps/supabase-staging/installations/new`
: `https://github.com/apps/supabase-github-v2-migration-test/installations/new`
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 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
const windowUrl =
type === 'install' ? GITHUB_INTEGRATION_INSTALLATION_URL : GITHUB_INTEGRATION_AUTHORIZATION_URL
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()
}
}