Skip to content

Commit

Permalink
fix endpoints-available-for-github-apps page (#15933)
Browse files Browse the repository at this point in the history
* fix endpoints-available-for-github-apps page

* lint
  • Loading branch information
zeke authored Oct 8, 2020
1 parent e90316e commit 03e728f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ versions:

You must use an installation access token to access endpoints using your {% data variables.product.prodname_github_app %}. For more information, see "[Authenticating with {% data variables.product.prodname_github_apps %}](/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation)."

{% for thing in rest.operationsEnabledForApps[currentVersion] %}
{% for thing in rest.operationsEnabledForGitHubApps[currentVersion] %}
{% assign category = thing[0] %}
{% assign operations = thing[1] %}
{% if operations.size > 0 %}
Expand Down
17 changes: 8 additions & 9 deletions lib/rest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { chain, get, union, flatten, groupBy } = require('lodash')
const { supported } = require('./enterprise-server-releases')
const operations = require('@github/rest-api-operations')
// TODO need to update this to the new versions in coordination with openAPI
const { oldVersions } = require('./old-versions-utils')
const allVersions = oldVersions
const { getOldVersionFromNewVersion } = require('./old-versions-utils')
const allVersions = Object.keys(require('./all-versions'))

// This list is generated for use in the tests,
// so we can verify that the names of the markdown files
Expand All @@ -18,16 +17,16 @@ const categories = union(dotcomCategories, enterpriseCategories)

// Attach convenience properties to each operation that can't easily be created in Liquid
allVersions.forEach(currentVersion => {
operations[currentVersion].forEach(operation => {
operations[getOldVersionFromNewVersion(currentVersion)].forEach(operation => {
operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required)
})
})

// This is a collection of operations that have `enabledForApps = true`
// This is a collection of operations that have `enabledForGitHubApps = true`
// It's grouped by resource title to make rendering easier
const operationsEnabledForApps = allVersions.reduce((acc, currentVersion) => {
acc[currentVersion] = chain(operations[currentVersion] || [])
.filter(operation => operation['x-github'].enabledForApps)
const operationsEnabledForGitHubApps = allVersions.reduce((acc, currentVersion) => {
acc[currentVersion] = chain(operations[getOldVersionFromNewVersion(currentVersion)] || [])
.filter(operation => operation['x-github'].enabledForGitHubApps)
.orderBy('category')
.value()
acc[currentVersion] = groupBy(acc[currentVersion], 'category')
Expand All @@ -37,5 +36,5 @@ const operationsEnabledForApps = allVersions.reduce((acc, currentVersion) => {
module.exports = {
categories,
operations,
operationsEnabledForApps
operationsEnabledForGitHubApps
}
6 changes: 6 additions & 0 deletions tests/rendering/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ describe('REST references docs', () => {
expect(operation.description).toContain('GitHub Enterprise')
})

test('loads operations enabled for GitHub Apps', async () => {
const operations = await getJSON('/en/free-pro-team@latest/rest/overview/endpoints-available-for-github-apps?json=rest.operationsEnabledForGitHubApps')
expect(operations['free-pro-team@latest'].actions.length).toBeGreaterThan(0)
expect(operations['enterprise-server@2.22'].actions.length).toBeGreaterThan(0)
})

test('no wrongly detected AppleScript syntax highlighting in schema data', async () => {
const { operations } = require('../../lib/rest')
expect(JSON.stringify(operations).includes('hljs language-applescript')).toBe(false)
Expand Down

0 comments on commit 03e728f

Please sign in to comment.