Skip to content

Commit

Permalink
feat: fetch integrations only when online
Browse files Browse the repository at this point in the history
  • Loading branch information
khendrikse committed Nov 10, 2023
1 parent d7a432c commit fc1c071
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/config/src/api/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ type AvailableIntegration = {

type GetAvailableIntegrationsOpts = {
testOpts: TestOptions
offline: boolean
}

export const getAvailableIntegrations = async function ({
testOpts,
offline,
}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
if (offline) {
return []
}
const { host } = testOpts
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)

Expand Down
13 changes: 9 additions & 4 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getSiteInfo = async function ({
if (api === undefined || mode === 'buildbot' || testEnv) {
const siteInfo = siteId === undefined ? {} : { id: siteId }

const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts }) : []
const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : []

return { siteInfo, accounts: [], addons: [], integrations }
}
Expand All @@ -47,7 +47,7 @@ export const getSiteInfo = async function ({
getSite(api, siteId, siteFeatureFlagPrefix),
getAccounts(api),
getAddons(api, siteId),
getIntegrations({ siteId, testOpts }),
getIntegrations({ siteId, testOpts, offline }),
]

const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
Expand Down Expand Up @@ -99,10 +99,15 @@ const getAddons = async function (api: NetlifyAPI, siteId: string) {
type GetIntegrationsOpts = {
siteId?: string
testOpts: TestOptions
offline: boolean
}

const getIntegrations = async function ({ siteId, testOpts }: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
if (!siteId) {
const getIntegrations = async function ({
siteId,
testOpts,
offline,
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
if (!siteId || offline) {
return []
}

Expand Down
4 changes: 3 additions & 1 deletion packages/config/src/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ type MergeIntegrationsOpts = {
apiIntegrations: IntegrationResponse[]
context: string
testOpts?: TestOptions
offline: boolean
}

export const mergeIntegrations = async function ({
configIntegrations = [],
apiIntegrations,
context,
testOpts = {},
offline,
}: MergeIntegrationsOpts): Promise<Integration[]> {
const availableIntegrations = await getAvailableIntegrations({ testOpts })
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline })

// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
const resolvedApiIntegrations = apiIntegrations.filter(
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const resolveConfig = async function (opts) {
configIntegrations: configA.integrations,
context: context,
testOpts,
offline,
})

const result = {
Expand Down

0 comments on commit fc1c071

Please sign in to comment.