Skip to content
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
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ jobs:
{ name: 'github-apps', path: 'src/github-apps/tests', },
{ name: 'graphql', path: 'src/graphql/tests', },
{ name: 'landings', path: 'src/landings/tests', },
// { name: 'learning-track', path: 'src/learning-track/tests', },
{ name: 'learning-track', path: 'src/learning-track/tests', },
{ name: 'linting', path: 'src/content-linter/tests', },
{ name: 'observability', path: 'src/observability/tests' },
{ name: 'pageinfo', path: 'src/pageinfo/tests', },
{ name: 'redirects', path: 'src/redirects/tests', },
{ name: 'release-notes', path: 'src/release-notes/tests', },
{ name: 'rendering', path: 'tests/rendering', },
{ name: 'rendering-fixtures', path: 'tests/rendering-fixtures', },
{ name: 'rest', path: 'src/rest/tests', },
{ name: 'routing', path: 'tests/routing', },
{ name: 'search', path: 'src/search/tests', },
{ name: 'secret-scanning', path: 'src/secret-scanning/tests',},
{ name: 'shielding', path: 'src/shielding/tests', },
context.payload.repository.full_name === 'github/docs-internal' &&
{ name: 'languages', path: 'src/languages/tests', },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ class GHAapp < Sinatra::Application
# this request is an attack, and you should reject it. GitHub uses the HMAC
# hexdigest to compute the signature. The `X-HUB-Signature` looks something
# like this: 'sha1=123456'.
# See https://developer.github.com/webhooks/securing/ for details.
def verify_webhook_signature
their_signature_header = request.env['HTTP_X_HUB_SIGNATURE'] || 'sha1='
method, their_digest = their_signature_header.split('=')
Expand Down Expand Up @@ -571,7 +570,7 @@ You can test that the server is listening to your app by triggering an event for

1. Create a new repository to use for testing your tutorial code. For more information, see "[AUTOTITLE](/repositories/creating-and-managing-repositories/creating-a-new-repository)."
1. Install the {% data variables.product.prodname_github_app %} on the repository you just created. For more information, see "[AUTOTITLE](/apps/using-github-apps/installing-your-own-github-app#installing-your-own-github-app)." During the installation process, choose **Only select repositories**, and select the repository you created in the previous step.
2. After you click **Install**, look at the output in the terminal tab where you're running `server.rb`. You should see something like this:
1. After you click **Install**, look at the output in the terminal tab where you're running `server.rb`. You should see something like this:

```shell
> D, [2023-06-08T15:45:43.773077 #30488] DEBUG -- : ---- received event installation
Expand Down Expand Up @@ -1147,7 +1146,7 @@ To push to a repository, your app must have write permissions for "Contents" in
To commit files, Git must know which username and email address to associate with the commit. Next you'll add environment variables to store the name and email address that your app will use when it makes Git commits.

1. Open the `.env` file you created earlier in this tutorial.
2. Add the following environment variables to your `.env` file. Replace `APP_NAME` with the name of your app, and `EMAIL_ADDRESS` with any email you'd like to use for this example.
1. Add the following environment variables to your `.env` file. Replace `APP_NAME` with the name of your app, and `EMAIL_ADDRESS` with any email you'd like to use for this example.

```shell copy
GITHUB_APP_USER_NAME="APP_NAME"
Expand Down Expand Up @@ -1542,7 +1541,6 @@ class GHAapp < Sinatra::Application
# this request is an attack, and you should reject it. GitHub uses the HMAC
# hexdigest to compute the signature. The `X-HUB-Signature` looks something
# like this: 'sha1=123456'.
# See https://developer.github.com/webhooks/securing/ for details.
def verify_webhook_signature
their_signature_header = request.env['HTTP_X_HUB_SIGNATURE'] || 'sha1='
method, their_digest = their_signature_header.split('=')
Expand Down
16 changes: 16 additions & 0 deletions lib/ajv-validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Ajv from 'ajv'
import addErrors from 'ajv-errors'
import addFormats from 'ajv-formats'
import semver from 'semver'

const ajv = new Ajv({ allErrors: true, allowUnionTypes: true })
addFormats(ajv)
addErrors(ajv)
// *** TODO: We can drop this override once the frontmatter schema has been updated to work with AJV. ***
ajv.addFormat('semver', {
validate: (x) => semver.validRange(x),
})

export function ajvValidate(schema) {
return ajv.compile(schema)
}
4 changes: 2 additions & 2 deletions src/content-linter/lib/default-markdownlint-options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function testOptions(rule, module, fixtureFile) {
export function testOptions(rule, module, strings) {
const config = {
default: false,
[rule]: true,
}

const options = {
files: [fixtureFile],
strings,
customRules: [module],
config,
}
Expand Down
9 changes: 9 additions & 0 deletions src/content-linter/lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ export function getRange(line, content) {
const startColumnIndex = line.indexOf(content)
return startColumnIndex !== -1 ? [startColumnIndex + 1, content.length] : null
}

export function isStringQuoted(text) {
// String starts with either a single or double quote
// ends with either a single or double quote
// and optionally ends with a question mark or exclamation point
// because that punctuation can exist outside of the quoted string
const regex = /^['"].*['"][?!]?$/
return text.match(regex)
}
4 changes: 2 additions & 2 deletions src/content-linter/lib/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import markdownlint from 'markdownlint'

import { testOptions } from './default-markdownlint-options.js'

export async function runRule(module, fixtureFile) {
const options = testOptions(module.names[0], module, fixtureFile)
export async function runRule(module, strings) {
const options = testOptions(module.names[0], module, strings)
return await markdownlint.promises.markdownlint(options)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forEachInlineChild } from 'markdownlint-rule-helpers'

import { addFixErrorDetail, getRange } from '../helpers/utils.js'
import { addFixErrorDetail, getRange, isStringQuoted } from '../helpers/utils.js'

export const imageAltTextEndPunctuation = {
names: ['GHD002', 'image-alt-text-end-punctuation'],
Expand All @@ -20,7 +20,9 @@ export const imageAltTextEndPunctuation = {
) {
addFixErrorDetail(onError, token.lineNumber, imageAltText + '.', imageAltText, range, {
lineNumber: token.lineNumber,
editColumn: token.line.indexOf(']') + 1,
editColumn: isStringQuoted(imageAltText)
? token.line.indexOf(']')
: token.line.indexOf(']') + 1,
deleteCount: 0,
insertText: '.',
})
Expand Down
5 changes: 2 additions & 3 deletions src/content-linter/lib/linting-rules/internal-links-lang.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { filterTokens } from 'markdownlint-rule-helpers'

import { addFixErrorDetail, getRange } from '../helpers/utils.js'
import { languageKeys } from '#src/languages/lib/languages.js'
import { allLanguageKeys } from '#src/languages/lib/languages.js'

export const internalLinksLang = {
names: ['GHD005', 'internal-links-lang'],
Expand All @@ -24,7 +23,7 @@ export const internalLinksLang = {
.filter((attr) => attr[0] === 'href')
.filter((attr) => attr[1].startsWith('/') || !attr[1].startsWith('//'))
// Filter out link paths that start with language code
.filter((attr) => languageKeys.some((lang) => attr[1].split('/')[1] === lang))
.filter((attr) => allLanguageKeys.some((lang) => attr[1].split('/')[1] === lang))
// Get the link path from the attribute
.map((attr) => attr[1])
// Create errors for each link path that includes a language code
Expand Down
2 changes: 1 addition & 1 deletion src/content-linter/scripts/markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main()
async function main() {
// If paths has not been specified, lint all files
const files = getFilesToLint((summaryByRule && ALL_CONTENT_DIR) || paths || getChangedFiles())
const spinner = ora({ text: 'Running content linter', spinner: 'simpleDots' })
const spinner = ora({ text: 'Running content linter\n\n', spinner: 'simpleDots' })

if (!files.length) {
spinner.succeed('No files to lint')
Expand Down
33 changes: 33 additions & 0 deletions src/content-linter/style/github-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const githubDocsConfig = {
severity: 'error',
'partial-markdown-files': true,
},
'no-github-docs-domains': {
// GHD020
severity: 'error',
'partial-markdown-files': true,
},
'search-replace': {
severity: 'error',
'severity-local-env': 'warning',
Expand All @@ -45,6 +50,34 @@ export const githubDocsConfig = {
search: 'TODOCS',
searchScope: 'all',
},
{
name: 'docs-domain',
message: 'Catch occurrences of docs.gitub.com domain.',
search: 'docs.gitub.com',
searchScope: 'all',
},
{
name: 'help-domain',
message: 'Catch occurrences of help.github.com domain.',
search: 'help.github.com',
searchScope: 'all',
},
{
name: 'preview-domain',
message: 'Catch occurrences of preview.ghdocs.com domain.',
search: 'preview.ghdocs.com',
searchScope: 'all',
},
{
name: 'developer-domain',
message: 'Catch occurrences of developer.github.com domain.',
// Do not match developer.github.com/changes or
// developer.github.com/enterprise/[0-9] or
// developer.github.com/enterprise/{{something}} (e.g. liquid).
// There are occurences that will likely always remain in the content.
searchPattern: '/developer.github.com(?!/(changes|enterprise/([0-9]|{))).*/g',
searchScope: 'all',
},
],
},
}
31 changes: 0 additions & 31 deletions src/content-linter/tests/fixtures/code-fence-line-length.md

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions src/content-linter/tests/fixtures/image-alt-text-length.md

This file was deleted.

7 changes: 0 additions & 7 deletions src/content-linter/tests/fixtures/image-file-kebab.md

This file was deleted.

21 changes: 0 additions & 21 deletions src/content-linter/tests/fixtures/internal-links-lang.md

This file was deleted.

12 changes: 0 additions & 12 deletions src/content-linter/tests/fixtures/internal-links-slash.md

This file was deleted.

18 changes: 0 additions & 18 deletions src/content-linter/tests/lint-code-languages.js

This file was deleted.

Loading