Skip to content

Commit 2e92698

Browse files
authored
Merge pull request #37935 from github/repo-sync
Repo sync
2 parents 180f801 + 8b3e8cf commit 2e92698

File tree

15 files changed

+859
-215
lines changed

15 files changed

+859
-215
lines changed

content/webhooks/types-of-webhooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ You can use the {% data variables.product.github %} web interface to manage a {%
6767

6868
## {% data variables.product.prodname_sponsors %} webhooks
6969

70-
You can create webhooks to subscribe to events relating to {% data variables.product.prodname_sponsors %}. You can only create up to {% ifversion ghes %}250{% else %}20{% endif %} webhooks for a {% data variables.product.prodname_sponsors %} account.
70+
You can create webhooks to subscribe to events relating to {% data variables.product.prodname_sponsors %}. You can only create up to 20 webhooks for a {% data variables.product.prodname_sponsors %} account.
7171

7272
You must be an account owner or have admin access in the sponsored account to manage sponsorship webhooks.
7373

data/reusables/contributing/content-linter-rules.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
| GHD018 | liquid-syntax | Markdown content must use valid Liquid | error | liquid |
5757
| GHD019 | liquid-if-tags | Liquid `ifversion` tags should be used instead of `if` tags when the argument is a valid version | error | liquid, versioning |
5858
| GHD020 | liquid-ifversion-tags | Liquid `ifversion` tags should contain valid version names as arguments | error | liquid, versioning |
59-
| GHD022 | liquid-ifversion-versions | Liquid `ifversion` (and `elsif`) should not always be true | warning | liquid, versioning |
6059
| GHD035 | rai-reusable-usage | RAI articles and reusables can only reference reusable content in the data/reusables/rai directory | error | feature, rai |
6160
| GHD036 | image-no-gif | Image must not be a gif, styleguide reference: contributing/style-guide-and-content-model/style-guide.md#images | error | images |
6261
| GHD038 | expired-content | Expired content must be remediated. | error | expired |

src/content-linter/lib/helpers/liquid-utils.js

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Tokenizer } from 'liquidjs'
1+
import { Tokenizer, TokenKind } from 'liquidjs'
2+
3+
import { deprecated } from '#src/versions/lib/enterprise-server-releases.js'
24

35
const liquidTokenCache = new Map()
46

@@ -26,6 +28,7 @@ export const TAG_OPEN = '{{'
2628
export const TAG_CLOSE = '}}'
2729

2830
export const conditionalTags = ['if', 'elseif', 'unless', 'case', 'ifversion']
31+
const CONDITIONAL_TAG_NAMES = ['if', 'ifversion', 'elsif', 'else', 'endif']
2932

3033
export function getPositionData(token, lines) {
3134
// Liquid indexes are 0-based, but we want to
@@ -46,3 +49,104 @@ export function getPositionData(token, lines) {
4649
}
4750
return { lineNumber, column: count, length: end - begin }
4851
}
52+
53+
/* When looking for unused Liquid `ifversion` tags, there
54+
* are a few ways content can be updated to remove
55+
* deprecated conditional statements. This function is
56+
* specific to tags in a statement that are removed along
57+
* with the content in the statement. For example:
58+
*
59+
* {% ifversion < 1.0 %}This is removed{% endif %}
60+
*
61+
* Returns an array of error objects in the format expected
62+
* by Markdownlint:
63+
* [ { lineNumber: 1, column: 1, deleteCount: 3, }]
64+
*/
65+
export function getContentDeleteData(token, tokenEnd, lines) {
66+
const { lineNumber, column } = getPositionData(token, lines)
67+
const errorInfo = []
68+
let begin = column - 1
69+
// Subtract one from end of next token tag. The end of the
70+
// current tag is one position before that.
71+
const length = tokenEnd - token.begin
72+
73+
if (lines[lineNumber - 1].slice(begin).length >= length) {
74+
return [{ lineNumber, column, deleteCount: length }]
75+
}
76+
77+
let remainingLength = length
78+
let incLineNumber = 0
79+
while (remainingLength > 0) {
80+
const zeroBasedLineNumber = lineNumber - 1 + incLineNumber
81+
const line = lines[zeroBasedLineNumber]
82+
const lineLength = line.length
83+
let deleteCount
84+
if (begin !== 0) {
85+
deleteCount = line.slice(begin).length
86+
remainingLength -= deleteCount + 1
87+
} else if (remainingLength >= lineLength) {
88+
deleteCount = -1
89+
remainingLength -= lineLength + 1
90+
} else {
91+
deleteCount = remainingLength
92+
remainingLength -= deleteCount
93+
}
94+
errorInfo.push({ lineNumber: zeroBasedLineNumber + 1, column: begin + 1, deleteCount })
95+
begin = 0
96+
incLineNumber++
97+
}
98+
return errorInfo
99+
}
100+
101+
// This function returns all ifversion conditional statement tags
102+
// and filters out any `if` conditional statements (including the
103+
// related elsif, else, and endif tags).
104+
// Docs doesn't use the standard `if` tag for versioning, instead the
105+
// `ifversion` tag is used.
106+
export function getLiquidIfVersionTokens(content) {
107+
const tokens = getLiquidTokens(content)
108+
.filter((token) => token.kind === TokenKind.Tag)
109+
.filter((token) => CONDITIONAL_TAG_NAMES.includes(token.name))
110+
111+
let inIfStatement = false
112+
const ifVersionTokens = []
113+
for (const token of tokens) {
114+
if (token.name === 'if') {
115+
inIfStatement = true
116+
continue
117+
}
118+
if (inIfStatement && token.name !== 'endif') continue
119+
if (inIfStatement && token.name === 'endif') {
120+
inIfStatement = false
121+
continue
122+
}
123+
ifVersionTokens.push(token)
124+
}
125+
return ifVersionTokens
126+
}
127+
128+
export function getSimplifiedSemverRange(release) {
129+
// Liquid conditionals only use the format > or < but not
130+
// >= or <=. Not sure exactly why.
131+
// if startswith >, we'll check to see if the release number
132+
// is in the deprecated list, meaning the > case can be removed
133+
// or changed to '*'.
134+
const releaseStrings = release.split(' ')
135+
const releaseToCheckIndex = releaseStrings.indexOf('>') + 1
136+
const releaseToCheck = releaseStrings[releaseToCheckIndex]
137+
138+
// If the release is not part of a range and the release number
139+
// is deprecated, return '*' to indicate all ghes releases.
140+
if (deprecated.includes(releaseToCheck) && releaseStrings.length === 2) {
141+
return '*'
142+
}
143+
144+
// When the release is a range and the lower range (e.g., `ghes > 3.12`)
145+
// is now deprecated, return an empty string.
146+
// Otherwise, return the release as-is.
147+
const newRelease = deprecated.includes(releaseToCheck)
148+
? release.replace(`> ${releaseToCheck}`, '')
149+
: release
150+
151+
return newRelease
152+
}

src/content-linter/lib/helpers/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,10 @@ export function getFrontmatter(lines) {
133133
if (Object.keys(data).length === 0) return null
134134
return data
135135
}
136+
137+
export function getFrontmatterLines(lines) {
138+
const indexStart = lines.indexOf('---')
139+
if (indexStart === -1) return []
140+
const indexEnd = lines.indexOf('---', indexStart + 1)
141+
return lines.slice(indexStart, indexEnd + 1)
142+
}

src/content-linter/lib/linting-rules/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ import { liquidDataReferencesDefined, liquidDataTagFormat } from './liquid-data-
2525
import { frontmatterSchema } from './frontmatter-schema.js'
2626
import { codeAnnotations } from './code-annotations.js'
2727
import { frontmatterLiquidSyntax, liquidSyntax } from './liquid-syntax.js'
28-
import { liquidIfTags, liquidIfVersionTags, liquidIfVersionVersions } from './liquid-versioning.js'
28+
import { liquidIfTags, liquidIfVersionTags } from './liquid-versioning.js'
2929
import { raiReusableUsage } from './rai-reusable-usage.js'
3030
import { imageNoGif } from './image-no-gif.js'
3131
import { expiredContent, expiringSoon } from './expired-content.js'
3232
import { tableLiquidVersioning } from './table-liquid-versioning.js'
3333
import { thirdPartyActionPinning } from './third-party-action-pinning.js'
3434
import { liquidTagWhitespace } from './liquid-tag-whitespace.js'
3535
import { linkQuotation } from './link-quotation.js'
36+
import { liquidIfversionVersions } from './liquid-ifversion-versions.js'
3637

3738
const noDefaultAltText = markdownlintGitHub.find((elem) =>
3839
elem.names.includes('no-default-alt-text'),
@@ -72,7 +73,7 @@ export const gitHubDocsMarkdownlint = {
7273
liquidSyntax,
7374
liquidIfTags,
7475
liquidIfVersionTags,
75-
liquidIfVersionVersions,
76+
liquidIfversionVersions,
7677
raiReusableUsage,
7778
imageNoGif,
7879
expiredContent,
@@ -81,5 +82,6 @@ export const gitHubDocsMarkdownlint = {
8182
thirdPartyActionPinning,
8283
liquidTagWhitespace,
8384
linkQuotation,
85+
liquidIfversionVersions,
8486
],
8587
}

0 commit comments

Comments
 (0)