Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 6d5661a

Browse files
committed
fix(github-api): add default header option for fetch repo info
1 parent e5ce85b commit 6d5661a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

services/github_api/client.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ const jsonOptions = {
2424
// graphql client
2525
export const graphqlClient = makeGithubExplore(graphqlEndpoint, token)
2626

27-
export const restClient = (api, fmt = 'json') => {
28-
if (fmt === 'json') {
29-
return fetch(`${api}`, jsonOptions).then(r => r.json())
27+
export const restClient = (api, fmt = 'default') => {
28+
switch (fmt) {
29+
case 'json': {
30+
return fetch(`${api}`, jsonOptions).then(r => r.json())
31+
}
32+
case 'raw': {
33+
return fetch(`${api}`, rawOptions).then(r => r.text())
34+
}
35+
default: {
36+
return fetch(`${api}`).then(r => r.text())
37+
}
3038
}
31-
32-
return fetch(`${api}`, rawOptions).then(r => r.text())
3339
}

services/github_api/repo_search.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ const contributorsQuery = (owner, name) => {
1414
const path = 'contributors?page=1&per_page=8'
1515
const api = `${restEndpoint}/repos/${owner}/${name}/${path}`
1616

17-
return restClient(`${api}`)
17+
return restClient(`${api}`, 'json')
1818
}
1919

2020
const readmeQuery = (owner, name) => {
2121
return restClient(`${restEndpoint}/repos/${owner}/${name}/readme`, 'raw')
2222
}
2323

24+
/**
25+
* @param {string} owner: repo owner
26+
* @param {string} name: repo name
27+
*
28+
* NOTE: use readmeQuery for readme instead of graphql is readme
29+
* has a lots of ext, like readme.md | readme.markdown ...
30+
*
31+
*/
2432
export const searchRepoPromise = (owner, name) =>
2533
Promise.all([
2634
timeout(baseInfoQuery(owner, name), TIMEOUT_SEC),

0 commit comments

Comments
 (0)