Skip to content

Commit 15bec28

Browse files
authored
fix: revert b8899e0 (#5689)
1 parent 1c9333c commit 15bec28

File tree

4 files changed

+18
-159
lines changed

4 files changed

+18
-159
lines changed

packages/config/src/api/site_info.ts

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type GetSiteInfoOpts = {
1414
offline?: boolean
1515
api?: NetlifyAPI
1616
context?: string
17+
featureFlags?: Record<string, boolean>
1718
testOpts?: TestOptions
1819
}
1920
/**
@@ -36,49 +37,22 @@ export const getSiteInfo = async function ({
3637
}: GetSiteInfoOpts) {
3738
const { env: testEnv = false } = testOpts
3839

39-
if (api === undefined || testEnv || offline) {
40+
if (api === undefined || mode === 'buildbot' || testEnv) {
4041
const siteInfo = siteId === undefined ? {} : { id: siteId }
4142

42-
return { siteInfo, accounts: [], addons: [], integrations: [] }
43-
}
44-
45-
const siteInfo = await getSite(api, siteId, siteFeatureFlagPrefix)
46-
const featureFlags = siteInfo.feature_flags
47-
48-
const useV2Endpoint = featureFlags?.cli_integration_installations_meta
49-
50-
if (useV2Endpoint) {
51-
const promises = [
52-
getAccounts(api),
53-
getAddons(api, siteId),
54-
getIntegrations({ siteId, testOpts, offline, accountId: siteInfo.account_id, featureFlags }),
55-
]
56-
57-
const [accounts, addons, integrations] = await Promise.all<any[]>(promises)
58-
59-
if (siteInfo.use_envelope) {
60-
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context })
61-
62-
siteInfo.build_settings.env = envelope
63-
}
64-
65-
return { siteInfo, accounts, addons, integrations }
66-
}
67-
if (mode === 'buildbot') {
68-
const siteInfo = siteId === undefined ? {} : { id: siteId }
69-
70-
const integrations = await getIntegrations({ siteId, testOpts, offline, featureFlags })
43+
const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : []
7144

7245
return { siteInfo, accounts: [], addons: [], integrations }
7346
}
7447

7548
const promises = [
49+
getSite(api, siteId, siteFeatureFlagPrefix),
7650
getAccounts(api),
7751
getAddons(api, siteId),
78-
getIntegrations({ siteId, testOpts, offline, featureFlags }),
52+
getIntegrations({ siteId, testOpts, offline }),
7953
]
8054

81-
const [accounts, addons, integrations] = await Promise.all(promises)
55+
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
8256

8357
if (siteInfo.use_envelope) {
8458
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context })
@@ -98,7 +72,7 @@ const getSite = async function (api: NetlifyAPI, siteId: string, siteFeatureFlag
9872
const site = await (api as any).getSite({ siteId, feature_flags: siteFeatureFlagPrefix })
9973
return { ...site, id: siteId }
10074
} catch (error) {
101-
return throwUserError(`Failed retrieving site data for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
75+
throwUserError(`Failed retrieving site data for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
10276
}
10377
}
10478

@@ -107,7 +81,7 @@ const getAccounts = async function (api: NetlifyAPI) {
10781
const accounts = await (api as any).listAccountsForUser()
10882
return Array.isArray(accounts) ? accounts : []
10983
} catch (error) {
110-
return throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
84+
throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
11185
}
11286
}
11387

@@ -120,24 +94,20 @@ const getAddons = async function (api: NetlifyAPI, siteId: string) {
12094
const addons = await (api as any).listServiceInstancesForSite({ siteId })
12195
return Array.isArray(addons) ? addons : []
12296
} catch (error) {
123-
return throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
97+
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
12498
}
12599
}
126100

127101
type GetIntegrationsOpts = {
128102
siteId?: string
129-
accountId?: string
130103
testOpts: TestOptions
131104
offline: boolean
132-
featureFlags?: Record<string, boolean>
133105
}
134106

135107
const getIntegrations = async function ({
136108
siteId,
137-
accountId,
138109
testOpts,
139110
offline,
140-
featureFlags,
141111
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
142112
if (!siteId || offline) {
143113
return []
@@ -147,21 +117,13 @@ const getIntegrations = async function ({
147117

148118
const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)
149119

150-
const useV2Endpoint = featureFlags?.cli_integration_installations_meta
151-
152-
const url = useV2Endpoint
153-
? `${baseUrl}team/${accountId}/integrations/installations/meta`
154-
: `${baseUrl}site/${siteId}/integrations/safe`
155-
156120
try {
157-
const response = await fetch(url)
121+
const response = await fetch(`${baseUrl}site/${siteId}/integrations/safe`)
158122

159123
const integrations = await response.json()
160124
return Array.isArray(integrations) ? integrations : []
161125
} catch (error) {
162-
// Integrations should not block the build if they fail to load
163-
// TODO: We should consider blocking the build as integrations are a critical part of the build process
164-
// https://linear.app/netlify/issue/CT-1214/implement-strategy-in-builds-to-deal-with-integrations-that-we-fail-to
126+
// for now, we'll just ignore errors, as this is early days
165127
return []
166128
}
167129
}

packages/config/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// We distinguish between errors thrown intentionally and uncaught exceptions
22
// (such as bugs) with a `customErrorInfo.type` property.
3-
export const throwUserError = function (messageOrError: string | Error, error?: Error): never {
3+
export const throwUserError = function (messageOrError: string | Error, error?: Error) {
44
const errorA = getError(messageOrError, error)
55
errorA[CUSTOM_ERROR_KEY] = { type: USER_ERROR_TYPE }
66
throw errorA

packages/config/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const resolveConfig = async function (opts) {
7373
mode,
7474
offline,
7575
siteFeatureFlagPrefix,
76+
featureFlags,
7677
testOpts,
7778
})
7879

packages/config/tests/api/tests.js

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,11 @@ const SITE_INTEGRATIONS_RESPONSE = {
2626
],
2727
}
2828

29-
const TEAM_INSTALLATIONS_META_RESPONSE = {
30-
path: '/team/account1/integrations/installations/meta',
31-
response: [
32-
{
33-
slug: 'test',
34-
version: 'so-cool',
35-
has_build: true,
36-
},
37-
],
38-
}
39-
4029
const SITE_INTEGRATIONS_EMPTY_RESPONSE = {
4130
path: '/site/test/integrations/safe',
4231
response: [],
4332
}
4433

45-
const siteInfoWithFeatureFlag = (flag) => {
46-
return {
47-
path: SITE_INFO_PATH,
48-
response: {
49-
ssl_url: 'test',
50-
name: 'test-name',
51-
build_settings: { repo_url: 'test' },
52-
account_id: 'account1',
53-
feature_flags: {
54-
[flag]: true,
55-
},
56-
},
57-
}
58-
}
59-
6034
const SITE_INFO_BUILD_SETTINGS = {
6135
path: SITE_INFO_PATH,
6236
response: {
@@ -333,114 +307,36 @@ test('In integration dev mode, integration specified in config is returned and b
333307
t.assert(config.integrations[0].version === undefined)
334308
})
335309

336-
test('Integrations are not returned if offline', async (t) => {
310+
test('Integrations are returned if feature flag is true, mode buildbot', async (t) => {
337311
const { output } = await new Fixture('./fixtures/base')
338312
.withFlags({
339-
offline: true,
340313
siteId: 'test',
341314
mode: 'buildbot',
342315
})
343316
.runConfigServer([SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
344317

345318
const config = JSON.parse(output)
346319

347-
t.assert(config.integrations)
348-
t.assert(config.integrations.length === 0)
349-
})
350-
351-
test('Integrations are not returned if no api', async (t) => {
352-
const { output } = await new Fixture('./fixtures/base')
353-
.withFlags({
354-
siteId: 'test',
355-
mode: 'buildbot',
356-
})
357-
.runConfigServer([SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
358-
359-
const config = JSON.parse(output)
360-
361-
t.assert(config.integrations)
362-
t.assert(config.integrations.length === 0)
363-
})
364-
365-
test('Integrations are returned if feature flag is false and mode is buildbot', async (t) => {
366-
const { output } = await new Fixture('./fixtures/base')
367-
.withFlags({
368-
siteId: 'test',
369-
mode: 'buildbot',
370-
token: 'test',
371-
})
372-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
373-
374-
const config = JSON.parse(output)
375-
376320
t.assert(config.integrations)
377321
t.assert(config.integrations.length === 1)
378322
t.assert(config.integrations[0].slug === 'test')
379323
t.assert(config.integrations[0].version === 'so-cool')
380324
t.assert(config.integrations[0].has_build === true)
381325
})
382326

383-
test('Integrations are returned if feature flag is false and mode is dev', async (t) => {
384-
const { output } = await new Fixture('./fixtures/base')
385-
.withFlags({
386-
siteId: 'test',
387-
mode: 'dev',
388-
token: 'test',
389-
})
390-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
391-
392-
const config = JSON.parse(output)
393-
394-
t.assert(config.integrations)
395-
t.assert(config.integrations.length === 1)
396-
t.assert(config.integrations[0].slug === 'test')
397-
t.assert(config.integrations[0].version === 'so-cool')
398-
t.assert(config.integrations[0].has_build === true)
399-
})
400-
401-
// new tests
402-
test('Integrations are returned if flag is true for site and mode is buildbot', async (t) => {
327+
test('Integrations are not returned if offline', async (t) => {
403328
const { output } = await new Fixture('./fixtures/base')
404329
.withFlags({
330+
offline: true,
405331
siteId: 'test',
406332
mode: 'buildbot',
407-
token: 'test',
408-
})
409-
.runConfigServer([
410-
siteInfoWithFeatureFlag('cli_integration_installations_meta'),
411-
TEAM_INSTALLATIONS_META_RESPONSE,
412-
FETCH_INTEGRATIONS_EMPTY_RESPONSE,
413-
])
414-
415-
const config = JSON.parse(output)
416-
417-
t.assert(config.integrations)
418-
t.assert(config.integrations.length === 1)
419-
t.assert(config.integrations[0].slug === 'test')
420-
t.assert(config.integrations[0].version === 'so-cool')
421-
t.assert(config.integrations[0].has_build === true)
422-
})
423-
424-
test('Integrations are returned if flag is true for site and mode is dev', async (t) => {
425-
const { output } = await new Fixture('./fixtures/base')
426-
.withFlags({
427-
siteId: 'test',
428-
mode: 'dev',
429-
token: 'test',
430333
})
431-
.runConfigServer([
432-
siteInfoWithFeatureFlag('cli_integration_installations_meta'),
433-
TEAM_INSTALLATIONS_META_RESPONSE,
434-
FETCH_INTEGRATIONS_EMPTY_RESPONSE,
435-
])
334+
.runConfigServer([SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
436335

437336
const config = JSON.parse(output)
438337

439338
t.assert(config.integrations)
440-
t.assert(config.integrations.length === 1)
441-
t.assert(config.integrations[0].slug === 'test')
442-
t.assert(config.integrations[0].version === 'so-cool')
443-
t.assert(config.integrations[0].has_build === true)
339+
t.assert(config.integrations.length === 0)
444340
})
445341

446342
test('baseRelDir is true if build.base is overridden', async (t) => {

0 commit comments

Comments
 (0)