From a02ae16a7c6baa7d98b68a4ce7d66b136a032d61 Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Wed, 10 May 2023 11:49:59 -0700 Subject: [PATCH 1/2] Move docs engineering reviewer to Action workflow (#36882) Co-authored-by: Peter Bengtsson --- .github/CODEOWNERS | 18 ------------ .github/labeler.yml | 15 ---------- .github/workflows/auto-label-prs.yml | 22 -------------- .../workflows/codeowners-content-strategy.yml | 21 ++++++++++++++ .../workflows/codeowners-docs-engineering.yml | 29 +++++++++++++++++++ 5 files changed, 50 insertions(+), 55 deletions(-) delete mode 100644 .github/labeler.yml delete mode 100644 .github/workflows/auto-label-prs.yml create mode 100644 .github/workflows/codeowners-content-strategy.yml create mode 100644 .github/workflows/codeowners-docs-engineering.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fd63db1fc5..bff0191ecf 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,26 +3,8 @@ # https://docs.github.com/articles/about-codeowners # https://git-scm.com/docs/gitignore -# Engineering -*.js @github/docs-engineering -*.ts @github/docs-engineering -*.tsx @github/docs-engineering -/.github/ @github/docs-engineering -/script/ @github/docs-engineering -/includes/ @github/docs-engineering -Dockerfile @github/docs-engineering -package-lock.json @github/docs-engineering -package.json @github/docs-engineering - # Site Policy /content/site-policy/ @github/site-policy-admins -# Content strategy -/contributing/content-markup-reference.md @github/docs-content-strategy -/contributing/content-style-guide.md @github/docs-content-strategy -/contributing/content-model.md @github/docs-content-strategy -/contributing/content-style-guide.md @github/docs-content-strategy -/contributing/content-templates.md @github/docs-content-strategy - # Requires review of #actions-oidc-integration, docs-engineering/issues/1506 content/actions/deployment/security-hardening-your-deployments/** @github/oidc diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index a885e4a3ab..0000000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,15 +0,0 @@ -engineering: - - lib/* - - lib/**/* - - middleware/* - - middleware/**/* - - tests/* - - tests/**/* - - stylesheets/* - - stylesheets/**/* - - script/* - - script/**/* - - components/* - - components/**/* - - pages/* - - pages/**/* diff --git a/.github/workflows/auto-label-prs.yml b/.github/workflows/auto-label-prs.yml deleted file mode 100644 index a9d08b7186..0000000000 --- a/.github/workflows/auto-label-prs.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Auto label Pull Requests - -# **What it does**: Automatically adds the engineering label when specific files change. -# **Why we have it**: Other automation applies specifically to engineering label issues and pull requests. -# **Who does it impact**: Automation that relies on the engineering label. - -on: - pull_request: - -permissions: - contents: read - pull-requests: write - -jobs: - triage: - if: github.repository == 'github/docs-internal' - runs-on: ubuntu-latest - steps: - # See labeling configuration in the `.github/labeler.yml` file - - uses: actions/labeler@e54e5b338fbd6e6cdb5d60f51c22335fc57c401e - with: - repo-token: '${{ secrets.GITHUB_TOKEN }}' diff --git a/.github/workflows/codeowners-content-strategy.yml b/.github/workflows/codeowners-content-strategy.yml new file mode 100644 index 0000000000..b378f5c41b --- /dev/null +++ b/.github/workflows/codeowners-content-strategy.yml @@ -0,0 +1,21 @@ +name: Codeowners - Content Strategy + +# **What it does**: Automatically add reviewers based on paths, but only for the docs-internal repo. +# **Why we have it**: So we can have reviewers automatically without getting open source notifications. +# **Who does it impact**: Docs team. + +on: + pull_request: + paths: + - '/contributing/content-*.md' + +jobs: + codeowners-content-strategy: + if: ${{ github.repository == 'github/docs-internal' }} + runs-on: ubuntu-latest + steps: + - name: Add Content Strategy as a reviewer + env: + GH_TOKEN: ${{ secrets.DOCS_BOT_FR }} + PR: ${{ github.event.pull_request.html_url }} + run: gh pr edit $PR --add-reviewer github/docs-content-strategy diff --git a/.github/workflows/codeowners-docs-engineering.yml b/.github/workflows/codeowners-docs-engineering.yml new file mode 100644 index 0000000000..f282ba38d5 --- /dev/null +++ b/.github/workflows/codeowners-docs-engineering.yml @@ -0,0 +1,29 @@ +name: Codeowners - Docs Engineering + +# **What it does**: Automatically add reviewers based on paths, but only for the docs-internal repo. +# And sets the 'engineering' label on the PR. +# **Why we have it**: So we can have reviewers automatically without getting open source notifications. +# **Who does it impact**: Docs team. + +on: + pull_request: + paths: + - '**.js' + - '**.ts' + - '**.tsx' + - '**.scss' + - 'src/**' + - '.github/**' + - '**Dockerfile' + - 'package*.json' + +jobs: + codeowners-docs-engineering: + if: ${{ github.repository == 'github/docs-internal' }} + runs-on: ubuntu-latest + steps: + - name: Add Docs Engineering as a reviewer + env: + GH_TOKEN: ${{ secrets.DOCS_BOT_FR }} + PR: ${{ github.event.pull_request.html_url }} + run: gh pr edit $PR --add-reviewer github/docs-engineering --add-label engineering From f806ee701295c3f061cab17ebca7a67ac93685f9 Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Wed, 10 May 2023 11:54:56 -0700 Subject: [PATCH 2/2] Move more files into src/webhooks (#36578) --- middleware/api/index.js | 2 +- next.config.js | 1 + .../webhooks/webhook-events-and-payloads.tsx | 118 +----------------- .../webhooks/components}/Webhook.tsx | 0 .../WebhookPayloadExample.module.scss | 0 .../webhooks/components}/types.ts | 2 +- .../webhooks/middleware}/webhooks.js | 6 +- .../pages/webhook-events-and-payloads.tsx | 115 +++++++++++++++++ 8 files changed, 125 insertions(+), 119 deletions(-) rename {components/webhooks => src/webhooks/components}/Webhook.tsx (100%) rename {components/webhooks => src/webhooks/components}/WebhookPayloadExample.module.scss (100%) rename {components/webhooks => src/webhooks/components}/types.ts (95%) rename {middleware/api => src/webhooks/middleware}/webhooks.js (86%) create mode 100644 src/webhooks/pages/webhook-events-and-payloads.tsx diff --git a/middleware/api/index.js b/middleware/api/index.js index 3a57237b67..553ce0fd49 100644 --- a/middleware/api/index.js +++ b/middleware/api/index.js @@ -5,7 +5,7 @@ import events from '../../src/events/middleware.js' import anchorRedirect from '../../src/rest/api/anchor-redirect.js' import search from '../../src/search/middleware/search.js' import pageInfo from '../../src/pageinfo/middleware.js' -import webhooks from './webhooks.js' +import webhooks from '../../src/webhooks/middleware/webhooks.js' const router = express.Router() diff --git a/next.config.js b/next.config.js index e096412938..79aaf31f98 100644 --- a/next.config.js +++ b/next.config.js @@ -37,6 +37,7 @@ export default { webpack: (config) => { config.experiments = config.experiments || {} config.experiments.topLevelAwait = true + config.resolve.fallback = { fs: false } return config }, diff --git a/pages/[versionId]/webhooks-and-events/webhooks/webhook-events-and-payloads.tsx b/pages/[versionId]/webhooks-and-events/webhooks/webhook-events-and-payloads.tsx index 8e80b9b23e..26ddf96f4a 100644 --- a/pages/[versionId]/webhooks-and-events/webhooks/webhook-events-and-payloads.tsx +++ b/pages/[versionId]/webhooks-and-events/webhooks/webhook-events-and-payloads.tsx @@ -1,114 +1,4 @@ -import { GetServerSideProps } from 'next' -import { useRouter } from 'next/router' -import { useEffect } from 'react' - -import { getInitialPageWebhooks } from 'src/webhooks/lib' -import { getMainContext, MainContext, MainContextT } from 'components/context/MainContext' -import { - getAutomatedPageContextFromRequest, - AutomatedPageContext, - AutomatedPageContextT, -} from 'components/context/AutomatedPageContext' -import { WebhookAction } from 'components/webhooks/types' -import { Webhook } from 'components/webhooks/Webhook' -import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items' -import { AutomatedPage } from 'components/article/AutomatedPage' - -type Props = { - mainContext: MainContextT - automatedPageContext: AutomatedPageContextT - webhooks: WebhookAction[] -} - -export default function WebhooksEventsAndPayloads({ - mainContext, - automatedPageContext, - webhooks, -}: Props) { - const router = useRouter() - const { locale } = router - const content = webhooks.map((webhook: WebhookAction, index) => { - return ( -
- -
- ) - }) - - // When someone clicks on a minitoc hash anchor link on this page, we want to - // remove the type query parameter from the URL because the type won't make - // sense anymore (e.g. ?actionTtype=closed#issues and you click on the fork minitoc - // we don't want the URL to be ?actionType=closed#fork). - useEffect(() => { - const hashChangeHandler = () => { - const { asPath } = router - let [pathRoot, pathQuery = ''] = asPath.split('?') - - if (pathRoot.includes('#')) { - pathRoot = pathRoot.split('#')[0] - } - - // carry over any other query parameters besides `actionType` for the webhook - // action type - if (pathQuery.includes('#')) { - pathQuery = pathQuery.split('#')[0] - } - const params = new URLSearchParams(pathQuery) - params.delete('actionType') - - if (location.hash) { - router.replace( - { pathname: pathRoot, query: params.toString(), hash: location.hash }, - undefined, - { - shallow: true, - locale, - } - ) - } - } - - window.addEventListener('hashchange', hashChangeHandler) - - return () => { - window.removeEventListener('hashchange', hashChangeHandler) - } - }, [locale]) - - return ( - - - {content} - - - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as object - const res = context.res as object - const currentVersion = context.query.versionId as string - const mainContext = await getMainContext(req, res) - const { miniTocItems } = getAutomatedPageContextFromRequest(req) - - // Get data for initial webhooks page (i.e. only 1 action type per webhook and - // no nested parameters) - const webhooks = (await getInitialPageWebhooks(currentVersion)) as WebhookAction[] - - // Build the minitocs for the webhooks page which is based on the webhook - // categories in addition to the Markdown in the webhook-events-and-payloads.md - // content file - const webhooksMiniTocs = await getAutomatedPageMiniTocItems( - webhooks.map((webhook) => webhook.data.category), - context - ) - webhooksMiniTocs && miniTocItems.push(...webhooksMiniTocs) - - return { - props: { - webhooks, - mainContext, - automatedPageContext: getAutomatedPageContextFromRequest(req), - }, - } -} +export { + default, + getServerSideProps, +} from '../../../../src/webhooks/pages/webhook-events-and-payloads' diff --git a/components/webhooks/Webhook.tsx b/src/webhooks/components/Webhook.tsx similarity index 100% rename from components/webhooks/Webhook.tsx rename to src/webhooks/components/Webhook.tsx diff --git a/components/webhooks/WebhookPayloadExample.module.scss b/src/webhooks/components/WebhookPayloadExample.module.scss similarity index 100% rename from components/webhooks/WebhookPayloadExample.module.scss rename to src/webhooks/components/WebhookPayloadExample.module.scss diff --git a/components/webhooks/types.ts b/src/webhooks/components/types.ts similarity index 95% rename from components/webhooks/types.ts rename to src/webhooks/components/types.ts index f898dd0232..553de8427e 100644 --- a/components/webhooks/types.ts +++ b/src/webhooks/components/types.ts @@ -1,4 +1,4 @@ -import { Parameter, StatusCode, CodeSample, BodyParameter } from '../rest/types' +import { Parameter, StatusCode, CodeSample, BodyParameter } from '../../../components/rest/types' export interface WebhookT { actions: string[] diff --git a/middleware/api/webhooks.js b/src/webhooks/middleware/webhooks.js similarity index 86% rename from middleware/api/webhooks.js rename to src/webhooks/middleware/webhooks.js index 1cfa291764..59a280f0cf 100644 --- a/middleware/api/webhooks.js +++ b/src/webhooks/middleware/webhooks.js @@ -1,7 +1,7 @@ import express from 'express' -import { getWebhook } from '../../src/webhooks/lib/index.js' -import { allVersions } from '../../lib/all-versions.js' -import { defaultCacheControl } from '../cache-control.js' +import { getWebhook } from '../lib/index.js' +import { allVersions } from '../../../lib/all-versions.js' +import { defaultCacheControl } from '../../../middleware/cache-control.js' const router = express.Router() diff --git a/src/webhooks/pages/webhook-events-and-payloads.tsx b/src/webhooks/pages/webhook-events-and-payloads.tsx new file mode 100644 index 0000000000..8faba87ac6 --- /dev/null +++ b/src/webhooks/pages/webhook-events-and-payloads.tsx @@ -0,0 +1,115 @@ +import { GetServerSideProps } from 'next' +import { useRouter } from 'next/router' +import { useEffect } from 'react' + +import { getMainContext, MainContext, MainContextT } from 'components/context/MainContext' +import { + getAutomatedPageContextFromRequest, + AutomatedPageContext, + AutomatedPageContextT, +} from 'components/context/AutomatedPageContext' +import { WebhookAction } from 'src/webhooks/components/types' +import { Webhook } from 'src/webhooks/components/Webhook' +import { AutomatedPage } from 'components/article/AutomatedPage' + +type Props = { + mainContext: MainContextT + automatedPageContext: AutomatedPageContextT + webhooks: WebhookAction[] +} + +export default function WebhooksEventsAndPayloads({ + mainContext, + automatedPageContext, + webhooks, +}: Props) { + const router = useRouter() + const { locale } = router + const content = webhooks.map((webhook: WebhookAction, index) => { + return ( +
+ +
+ ) + }) + + // When someone clicks on a minitoc hash anchor link on this page, we want to + // remove the type query parameter from the URL because the type won't make + // sense anymore (e.g. ?actionTtype=closed#issues and you click on the fork minitoc + // we don't want the URL to be ?actionType=closed#fork). + useEffect(() => { + const hashChangeHandler = () => { + const { asPath } = router + let [pathRoot, pathQuery = ''] = asPath.split('?') + + if (pathRoot.includes('#')) { + pathRoot = pathRoot.split('#')[0] + } + + // carry over any other query parameters besides `actionType` for the webhook + // action type + if (pathQuery.includes('#')) { + pathQuery = pathQuery.split('#')[0] + } + const params = new URLSearchParams(pathQuery) + params.delete('actionType') + + if (location.hash) { + router.replace( + { pathname: pathRoot, query: params.toString(), hash: location.hash }, + undefined, + { + shallow: true, + locale, + } + ) + } + } + + window.addEventListener('hashchange', hashChangeHandler) + + return () => { + window.removeEventListener('hashchange', hashChangeHandler) + } + }, [locale]) + + return ( + + + {content} + + + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { getInitialPageWebhooks } = await import('src/webhooks/lib') + const { getAutomatedPageMiniTocItems } = await import('lib/get-mini-toc-items') + + const req = context.req as object + const res = context.res as object + const currentVersion = context.query.versionId as string + const mainContext = await getMainContext(req, res) + const { miniTocItems } = getAutomatedPageContextFromRequest(req) + + // Get data for initial webhooks page (i.e. only 1 action type per webhook and + // no nested parameters) + const webhooks = (await getInitialPageWebhooks(currentVersion)) as WebhookAction[] + + // Build the minitocs for the webhooks page which is based on the webhook + // categories in addition to the Markdown in the webhook-events-and-payloads.md + // content file + const webhooksMiniTocs = await getAutomatedPageMiniTocItems( + webhooks.map((webhook) => webhook.data.category), + context + ) + webhooksMiniTocs && miniTocItems.push(...webhooksMiniTocs) + + return { + props: { + webhooks, + mainContext, + automatedPageContext: getAutomatedPageContextFromRequest(req), + }, + } +}