Skip to content

Commit

Permalink
Merge branch 'main' into fix-composite-action
Browse files Browse the repository at this point in the history
  • Loading branch information
ramyaparimi authored May 11, 2022
2 parents b7f3c52 + 04455e2 commit 01639a8
Show file tree
Hide file tree
Showing 337 changed files with 2,398,620 additions and 388,339 deletions.
69 changes: 57 additions & 12 deletions .github/actions-scripts/content-changes-table-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import * as github from '@actions/github'
import { setOutput } from '@actions/core'

import { getContents } from '../../script/helpers/git-utils.js'
import parse from '../../lib/read-frontmatter.js'
import getApplicableVersions from '../../lib/get-applicable-versions.js'
import nonEnterpriseDefaultVersion from '../../lib/non-enterprise-default-version.js'

const { GITHUB_TOKEN, APP_URL } = process.env
const context = github.context

Expand All @@ -14,13 +19,13 @@ if (!APP_URL) {
throw new Error(`APP_URL environment variable not set`)
}

const PROD_URL = 'https://docs.github.com'
const octokit = github.getOctokit(GITHUB_TOKEN)

const response = await octokit.rest.repos.compareCommits({
const response = await octokit.rest.repos.compareCommitsWithBasehead({
owner: context.repo.owner,
repo: context.payload.repository.name,
base: context.payload.pull_request.base.sha,
head: context.payload.pull_request.head.sha,
basehead: `${context.payload.pull_request.base.sha}...${context.payload.pull_request.head.sha}`,
})

const { files } = response.data
Expand All @@ -36,16 +41,56 @@ for (const file of articleFiles) {
const sourceUrl = file.blob_url
const fileName = file.filename.slice(pathPrefix.length)
const fileUrl = fileName.slice(0, fileName.lastIndexOf('.'))
const previewLink = `${APP_URL}/${fileUrl}`
const productionLink = `https://docs.github.com/${fileUrl}`
let markdownLine = ''

if (file.status === 'modified') {
markdownLine = `| [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | [Original](${productionLink}) | |\n`
} else if (file.status === 'added') {
markdownLine = `| New file: [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | | |\n`

// get the file contents and decode them
// this script is called from the main branch, so we need the API call to get the contents from the branch, instead
const fileContents = await getContents(
context.repo.owner,
context.payload.repository.name,
context.payload.pull_request.head.sha,
file.filename
)

// parse the frontmatter
const { data } = parse(fileContents)

let contentCell = ''
let previewCell = ''
let prodCell = ''

if (file.status === 'added') contentCell = `New file: `
contentCell += `[\`${fileName}\`](${sourceUrl})`

for (const version in data.versions) {
const currentApplicableVersions = getApplicableVersions({
[version]: data.versions[version],
})

if (currentApplicableVersions.length === 1) {
// for fpt, ghec, and ghae
if (currentApplicableVersions.toString() === nonEnterpriseDefaultVersion) {
// omit version from fpt url
previewCell += `[${version}](${APP_URL}/${fileUrl})<br>`
prodCell += `[${version}](${PROD_URL}/${fileUrl})<br>`
} else {
// for non-versioned releases (ghae, ghec) use full url
previewCell += `[${version}](${APP_URL}/${currentApplicableVersions}/${fileUrl})<br>`
prodCell += `[${version}](${PROD_URL}/${currentApplicableVersions}/${fileUrl})<br>`
}
} else {
// for ghes releases, link each version
previewCell += `${version}@ `
prodCell += `${version}@ `

currentApplicableVersions.forEach((ghesVersion) => {
previewCell += `[${ghesVersion.split('@')[1]}](${APP_URL}/${ghesVersion}/${fileUrl}) `
prodCell += `[${ghesVersion.split('@')[1]}](${PROD_URL}/${ghesVersion}/${fileUrl}) `
})
previewCell += '<br>'
prodCell += '<br>'
}
}
markdownTable += markdownLine
markdownTable += `| ${contentCell} | ${previewCell} | ${prodCell} | |\n`
}

setOutput('changesTable', markdownTable)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion components/guides/ProductGuides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { useTranslation } from 'components/hooks/useTranslation'

export const ProductGuides = () => {
const { title, learningTracks, includeGuides } = useProductGuidesContext()
const { t } = useTranslation('sub_landing')
const { t } = useTranslation('product_guides')

return (
<DefaultLayout>
<LandingSection className="pt-3">
Expand Down
18 changes: 13 additions & 5 deletions components/lib/get-rest-code-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export function getGHExample(operation: Operation, codeSample: CodeSample) {
requestBodyParams = Object.keys(codeSample.request.bodyParameters)
.map((key) => {
if (typeof codeSample.request.bodyParameters[key] === 'string') {
return `-f ${key}='${codeSample.request.bodyParameters[key]}'`
return `-f ${key}='${codeSample.request.bodyParameters[key]}'\n`
} else {
return `-F ${key}=${codeSample.request.bodyParameters[key]}`
return `-F ${key}=${codeSample.request.bodyParameters[key]}\n`
}
})
.join(' ')
Expand All @@ -97,7 +97,9 @@ export function getGHExample(operation: Operation, codeSample: CodeSample) {
requestPath,
requestBodyParams,
].filter(Boolean)
return `gh api \\\n ${args.join(' \\\n ')}`
return `# GitHub CLI api\n# https://cli.github.com/manual/gh_api\n\ngh api \\\n ${args.join(
' \\\n '
)}`
}

/*
Expand Down Expand Up @@ -135,8 +137,14 @@ export function getJSExample(operation: Operation, codeSample: CodeSample) {
queryParameters = `{?${queryParms.join(',')}}`
}
}

return `await octokit.request('${operation.verb.toUpperCase()} ${
const comment = `// Octokit.js\n// https://github.com/octokit/core.js#readme\n`
const require = `const octokit = new Octokit(${stringify(
{ auth: 'personal-access-token123' },
null,
2
)})\n\n`

return `${comment}${require}await octokit.request('${operation.verb.toUpperCase()} ${
operation.requestPath
}${queryParameters}', ${stringify(parameters, null, 2)})`
}
45 changes: 0 additions & 45 deletions components/rest/BodyParametersRows.tsx

This file was deleted.

85 changes: 41 additions & 44 deletions components/rest/ChildBodyParametersRows.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useTranslation } from 'components/hooks/useTranslation'
import { ParameterRow } from './ParameterRow'
import type { ChildParamsGroup } from './types'

type Props = {
Expand All @@ -12,50 +13,46 @@ export function ChildBodyParametersRows({ slug, childParamsGroups }: Props) {
return (
<tr className="border-none">
<td colSpan={4} className="has-nested-table">
{childParamsGroups?.map((childParamGroup) => {
return (
<details key={childParamGroup.id}>
<summary
role="button"
aria-expanded="false"
className="keyboard-focus color-fg-muted"
>
<span className="d-inline-block mb-3" id={`${slug}-${childParamGroup.id}`}>
Properties of the
<code>{childParamGroup.parentName}</code>
{childParamGroup.parentType}
</span>
</summary>
<table
id={`${childParamGroup.parentName}-object`}
className="ml-4 mb-4 mt-2 color-bg-subtle"
>
<thead>
<tr>
<th>
{t('rest.reference.name')} ({t('rest.reference.type')})
</th>
<th>{t('rest.reference.description')}</th>
</tr>
</thead>
<tbody>
{childParamGroup.params.map((childParam) => {
return (
<tr key={`${childParam.name}-${childParam.description}`}>
<td className="color-bg-subtle">
<code>{childParam.name}</code> ({childParam.type})
</td>
<td className="color-bg-subtle">
<div dangerouslySetInnerHTML={{ __html: childParam.description }} />
</td>
</tr>
)
})}
</tbody>
</table>
</details>
)
})}
{childParamsGroups?.map((childParamGroup) => (
<details key={childParamGroup.id}>
<summary role="button" aria-expanded="false" className="keyboard-focus color-fg-muted">
<span className="d-inline-block mb-3" id={`${slug}-${childParamGroup.id}`}>
Properties of the
<code>{childParamGroup.parentName}</code>
{childParamGroup.parentType}
</span>
</summary>
<table
id={`${childParamGroup.parentName}-object`}
className="ml-4 mb-4 mt-2 color-bg-subtle"
>
<thead className="visually-hidden">
<tr>
<th>
{`${t('rest.reference.name')}, ${t('rest.reference.type')}, ${t(
'rest.reference.description'
)}`}
</th>
</tr>
</thead>
<tbody>
{childParamGroup.params.map((childParam, index) => (
<ParameterRow
name={childParam.name}
description={childParam.description}
type={childParam.type}
isRequired={childParam.isRequired}
defaultValue={childParam.default}
enumValues={childParam.enum}
slug={slug}
isChild={true}
key={`${index}-${childParam}`}
/>
))}
</tbody>
</table>
</details>
))}
</td>
</tr>
)
Expand Down
14 changes: 0 additions & 14 deletions components/rest/CodeBlock.module.scss

This file was deleted.

49 changes: 0 additions & 49 deletions components/rest/CodeBlock.tsx

This file was deleted.

Loading

0 comments on commit 01639a8

Please sign in to comment.