Skip to content

Commit 484530c

Browse files
authored
repo sync
2 parents f00d067 + 48f0317 commit 484530c

File tree

4 files changed

+58
-95
lines changed

4 files changed

+58
-95
lines changed

lib/redirects/precompile.js

-41
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ module.exports = async function precompileRedirects (pageList, pageMap) {
5050
const developerRouteWithLanguage = `/en${developerRoute}`
5151
allRedirects[developerRouteWithLanguage] = newPath
5252

53-
// TODO until we update all the old /v3 and /v4 links, we need to support redirects
54-
// from the old /enterprise/<number>/v3 format to the new /enterprise-server@<number/rest format
55-
// AS WELL AS /enterprise-server@<number/v3 to /enterprise-server@<number/rest.
56-
// This is because the new format gets created dynamically even when the links point to /v3 or /v4.
57-
// EXAMPLES:
58-
// /en/enterprise/2.20/v3/pulls/comments -> /en/[email protected]/rest/reference/pulls#comments
59-
// /en/[email protected]/v3/pulls/comments -> /en/[email protected]/rest/reference/pulls#comments
60-
// NOTE: after we update all the /v3 and /v4 links, we can yank the following block
61-
if (developerRoute.includes('/enterprise/')) {
62-
const developerRouteWithNewFormat = developerRoute.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
63-
const developerRouteWithNewFormatWithLanguage = `/en${developerRouteWithNewFormat}`
64-
allRedirects[developerRouteWithNewFormat] = newPath
65-
allRedirects[developerRouteWithNewFormatWithLanguage] = newPath
66-
}
67-
// TODO ENDYANK
68-
6953
// although we only support developer Enterprise paths up to 2.21, we make
7054
// an exception to always redirect versionless paths to the latest version
7155
if (developerRoute.includes('/2.21/')) {
@@ -74,32 +58,7 @@ module.exports = async function precompileRedirects (pageList, pageMap) {
7458
const developerRouteWithLanguageWithoutVersion = `/en${developerRouteWithoutVersion}`
7559
allRedirects[developerRouteWithoutVersion] = newPathOnLatestVersion
7660
allRedirects[developerRouteWithLanguageWithoutVersion] = newPathOnLatestVersion
77-
// TODO after we update all the /v3 and /v4 links, we can yank the following
78-
const developerRouteWithoutVersionWithNewFormat = developerRouteWithoutVersion
79-
.replace('/enterprise/', 'enterprise-server')
80-
const developerRouteWithoutVersionWithNewFormatWithLanguage = `/en${developerRouteWithoutVersionWithNewFormat}`
81-
allRedirects[developerRouteWithoutVersionWithNewFormat] = newPathOnLatestVersion
82-
allRedirects[developerRouteWithoutVersionWithNewFormatWithLanguage] = newPathOnLatestVersion
83-
// TODO ENDYANK
84-
}
85-
86-
// TODO: TEMPORARILY support explicit 2.22 redirects (created on page render by lib/rewrite-local-links)
87-
// after we update `/v3` and `/v4` links everywhere to `/rest` and `/graphql`, we can
88-
// yank this entire block because 2.22 never existed on developer site
89-
if (developerRoute.includes('/2.21/')) {
90-
const newPath222 = newPath.replace('@2.21/', '@2.22/')
91-
const developerRoute222 = developerRoute.replace('/2.21/', '/2.22/')
92-
const developerRouteWithLanguage222 = `/en${developerRoute222}`
93-
allRedirects[developerRoute222] = newPath222
94-
allRedirects[developerRouteWithLanguage222] = newPath222
95-
96-
const developerRouteWithNewFormat222 = developerRoute222
97-
.replace('/enterprise/2.22/', '/[email protected]/')
98-
const developerRouteWithNewFormatWithLanguage222 = `/en${developerRouteWithNewFormat222}`
99-
allRedirects[developerRouteWithNewFormat222] = newPath222
100-
allRedirects[developerRouteWithNewFormatWithLanguage222] = newPath222
10161
}
102-
// TODO ENDYANK
10362

10463
// given a developer route like `/enterprise/2.19/v3/activity`,
10564
// add a veriation like `/enterprise/2.19/user/v3/activity`;

lib/warm-server.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ const loadRedirects = require('./redirects/precompile')
44
const loadSiteData = require('./site-data')
55
const loadSiteTree = require('./site-tree')
66

7+
// Instrument these functions so that
8+
// it's wrapped in a timer that reports to Datadog
9+
const dog = {
10+
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
11+
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
12+
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
13+
loadSiteData: statsd.asyncTimer(loadSiteData, 'load_site_data'),
14+
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
15+
}
16+
717
// For local caching
818
let pageList, pageMap, site, redirects, siteTree
919

@@ -32,21 +42,21 @@ async function warmServer () {
3242
if (!pageList || !site) {
3343
// Promise.all is used to load multiple things in parallel
3444
[pageList, site] = await Promise.all([
35-
pageList || loadPages(),
36-
site || loadSiteData()
45+
pageList || dog.loadPages(),
46+
site || dog.loadSiteData()
3747
])
3848
}
3949

4050
if (!pageMap) {
41-
pageMap = await loadPageMap(pageList)
51+
pageMap = await dog.loadPageMap(pageList)
4252
}
4353

4454
if (!redirects) {
45-
redirects = await loadRedirects(pageList, pageMap)
55+
redirects = await dog.loadRedirects(pageList, pageMap)
4656
}
4757

4858
if (!siteTree) {
49-
siteTree = await loadSiteTree(pageMap, site, redirects)
59+
siteTree = await dog.loadSiteTree(pageMap, site, redirects)
5060
}
5161

5262
if (process.env.NODE_ENV !== 'test') {
@@ -58,7 +68,7 @@ async function warmServer () {
5868

5969
// Instrument the `warmServer` function so that
6070
// it's wrapped in a timer that reports to Datadog
61-
const instrumentedWarmServer = statsd.asyncTimer(warmServer, 'warm_server')
71+
dog.warmServer = statsd.asyncTimer(warmServer, 'warm_server')
6272

6373
// We only want statistics if the priming needs to occur, so let's wrap the
6474
// real method and return early [without statistics] whenever possible
@@ -68,5 +78,5 @@ module.exports = async function warmServerWrapper () {
6878
return getWarmedCache()
6979
}
7080

71-
return instrumentedWarmServer()
81+
return dog.warmServer()
7282
}

script/early-access/create-branch

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# [start-readme]
4+
#
5+
# This script is run on a writer's machine to create an Early Access branch that matches the current docs-internal branch.
6+
#
7+
# [end-readme]
8+
9+
set -e
10+
11+
# Get current branch name
12+
currentBranch=$(git rev-parse --abbrev-ref HEAD)
13+
14+
if [ $currentBranch == "main" ]; then
15+
echo "You cannot run this script on the 'main' branch. Checkout a new branch first."
16+
exit 0
17+
fi
18+
19+
# Go up a directory
20+
pushd .. > /dev/null
21+
22+
if [ ! -d "docs-early-access" ]; then
23+
echo "A 'docs-early-access' directory does not exist! Run script/early-access/clone-locally first."
24+
popd > /dev/null
25+
exit 0
26+
fi
27+
28+
# Navigate to docs-early-access
29+
cd docs-early-access
30+
31+
# Check out main and update
32+
git checkout main
33+
git pull origin main
34+
35+
# Create a branch with the current docs-internal branch name
36+
git checkout -b $currentBranch
37+
38+
# Go back to the previous working directory
39+
popd > /dev/null
40+
41+
echo -e "\nDone! Created a branch called ${currentBranch}. Remember to commit your work in ../docs-early-access when you're ready."

tests/routing/developer-site-redirects.js

-47
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { eachOfLimit } = require('async')
22
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
33
const { get } = require('../helpers/supertest')
4-
const { getEnterpriseVersionNumber } = require('../../lib/patterns')
54
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
65
const restRedirectFixtures = require('../fixtures/rest-redirects')
76
const graphqlRedirectFixtures = require('../fixtures/graphql-redirects')
@@ -126,29 +125,6 @@ describe('developer redirects', () => {
126125
)
127126
})
128127

129-
// TODO temporarily ensure we redirect old links using the new enterprise format
130-
// for currently supported enterprise releases only
131-
// EXAMPLE: /en/[email protected]/v3/pulls/comments -> /en/[email protected]/rest/reference/pulls#comments
132-
// We can remove test after we update all the old `/v3` links to point to `/rest`
133-
test('temporary rest reference enterprise redirects', async () => {
134-
await eachOfLimit(
135-
restRedirectFixtures,
136-
MAX_CONCURRENT_REQUESTS,
137-
async (newPath, oldPath) => {
138-
const releaseNumber = oldPath.match(getEnterpriseVersionNumber)
139-
if (!releaseNumber) return
140-
if (!enterpriseServerReleases.supported.includes(releaseNumber[1])) return
141-
142-
oldPath = oldPath
143-
.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
144-
.replace('/user/', '/')
145-
const res = await get(oldPath)
146-
expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
147-
expect(res.headers.location).toBe(newPath)
148-
}
149-
)
150-
})
151-
152128
// this fixtures file includes /v4 and /enterprise/v4 paths
153129
test('graphql reference redirects', async () => {
154130
await eachOfLimit(
@@ -164,28 +140,5 @@ describe('developer redirects', () => {
164140
}
165141
)
166142
})
167-
168-
// TODO temporarily ensure we redirect old links using the new enterprise format
169-
// for currently supported enterprise releases only
170-
// EXAMPLE: /en/[email protected]/v4/interface/actor -> /en/[email protected]/graphql/reference/interfaces#actor
171-
// We can remove test after we update all the old `/v4` links to point to `/graphql`
172-
test('temporary rest reference enterprise redirects', async () => {
173-
await eachOfLimit(
174-
graphqlRedirectFixtures,
175-
MAX_CONCURRENT_REQUESTS,
176-
async (newPath, oldPath) => {
177-
const releaseNumber = oldPath.match(getEnterpriseVersionNumber)
178-
if (!releaseNumber) return
179-
if (!enterpriseServerReleases.supported.includes(releaseNumber[1])) return
180-
181-
oldPath = oldPath
182-
.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
183-
.replace('/user/', '/')
184-
const res = await get(oldPath)
185-
expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
186-
expect(res.headers.location).toBe(newPath)
187-
}
188-
)
189-
})
190143
})
191144
})

0 commit comments

Comments
 (0)