Skip to content

Commit

Permalink
Fix Management Console API code samples (github#30455)
Browse files Browse the repository at this point in the history
  • Loading branch information
manue1 authored Sep 6, 2022
1 parent cefc49b commit 219638d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 6 additions & 1 deletion components/lib/get-rest-code-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ export function getShellExample(operation: Operation, codeSample: CodeSample) {
}
}

let authHeader = '-H "Authorization: Bearer <YOUR-TOKEN>"'
if (operation.subcategory === 'management-console') {
authHeader = '-u "api_key:your-password"'
}

const args = [
operation.verb !== 'get' && `-X ${operation.verb.toUpperCase()}`,
`-H "Accept: ${defaultAcceptHeader}" \\ \n -H "Authorization: Bearer <YOUR-TOKEN>"`,
`-H "Accept: ${defaultAcceptHeader}" \\ \n ${authHeader}`,
`${operation.serverUrl}${requestPath}`,
requestBodyParams,
].filter(Boolean)
Expand Down
19 changes: 11 additions & 8 deletions components/rest/RestCodeSamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ export function RestCodeSamples({ operation, slug }: Props) {
}))

// Menu options for the language selector
const languageSelectOptions: LanguageOptionT[] = [
{ key: CURLKEY, text: 'cURL' },
{ key: JSKEY, text: 'JavaScript' },
]
// Not all examples support the GH CLI language option. If any of
// the examples don't support it, we don't show GH CLI as an option.
if (!languageExamples.some((example) => example.ghcli === undefined)) {
languageSelectOptions.push({ key: GHCLIKEY, text: 'GitHub CLI' })
const languageSelectOptions: LanguageOptionT[] = [{ key: CURLKEY, text: 'cURL' }]

// Management Console operations are not supported by Octokit
if (operation.subcategory !== 'management-console') {
languageSelectOptions.push({ key: JSKEY, text: 'JavaScript' })

// Not all examples support the GH CLI language option. If any of
// the examples don't support it, we don't show GH CLI as an option.
if (!languageExamples.some((example) => example.ghcli === undefined)) {
languageSelectOptions.push({ key: GHCLIKEY, text: 'GitHub CLI' })
}
}

// Menu options for the example selector
Expand Down

0 comments on commit 219638d

Please sign in to comment.