Skip to content

Commit 693fb35

Browse files
authored
links on /rest/overview/endpoints (#25771)
* links on /rest/overview/endpoints-available-for-github-apps * tests * remove unused code
1 parent 8f39ff6 commit 693fb35

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

content/rest/overview/endpoints-available-for-github-apps.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,4 @@ topics:
1414
shortTitle: GitHub App-enabled endpoints
1515
---
1616

17-
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)."
18-
19-
{% for thing in rest.operationsEnabledForGitHubApps[currentVersion] %}
20-
{% assign category = thing[0] %}
21-
{% assign operations = thing[1] %}
22-
{% if operations.size > 0 %}
23-
<h3 id="{{category}}">
24-
<a href="#{{category}}">{{ category }}</a>
25-
</h3>
26-
<ul>
27-
{% for operation in operations %}
28-
<li><a href="/{{currentLanguage}}/rest/reference/{{operation.category}}#{{operation.slug}}"><code><span style="text-transform: uppercase">{{operation.verb}}</span> {{operation.requestPath}}</code></a></li>
29-
{% endfor %}
30-
</ul>
31-
{% endif %}
32-
{% endfor %}
17+
**The content of this page is rendered as a NextJS page component.**

pages/[versionId]/rest/overview/endpoints-available-for-github-apps.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { GetServerSideProps } from 'next'
2+
import { useRouter } from 'next/router'
23
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
34
import {
45
getArticleContextFromRequest,
56
ArticleContextT,
67
ArticleContext,
78
} from 'components/context/ArticleContext'
89
import { ArticlePage } from 'components/article/ArticlePage'
10+
import { Link } from 'components/Link'
911
import { getEnabledForApps } from 'lib/rest/index.js'
1012

1113
type OperationT = {
@@ -27,31 +29,27 @@ let enabledForApps: AppDataT | null = null
2729
type Props = {
2830
mainContext: MainContextT
2931
enabledForApps: EnabledAppCategoryT
30-
userLanguage: string
3132
articleContext: ArticleContextT
3233
}
3334

34-
export default function Category({
35-
mainContext,
36-
enabledForApps,
37-
userLanguage,
38-
articleContext,
39-
}: Props) {
40-
const content = Object.keys(enabledForApps).map((category: string, index: Number) => (
41-
<div key={`enabledAppCategory-${index}`}>
42-
{enabledForApps[category].length > 0 ? (
35+
export default function Category({ mainContext, enabledForApps, articleContext }: Props) {
36+
const { locale } = useRouter()
37+
38+
const content = Object.entries(enabledForApps).map(([category, operations]) => (
39+
<div key={`enabledAppCategory-${category}`}>
40+
{operations.length > 0 && (
4341
<h3 id={category}>
44-
<a href={category}>{category}</a>
42+
<Link href={`/${locale}/rest/reference/${category}`}>{category}</Link>
4543
</h3>
46-
) : null}
44+
)}
4745
<ul>
48-
{enabledForApps[category].map((operation: OperationT, index: Number) => (
49-
<li key={`enabledAppOperation-${index}`}>
50-
<a href={`${userLanguage}/rest/reference/${category}#${operation.slug}`}>
46+
{operations.map((operation) => (
47+
<li key={`enabledAppOperation-${operation.slug}`}>
48+
<Link href={`/${locale}/rest/reference/${category}#${operation.slug}`}>
5149
<code>
5250
<span className="text-uppercase">{operation.verb}</span> {operation.requestPath}
5351
</code>
54-
</a>
52+
</Link>
5553
</li>
5654
))}
5755
</ul>
@@ -72,7 +70,6 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
7270
const res = context.res as object
7371
const currentVersion = context.query.versionId as string
7472
const mainContext = getMainContext(req, res)
75-
const userLanguage = context.locale || ''
7673

7774
if (!enabledForApps) {
7875
enabledForApps = (await getEnabledForApps()) as AppDataT
@@ -82,7 +79,6 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
8279
props: {
8380
mainContext,
8481
enabledForApps: enabledForApps[currentVersion],
85-
userLanguage,
8682
articleContext: getArticleContextFromRequest(req),
8783
},
8884
}

tests/rendering/rest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ describe('REST references docs', () => {
7070
const schemaSlugs = []
7171
// using the static file, generate the expected slug for each operation
7272
for (const [key, value] of Object.entries(enableForApps[version])) {
73-
schemaSlugs.push(...value.map((item) => `en/rest/reference/${key}#${item.slug}`))
73+
schemaSlugs.push(...value.map((item) => `/en/rest/reference/${key}#${item.slug}`))
7474
}
7575
// get all of the href attributes in the anchor tags
7676
const $ = await getDOM(`/en/${version}/rest/overview/endpoints-available-for-github-apps`)
77-
const domH3Ids = $('a')
77+
const domH3Ids = $('#article-contents a')
7878
.map((i, a) => $(a).attr('href'))
7979
.get()
8080
expect(schemaSlugs.every((slug) => domH3Ids.includes(slug))).toBe(true)

0 commit comments

Comments
 (0)