Skip to content

repo sync #24705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/openapi-decorate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:

- name: Checkout repository code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
with:
# In order to fail gracefully when a branch already exists
# in the "Create pull request" step, we need to be able
# to get all existing branches.
fetch-depth: 0

# Check out a nested repository inside of previous checkout
- name: Checkout rest-api-description repo
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
{ name: 'content', path: 'tests/content', },
{ name: 'graphql', path: 'tests/graphql', },
{ name: 'events', path: 'src/events/tests', },
{ name: 'automated-pipelines', path: 'src/automated-pipelines/tests', },
{ name: 'linting', path: 'tests/linting', },
{ name: 'meta', path: 'tests/meta', },
{ name: 'routing', path: 'tests/routing', },
Expand Down
1 change: 0 additions & 1 deletion lib/liquid-tags/extended-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const subsetTags = {
mac: '',
windows: '',
linux: '',
all: '',
tip: 'border rounded-1 mb-4 p-3 color-border-accent-emphasis color-bg-accent f5',
note: 'border rounded-1 mb-4 p-3 color-border-accent-emphasis color-bg-accent f5',
warning: 'border rounded-1 mb-4 p-3 color-border-danger color-bg-danger f5',
Expand Down
37 changes: 27 additions & 10 deletions lib/update-internal-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function updateFile(file, context, opts) {
try {
if (Array.isArray(data[key])) {
if ((Array.isArray(seek) && seek.includes(key)) || seek === IS_ARRAY || seek === ANY) {
const better = getNewFrontmatterLinkList(data[key], context, opts, file)
const better = getNewFrontmatterLinkList(data[key], context, opts, file, rawContent)
if (!equalArray(better, data[key])) {
newData[key] = better
}
Expand All @@ -143,7 +143,7 @@ async function updateFile(file, context, opts) {
seek === IS_ARRAY ||
seek === ANY
) {
const better = getNewFrontmatterLinkList(thing, context, opts, file)
const better = getNewFrontmatterLinkList(thing, context, opts, file, rawContent)
if (!equalArray(better, thing)) {
newData[key][group] = better
}
Expand Down Expand Up @@ -318,7 +318,7 @@ function matcher(node) {
return false
}

function getNewFrontmatterLinkList(list, context, opts, file) {
function getNewFrontmatterLinkList(list, context, opts, file, rawContent) {
/**
* The `list` is expected to all be strings. Sometimes they're like this:
*
Expand Down Expand Up @@ -350,15 +350,17 @@ function getNewFrontmatterLinkList(list, context, opts, file) {
} else {
const redirected = getRedirect(asURL, context)
if (redirected === undefined) {
const lineNumber = findLineNumber(entry, rawContent)
const msg =
'A frontmatter link appears to be broken. ' +
`Neither redirect or a findable page: ${pure}. (file: ${file} line: ${
lineNumber || 'unknown'
})`

if (opts.strict) {
throw new Error(
`Neither redirecting nor findable '${asURL}' in frontmatter link. (file: ${file})`
)
throw new Error(msg)
}
console.warn(
'WARNING: A frontmatter link appears to be broken. ' +
`Neither redirect or a findable page: ${pure}. (file: ${file})`
)
console.warn(`WARNING: ${msg}`)
better.push(entry)
} else {
// Perhaps it just redirected to a specific version
Expand All @@ -375,6 +377,21 @@ function getNewFrontmatterLinkList(list, context, opts, file) {
return better
}

// Try to return the line in the raw content that entry was on.
// It's hard to know exactly because the `entry` is the result of parsing
// the YAML, most likely, from the front
function findLineNumber(entry, rawContent) {
let number = 0
for (const line of rawContent.split(/\n/g)) {
number++
if (line.endsWith(entry) && line.includes(` ${entry}`)) {
return number
}
}

return null
}

const liquidStartRex = /^{%-?\s*ifversion .+?\s*%}/
const liquidEndRex = /{%-?\s*endif\s*-?%}$/

Expand Down
Loading