Throw error on mismatched versioning (#16191)

* throw an error if a page is available in a version that its parent product is not available in

* add tests

* fix one Insights content file versioned for FPT when Insights is only available in GHES currently
This commit is contained in:
Sarah Schneider 2020-10-23 11:13:05 -04:00 коммит произвёл GitHub
Родитель 8d4e30f608
Коммит 095410dcb0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 34 добавлений и 5 удалений

Просмотреть файл

@ -6,7 +6,6 @@ redirect_from:
- /github/installing-and-configuring-github-insights/updating-github-insights
permissions: 'People with read permissions to the `github/insights-releases` repository and administrative access to the application server can update {% data variables.product.prodname_insights %}.'
versions:
free-pro-team: '*'
enterprise-server: '*'
---

Просмотреть файл

@ -6,6 +6,7 @@ const patterns = require('./patterns')
const getMapTopicContent = require('./get-map-topic-content')
const rewriteAssetPathsToS3 = require('./rewrite-asset-paths-to-s3')
const rewriteLocalLinks = require('./rewrite-local-links')
const getApplicableVersions = require('./get-applicable-versions')
const encodeBracketedParentheticals = require('./encode-bracketed-parentheticals')
const generateRedirectsForPermalinks = require('./redirects/permalinks')
const getEnglishHeadings = require('./get-english-headings')
@ -67,6 +68,15 @@ class Page {
delete this.popularLinks
delete this.guideLinks
// a page should only be available in versions that its parent product is available in
const versionsParentProductIsNotAvailableIn = getApplicableVersions(this.versions, this.fullPath)
// only the homepage will not have this.parentProduct
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))
if (versionsParentProductIsNotAvailableIn.length && this.languageCode === 'en') {
throw new Error(`\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`)
}
// derive array of Permalink objects
this.permalinks = Permalink.derive(this.languageCode, this.relativePath, this.title, this.versions)
@ -95,10 +105,12 @@ class Page {
if (id === 'index.md') return null
// make sure the ID is valid
assert(
Object.keys(products).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
if (process.env.NODE_ENV !== 'test') {
assert(
Object.keys(products).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
}
return id
}

Просмотреть файл

@ -0,0 +1,6 @@
---
title: Some GitHub article
versions:
free-pro-team: '*'
enterprise-server: '*'
---

Просмотреть файл

@ -365,4 +365,16 @@ describe('catches errors thrown in Page class', () => {
expect(getPage).toThrowError('versions')
})
test('page with a version in frontmatter that its parent product is not available in', () => {
function getPage () {
return new Page({
relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md',
basePath: path.join(__dirname, '../fixtures/products'),
languageCode: 'en'
})
}
expect(getPage).toThrowError(/`versions` frontmatter.*? product is not available in/)
})
})