Skip to content

Commit 219638d

Browse files
authored
Fix Management Console API code samples (github#30455)
1 parent cefc49b commit 219638d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

components/lib/get-rest-code-samples.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ export function getShellExample(operation: Operation, codeSample: CodeSample) {
4343
}
4444
}
4545

46+
let authHeader = '-H "Authorization: Bearer <YOUR-TOKEN>"'
47+
if (operation.subcategory === 'management-console') {
48+
authHeader = '-u "api_key:your-password"'
49+
}
50+
4651
const args = [
4752
operation.verb !== 'get' && `-X ${operation.verb.toUpperCase()}`,
48-
`-H "Accept: ${defaultAcceptHeader}" \\ \n -H "Authorization: Bearer <YOUR-TOKEN>"`,
53+
`-H "Accept: ${defaultAcceptHeader}" \\ \n ${authHeader}`,
4954
`${operation.serverUrl}${requestPath}`,
5055
requestBodyParams,
5156
].filter(Boolean)

components/rest/RestCodeSamples.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ export function RestCodeSamples({ operation, slug }: Props) {
6060
}))
6161

6262
// Menu options for the language selector
63-
const languageSelectOptions: LanguageOptionT[] = [
64-
{ key: CURLKEY, text: 'cURL' },
65-
{ key: JSKEY, text: 'JavaScript' },
66-
]
67-
// Not all examples support the GH CLI language option. If any of
68-
// the examples don't support it, we don't show GH CLI as an option.
69-
if (!languageExamples.some((example) => example.ghcli === undefined)) {
70-
languageSelectOptions.push({ key: GHCLIKEY, text: 'GitHub CLI' })
63+
const languageSelectOptions: LanguageOptionT[] = [{ key: CURLKEY, text: 'cURL' }]
64+
65+
// Management Console operations are not supported by Octokit
66+
if (operation.subcategory !== 'management-console') {
67+
languageSelectOptions.push({ key: JSKEY, text: 'JavaScript' })
68+
69+
// Not all examples support the GH CLI language option. If any of
70+
// the examples don't support it, we don't show GH CLI as an option.
71+
if (!languageExamples.some((example) => example.ghcli === undefined)) {
72+
languageSelectOptions.push({ key: GHCLIKEY, text: 'GitHub CLI' })
73+
}
7174
}
7275

7376
// Menu options for the example selector

0 commit comments

Comments
 (0)