Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ef82435
check repo
sarahs Dec 7, 2020
797911d
make Early Access banner more prominent
sarahs Dec 7, 2020
dc38acd
support custom Early Access breadcrumbs
sarahs Dec 7, 2020
2e8b8d3
test Early Access breadcrumbs
sarahs Dec 7, 2020
38659b3
return an empty breadcrumbs object on the landing page
sarahs Dec 8, 2020
c55080e
updates for refactored req.context.pages
sarahs Dec 8, 2020
4b1988d
Merge branch 'main' into skip-early-access-tests
sarahs Dec 8, 2020
e51842b
Merge branch 'main' into early-access-tweaks
sarahs Dec 8, 2020
117bd5f
add new conditional test runs helper
sarahs Dec 8, 2020
a161a59
lint
sarahs Dec 8, 2020
5a07447
add comment clarifying purpose of separate middleware
sarahs Dec 8, 2020
5c7a675
Merge branch 'early-access-tweaks' of github.com:github/docs-internal…
sarahs Dec 8, 2020
cfc4f67
Merge branch 'main' into early-access-tweaks
sarahs Dec 10, 2020
41a4732
Merge branch 'main' into early-access-tweaks
sarahs Dec 10, 2020
5b82f5e
Merge branch 'main' into skip-early-access-tests
sarahs Dec 10, 2020
a97698f
Merge pull request #16773 from github/skip-early-access-tests
sarahs Dec 10, 2020
82ad16c
Merge branch 'main' into early-access-tweaks
sarahs Dec 10, 2020
712dd75
Confirm w/ internal GitHub team members when they post to docs (#16804)
chiedo Dec 10, 2020
dd3fabb
Merge branch 'main' into early-access-tweaks
sarahs Dec 10, 2020
603ad36
Merge pull request #16783 from github/early-access-tweaks
sarahs Dec 10, 2020
cdf6695
Branch was updated using the 'autoupdate branch' Actions workflow.
Octomerger Dec 10, 2020
b7739ec
repo sync
Octomerger Dec 10, 2020
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
72 changes: 72 additions & 0 deletions .github/workflows/confirm-internal-staff-work-in-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Confirm internal staff meant to post in public

on:
issues:
types:
- opened
- reopened
- transferred
pull_request_target:
types:
- opened
- reopened

jobs:
check-team-membership:
runs-on: ubuntu-latest
continue-on-error: true
if: github.repository == 'github/docs'
steps:
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
with:
github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
script: |
// Only perform this action with GitHub employees
try {
await github.teams.getMembershipForUserInOrg({
org: 'github',
team_slug: 'employees',
username: context.payload.sender.login,
});
} catch(err) {
// An error will be thrown if the user is not a GitHub employee
// If a user is not a GitHub employee, we should stop here and
// Not send a notification
return
}

// Don't perform this action with Docs team members
try {
await github.teams.getMembershipForUserInOrg({
org: 'github',
team_slug: 'docs',
username: context.payload.sender.login,
});
// If the user is a Docs team member, we should stop here and not send
// a notification
return
} catch(err) {
// An error will be thrown if the user is not a Docs team member
// If a user is not a Docs team member we should continue and send
// the notification
}

const issueNo = context.number || context.issue.number

// Create an issue in our private repo
await github.issues.create({
owner: 'github',
repo: 'docs-internal',
title: `@${context.payload.sender.login} confirm that \#${issueNo} should be in the public github/docs repo`,
body: `@${context.payload.sender.login} opened https://github.com/github/docs/issues/${issueNo} publicly in the github/docs repo, instead of the private github/docs-internal repo.\n\n@${context.payload.sender.login}, please confirm that this belongs in the public repo and that no sensitive information was disclosed by commenting below and closing the issue.\n\nIf this was not intentional and sensitive information was shared, please delete https://github.com/github/docs/issues/${issueNo} and notify us in the \#docs-open-source channel.\n\nThanks! \n\n/cc @github/docs @github/docs-engineering`
});

throw new Error('A Hubber opened an issue on the public github/docs repo');

- name: Send Slack notification if a GitHub employee who isn't on the docs team opens an issue in public
if: ${{ failure() && github.repository == 'github/docs' }}
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
with:
channel: ${{ secrets.DOCS_OPEN_SOURCE_SLACK_CHANNEL_ID }}
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
text: <@${{github.actor}}> opened https://github.com/github/docs/issues/${{ github.event.number || github.event.issue.number }} publicly on the github/docs repo instead of the private github/docs-internal repo. They have been notified via a new issue in the github/docs-internal repo to confirm this was intentional.
2 changes: 1 addition & 1 deletion data/ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ header:
still in translation. For the most up-to-date and accurate information,
please visit our
<a id="to-english-doc" href="/en">English documentation</a>.
early_access: 👋 This page contains content about an early access feature. Please do not share this URL publicly.
early_access: 📣 Please <b>do not share</b> this URL publicly. This page contains content about an early access feature.
search:
need_help: Need help?
placeholder: Search topics, products...
Expand Down
4 changes: 2 additions & 2 deletions includes/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="breadcrumbs f5" aria-label="Breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if page.hidden %}
<span class="d-inline-block">{{breadcrumb[1].title}}</span>
{% if breadcrumb[1].href == '' %}
<span>{{breadcrumb[1].title}}</span>
{% else %}
<a title="{{ breadcrumb[0]}}: {{breadcrumb[1].title}}" href="/{{currentLanguage}}{{breadcrumb[1].href}}" class="d-inline-block {% if breadcrumb[1].href == currentPathWithoutLanguage %}text-gray-light{% endif %}">
{{breadcrumb[1].title}}</a>
Expand Down
2 changes: 1 addition & 1 deletion includes/header-notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{% endif %}

{% if early_access_notification_type %}
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 early_access">
<div class="header-notifications text-center f5 bg-red-1 text-gray-dark py-4 px-6 early_access">
{{ early_access_notification }}
</div>
{% endif %}
5 changes: 4 additions & 1 deletion middleware/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const path = require('path')
const { getPathWithoutLanguage } = require('../lib/path-utils')

module.exports = async (req, res, next) => {
if (!req.context.page) return next()
if (req.context.page.hidden) return next()

req.context.breadcrumbs = {}

if (!req.context.page) return next()
// Return an empty object on the landing page
if (req.context.page.relativePath === 'index.md') return next()

const rawPath = getPathWithoutLanguage(req.path)
Expand Down
6 changes: 4 additions & 2 deletions middleware/contextualizers/early-access-links.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { uniq } = require('lodash')

module.exports = function earlyAccessContext (req, res, next) {
if (process.env.NODE_ENV === 'production') {
return next(404)
}

// Get a list of all hidden pages per version
const earlyAccessPageLinks = req.context.pages
const earlyAccessPageLinks = uniq(Object.values(req.context.pages)
.filter(page => page.hidden)
// Do not include early access landing page
.filter(page => page.relativePath !== 'early-access/index.md')
// Create Markdown links
.map(page => {
return page.permalinks.map(permalink => `- [${permalink.title}](${permalink.href})`)
})
.flat()
.flat())
// Get links for the current version
.filter(link => link.includes(req.context.currentVersion))
.sort()
Expand Down
69 changes: 69 additions & 0 deletions middleware/early-access-breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const path = require('path')
const { getPathWithoutLanguage } = require('../lib/path-utils')

// Early Access content doesn't conform to the same structure as other products, so we
// can't derive breadcrumbs from the siteTree in the same way. Hence, this separate middleware.
module.exports = async (req, res, next) => {
if (!req.context.page) return next()
if (!req.context.page.hidden) return next()

req.context.breadcrumbs = {}

const earlyAccessProduct = req.context.siteTree[req.language][req.context.currentVersion].products[req.context.currentProduct]

req.context.breadcrumbs.earlyAccessProduct = {
href: '', // no link for the EA product breadcrumb
title: earlyAccessProduct.title
}

const rawPath = getPathWithoutLanguage(req.path)
const pathParts = rawPath.split('/')

// drop first '/'
pathParts.shift()

// drop the version and early-accesss segments so pathParts now starts with /product
pathParts.shift()
pathParts.shift()

// Early Access products do not require an index.md, so look for a matching public product
const product = req.context.siteTree[req.language][req.context.currentVersion].products[pathParts[0]]

if (!product) return next()

req.context.breadcrumbs.product = {
href: '', // no link for the EA product breadcrumbs
title: product.title
}

if (!pathParts[1]) return next()

// get Early Access category path
// e.g., `enforcing-best-practices-with-github-policies` in /free-pro-team@latest/early-access/github/enforcing-best-practices-with-github-policies
const categoryPath = path.posix.join('/', req.context.currentVersion, 'early-access', pathParts[0], pathParts[1])
const category = req.context.pages[path.posix.join('/en', categoryPath)]

if (!category) return next()

req.context.breadcrumbs.category = {
href: categoryPath, // do include a link for EA category breadcrumbs
title: category.shortTitle || category.title
}

if (!pathParts[2]) return next()

// for Early Access purposes, we don't need to differentiate between map topics and articles breadcrumbs
const mapTopicOrArticlePath = path.posix.join(categoryPath, pathParts[2])
const mapTopicOrArticle = req.context.pages[path.posix.join('/en', mapTopicOrArticlePath)]

if (!mapTopicOrArticle) return next()

const mapTopicOrArticleTitle = await mapTopicOrArticle.renderProp('shortTitle', req.context, { textOnly: true, encodeEntities: true })

req.context.breadcrumbs.article = {
href: mapTopicOrArticlePath, // do include a link for EA map topic/article breadcrumbs
title: mapTopicOrArticleTitle
}

return next()
}
1 change: 1 addition & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = function (app) {
app.use(require('./contextualizers/rest'))
app.use(require('./contextualizers/webhooks'))
app.use(require('./breadcrumbs'))
app.use(require('./early-access-breadcrumbs'))
app.use(require('./dev-toc'))
app.use(require('./featured-links'))

Expand Down
2 changes: 1 addition & 1 deletion stylesheets/article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
/* Breadcrumbs
------------------------------------------------------------------------------*/

.breadcrumbs a:not(:last-child)::after{
.breadcrumbs a:not(:last-child)::after, .breadcrumbs span:not(:last-child)::after {
content: '/';
color: $gray-400;
padding-right: $spacer-1;
Expand Down
9 changes: 9 additions & 0 deletions tests/helpers/conditional-runs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const runningActionsOnInternalRepo = process.env.GITHUB_ACTIONS === 'true' && process.env.GITHUB_REPOSITORY === 'github/docs-internal'

const testViaActionsOnly = runningActionsOnInternalRepo ? test : test.skip
const describeViaActionsOnly = runningActionsOnInternalRepo ? describe : describe.skip

module.exports = {
testViaActionsOnly,
describeViaActionsOnly
}
23 changes: 23 additions & 0 deletions tests/rendering/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { getDOM, getJSON } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

const describeInternalOnly = process.env.GITHUB_REPOSITORY === 'github/docs-internal' ? describe : describe.skip

describe('breadcrumbs', () => {
jest.setTimeout(300 * 1000)

Expand Down Expand Up @@ -60,6 +62,27 @@ describe('breadcrumbs', () => {
})
})

describeInternalOnly('early access rendering', () => {
test('top-level product pages have breadcrumbs', async () => {
const $ = await getDOM('/early-access/github/articles/using-gist-playground')
expect($('.breadcrumbs')).toHaveLength(1)
})

test('early access article pages have breadcrumbs with product, category, and article', async () => {
const $ = await getDOM('/early-access/github/enforcing-best-practices-with-github-policies/about-github-policies')
const $breadcrumbSpans = $('.breadcrumbs span')
const $breadcrumbLinks = $('.breadcrumbs a')

expect($breadcrumbSpans).toHaveLength(2)
expect($breadcrumbLinks).toHaveLength(2)
expect($breadcrumbSpans.eq(0).text()).toBe('Early Access documentation')
expect($breadcrumbSpans.eq(1).text()).toBe('GitHub.com')
expect($breadcrumbLinks.eq(0).attr('title')).toBe('category: Enforcing best practices with GitHub Policies')
expect($breadcrumbLinks.eq(1).attr('title')).toBe('article: About GitHub Policies')
expect($breadcrumbLinks.eq(1).hasClass('text-gray-light')).toBe(true)
})
})

describe('context.breadcrumbs object', () => {
test('works on product index pages', async () => {
const breadcrumbs = await getJSON('/en/github?json=breadcrumbs')
Expand Down
3 changes: 2 additions & 1 deletion tests/rendering/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const lodash = require('lodash')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { get, getDOM, head } = require('../helpers/supertest')
const { describeViaActionsOnly } = require('../helpers/conditional-runs')
const path = require('path')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
const { loadPages } = require('../../lib/pages')
Expand Down Expand Up @@ -356,7 +357,7 @@ describe('server', () => {
})
})

describe.skip('Early Access articles', () => {
describeViaActionsOnly('Early Access articles', () => {
let hiddenPageHrefs, hiddenPages

beforeAll(async (done) => {
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/early-access.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const fs = require('fs').promises
const path = require('path')

const { GITHUB_ACTIONS, GITHUB_REPOSITORY } = process.env
const runningActionsOnInternalRepo = GITHUB_ACTIONS === 'true' && GITHUB_REPOSITORY === 'github/docs-internal'
const testViaActionsOnly = runningActionsOnInternalRepo ? test : test.skip
const { testViaActionsOnly } = require('../helpers/conditional-runs')

describe('cloning early-access', () => {
testViaActionsOnly('the content directory exists', async () => {
Expand Down