Skip to content

Commit

Permalink
Merge pull request github#30654 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Dec 13, 2023
2 parents 20a2e96 + c2bcee1 commit 4737755
Show file tree
Hide file tree
Showing 28 changed files with 151 additions and 206 deletions.
2 changes: 1 addition & 1 deletion content/get-started/quickstart/github-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ topics:

## Prerequisites

To follow {% data variables.product.prodname_dotcom %} flow, you will need a {% data variables.product.prodname_dotcom %} account and a repository. {% ifversion fpt or ghec %}For information on how to create an account, see "[AUTOTITLE](/get-started/quickstart/creating-an-account-on-github)."{% elsif ghes or ghae %}For more information, contact your site administrator.{% endif %} For information on how to create a repository, see "[AUTOTITLE](/get-started/quickstart/create-a-repo)."{% ifversion fpt or ghec %} For information on how to find an existing repository to contribute to, see "[AUTOTITLE](/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github)."{% endif %}
To follow {% data variables.product.prodname_dotcom %} flow, you will need a {% data variables.product.prodname_dotcom %} account and a repository. {% ifversion fpt or ghec %}For information on how to create an account, see "[AUTOTITLE](/get-started/quickstart/creating-an-account-on-github)."{% elsif ghes or ghae %}For more information, contact your site administrator.{% endif %} For information on how to create a repository, see "[AUTOTITLE](/repositories/creating-and-managing-repositories/quickstart-for-repositories)."{% ifversion fpt or ghec %} For information on how to find an existing repository to contribute to, see "[AUTOTITLE](/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github)."{% endif %}

## Following {% data variables.product.prodname_dotcom %} flow

Expand Down
1 change: 0 additions & 1 deletion content/get-started/quickstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ children:
- /creating-an-account-on-github
- /hello-world
- /set-up-git
- /create-a-repo
- /fork-a-repo
- /github-flow
- /contributing-to-projects
Expand Down
2 changes: 1 addition & 1 deletion content/get-started/quickstart/set-up-git.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you want to work with Git locally, but do not want to use the command line, y

If you do not need to work with files locally, {% data variables.product.product_name %} lets you complete many Git-related actions directly in the browser, including:

- [Creating a repository](/get-started/quickstart/create-a-repo)
- [AUTOTITLE](/repositories/creating-and-managing-repositories/quickstart-for-repositories)
- [Forking a repository](/get-started/quickstart/fork-a-repo)
- [Managing files](/repositories/working-with-files/managing-files)
- [Being social](/get-started/quickstart/be-social)
Expand Down
2 changes: 1 addition & 1 deletion content/github-cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ featuredLinks:
- /pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
- /issues/tracking-your-work-with-issues/creating-an-issue
- /authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
- /get-started/quickstart/create-a-repo
- /repositories/creating-and-managing-repositories/quickstart-for-repositories
- /pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
- /pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/merging-a-pull-request
- /get-started/quickstart/fork-a-repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ topics:

A repository is the most basic element of {% data variables.product.prodname_dotcom %}. It's a place where you can store your code, your files, and each file's revision history. Repositories can have multiple collaborators and can be either public{% ifversion ghes or ghec %}, internal,{% endif %} or private.

To create a new repository, go to [https://github.com/new](https://github.com/new). For instructions, see "[AUTOTITLE](/get-started/quickstart/create-a-repo)."
To create a new repository, go to [https://github.com/new](https://github.com/new). For instructions, see "[AUTOTITLE](/repositories/creating-and-managing-repositories/quickstart-for-repositories)."

## Repository terminology

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ topics:
children:
- /about-repositories
- /best-practices-for-repositories
- /quickstart-for-repositories
- /repository-limits
- /creating-a-new-repository
- /creating-a-repository-from-a-template
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: Create a repo
title: Quickstart for repositories
type: quick_start
redirect_from:
- /create-a-repo
- /articles/create-a-repo
- /github/getting-started-with-github/create-a-repo
- /github/getting-started-with-github/quickstart/create-a-repo
intro: 'To put your project up on {% data variables.product.prodname_dotcom %}, you will need to create a repository for it to live in.'
- /get-started/quickstart/create-a-repo
intro: 'Learn how to create a new repository and commit your first change in 5 minutes.'
versions:
fpt: '*'
ghes: '*'
Expand All @@ -19,28 +21,7 @@ topics:
---
## Create a repository

{% ifversion fpt or ghec %}

You can store a variety of projects in {% data variables.product.prodname_dotcom %} repositories, including open source projects. With open source projects, you can share code to make better, more reliable software. You can use repositories to collaborate with others and track your work. For more information, see "[AUTOTITLE](/repositories/creating-and-managing-repositories/about-repositories)." To learn more about open source projects, visit [OpenSource.org](https://opensource.org/about).

{% elsif ghes or ghae %}

You can store a variety of projects in {% data variables.product.product_name %} repositories, including innersource projects. With innersource, you can share code to make better, more reliable software. For more information on innersource, see {% data variables.product.company_short %}'s white paper "[An introduction to innersource](https://resources.github.com/whitepapers/introduction-to-innersource/)."

{% endif %}

{% ifversion fpt or ghec %}

{% note %}

**Notes:**
- You can create public repositories for an open source project. When creating your public repository, make sure to include a [license file](https://choosealicense.com/) that determines how you want your project to be shared with others. {% data reusables.open-source.open-source-guide-repositories %}
- {% data reusables.open-source.open-source-learning %}
- You can also add community health files to your repositories, to set guidelines on how to contribute, keep your repositories safe, and much more. For more information, see "[AUTOTITLE](/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file)."

{% endnote %}

{% endif %}
{% data variables.product.product_name %} repositories store a variety of projects. In this guide, you'll create a repository and commit your first change.

{% webui %}

Expand Down
2 changes: 1 addition & 1 deletion content/repositories/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Repositories documentation
shortTitle: Repositories
intro: Learn to use and manage the repositories that allow you to store and collaborate on your project's code.
introLinks:
quickstart: /get-started/quickstart/create-a-repo
quickstart: /repositories/creating-and-managing-repositories/quickstart-for-repositories
overview: /repositories/creating-and-managing-repositories/about-repositories
featuredLinks:
startHere:
Expand Down
2 changes: 1 addition & 1 deletion data/reusables/getting-started/create-a-repository.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Creating a repository for your project allows you to store code in {% data variables.product.prodname_dotcom %}. This provides a backup of your work that you can choose to share with other developers. For more information, see “[Create a repository](/get-started/quickstart/create-a-repo)."
Creating a repository for your project allows you to store code in {% data variables.product.prodname_dotcom %}. This provides a backup of your work that you can choose to share with other developers. For more information, see “[AUTOTITLE](/repositories/creating-and-managing-repositories/quickstart-for-repositories)."
20 changes: 5 additions & 15 deletions src/content-linter/tests/lint-versioning.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { jest } from '@jest/globals'
import Ajv from 'ajv'
import addErrors from 'ajv-errors'
import semver from 'semver'

import featureVersionsSchema from '../lib/feature-versions-schema.js'
import { getDeepDataByLanguage } from '#src/data-directory/lib/get-data.js'
import { getJsonValidator } from '#src/tests/lib/validate-json-schema.js'
import { formatAjvErrors } from '#src/tests/helpers/schemas.js'

/*
Expand All @@ -18,26 +16,18 @@ import { formatAjvErrors } from '#src/tests/helpers/schemas.js'
jest.useFakeTimers({ legacyFakeTimers: true })

const featureVersions = Object.entries(getDeepDataByLanguage('features', 'en'))

const ajv = new Ajv({ allErrors: true, allowUnionTypes: true })
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),
})
// *** End TODO ***
const validate = ajv.compile(featureVersionsSchema)
const validate = getJsonValidator(featureVersionsSchema)

// Make sure data/features/*.yml contains valid versioning.
describe('lint feature versions', () => {
test.each(featureVersions)('data/features/%s matches the schema', (name, featureVersion) => {
const valid = validate(featureVersion)
const isValid = validate(featureVersion)
let errors

if (!valid) {
if (!isValid) {
errors = formatAjvErrors(validate.errors)
}

expect(valid, errors).toBe(true)
expect(isValid, errors).toBe(true)
})
})
10 changes: 3 additions & 7 deletions src/events/middleware.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import express from 'express'
import { omit, without, mapValues } from 'lodash-es'
import Ajv from 'ajv'
import addFormats from 'ajv-formats'
import QuickLRU from 'quick-lru'

import { schemas, hydroNames } from './lib/schema.js'
import catchMiddlewareError from '#src/observability/middleware/catch-middleware-error.js'
import { noCacheControl } from '#src/frame/middleware/cache-control.js'
import { getJsonValidator } from '#src/tests/lib/validate-json-schema.js'
import { formatErrors } from './lib/middleware-errors.js'
import { publish as _publish } from './lib/hydro.js'

const router = express.Router()
const ajv = new Ajv()
addFormats(ajv)
const OMIT_FIELDS = ['type']
const allowedTypes = new Set(without(Object.keys(schemas), 'validation'))
const isProd = process.env.NODE_ENV === 'production'
const validations = mapValues(schemas, (schema) => ajv.compile(schema))

const validators = mapValues(schemas, (schema) => getJsonValidator(schema))
// In production, fire and not wait to respond.
// _publish will send an error to failbot,
// so we don't get alerts but we still track it.
Expand Down Expand Up @@ -47,7 +43,7 @@ router.post(
}

// Validate the data matches the corresponding data schema
const validate = validations[type]
const validate = validators[type]
if (!validate(req.body)) {
const hash = `${req.ip}:${validate.errors
.map((error) => error.message + error.instancePath)
Expand Down
15 changes: 6 additions & 9 deletions src/events/tests/middleware-errors.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import Ajv from 'ajv'
import addFormats from 'ajv-formats'
import { validateJson } from '#src/tests/lib/validate-json-schema.js'
import { formatErrors } from '../lib/middleware-errors.js'
import { schemas } from '../lib/schema.js'

const ajv = new Ajv()
addFormats(ajv)

expect.extend({
toMatchSchema(data, schema) {
const isValid = ajv.validate(schema, data)
const { isValid, errors } = validateJson(schema, data)
return {
pass: isValid,
message: () => (isValid ? '' : ajv.errorsText()),
message: () => (isValid ? '' : errors.message),
}
},
})

describe('formatErrors', () => {
it('should produce objects that match the validation spec', () => {
// Produce an error
ajv.validate({ type: 'string' }, 0)
for (const formatted of formatErrors(ajv.errors, '')) {
const { errors } = validateJson({ type: 'string' }, 0)
const formattedErrors = formatErrors(errors, '')
for (const formatted of formattedErrors) {
expect(formatted).toMatchSchema(schemas.validation)
}
})
Expand Down
35 changes: 11 additions & 24 deletions src/frame/lib/read-frontmatter.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import matter from 'gray-matter'
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 })
ajv.addKeyword({
keyword: 'translatable',
})
ajv.addFormat('semver', {
validate: (x) => semver.validRange(x),
})
addErrors(ajv)
addFormats(ajv)

import { validateJson } from '#src/tests/lib/validate-json-schema.js'

function readFrontmatter(markdown, opts = {}) {
const schema = opts.schema || { type: 'object', properties: {} }
const filepath = opts.filepath || null

let content, data
let errors = []

try {
;({ content, data } = matter(markdown))
Expand All @@ -39,18 +26,13 @@ function readFrontmatter(markdown, opts = {}) {
}

if (filepath) error.filepath = filepath
errors.push(error)
const errors = [error]
console.warn(errors)

return { errors }
}

const ajvValidate = ajv.compile(schema)
const valid = ajvValidate(data)

if (!valid) {
errors = ajvValidate.errors
}
const validate = validateJson(schema, data)

// Combine the AJV-supplied `instancePath` and `params` into a more user-friendly frontmatter path.
// For example, given:
Expand All @@ -69,15 +51,20 @@ function readFrontmatter(markdown, opts = {}) {
return typeof mainProps !== 'object' ? `${prefixProps}.${mainProps}` : prefixProps
}

if (!valid && filepath) {
errors = ajvValidate.errors.map((error) => {
const errors = []

if (!validate.isValid && filepath) {
const formattedErrors = validate.errors.map((error) => {
const userFriendly = {}
userFriendly.property = cleanPropertyPath(error.params, error.instancePath)
userFriendly.message = error.message
userFriendly.reason = error.keyword
userFriendly.filepath = filepath
return userFriendly
})
errors.push(...formattedErrors)
} else if (!validate.isValid) {
errors.push(...validate.errors)
}

return { content, data, errors }
Expand Down
12 changes: 6 additions & 6 deletions src/frame/tests/site-tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ajv from 'ajv'
import { jest } from '@jest/globals'

import { getJsonValidator } from '#src/tests/lib/validate-json-schema.js'
import schema from '#src/tests/helpers/schemas/site-tree-schema.js'
import EnterpriseServerReleases from '#src/versions/lib/enterprise-server-releases.js'
import { loadSiteTree } from '#src/frame/lib/page-data.js'
Expand All @@ -8,8 +9,7 @@ import { formatAjvErrors } from '#src/tests/helpers/schemas.js'

const latestEnterpriseRelease = EnterpriseServerReleases.latest

const ajv = new Ajv({ allErrors: true })
const siteTreeValidate = ajv.compile(schema.childPage)
const siteTreeValidate = getJsonValidator(schema.childPage)

describe('siteTree', () => {
jest.setTimeout(3 * 60 * 1000)
Expand Down Expand Up @@ -58,14 +58,14 @@ describe('siteTree', () => {

function validate(currentPage) {
;(currentPage.childPages || []).forEach((childPage) => {
const valid = siteTreeValidate(childPage)
const isValid = siteTreeValidate(childPage)
let errors

if (!valid) {
if (!isValid) {
errors = `file ${childPage.page.fullPath}: ${formatAjvErrors(siteTreeValidate.errors)}`
}

expect(valid, errors).toBe(true)
expect(isValid, errors).toBe(true)

// Run recurisvely until we run out of child pages
validate(childPage)
Expand Down
14 changes: 11 additions & 3 deletions src/github-apps/scripts/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import yaml from 'js-yaml'
import { getContents } from '#src/workflows/git-utils.js'
import permissionSchema from './permission-list-schema.js'
import enabledSchema from './enabled-list-schema.js'
import { validateData } from '../../rest/scripts/utils/validate-data.js'
import { validateJson } from '#src/tests/lib/validate-json-schema.js'

const ENABLED_APPS_DIR = 'src/github-apps/data'
const CONFIG_FILE = 'src/github-apps/lib/config.json'
Expand Down Expand Up @@ -287,12 +287,20 @@ function initAppData(storage, category, data) {
async function validateAppData(data, pageType) {
if (pageType.includes('permissions')) {
for (const value of Object.values(data)) {
validateData(value, permissionSchema)
const { isValid, errors } = validateJson(permissionSchema, value)
if (!isValid) {
console.error(JSON.stringify(errors, null, 2))
throw new Error('GitHub Apps permission schema validation failed')
}
}
} else {
for (const arrayItems of Object.values(data)) {
for (const item of arrayItems) {
validateData(item, enabledSchema)
const { isValid, errors } = validateJson(enabledSchema, item)
if (!isValid) {
console.error(JSON.stringify(errors, null, 2))
throw new Error('GitHub Apps enabled apps schema validation failed')
}
}
}
}
Expand Down
Loading

0 comments on commit 4737755

Please sign in to comment.