-
-
Notifications
You must be signed in to change notification settings - Fork 521
Expand file tree
/
Copy pathgithub.js
More file actions
40 lines (36 loc) · 905 Bytes
/
github.js
File metadata and controls
40 lines (36 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { getFallbackData } from './prerender-data.jsx';
/**
* Throw if the response status is in the error range
* @param {Response} r
*/
function checkStatus(r) {
if (!r.ok) {
throw new Error(`${r.status}: Request failed for '${r.url}'`);
}
return r;
}
const baseUrl = '/.netlify/functions/';
export const fetchOrganizationRepos = org =>
fetch(`${baseUrl}repos?org=${org}`, {
credentials: 'include',
mode: 'no-cors',
priority: 'low'
})
.then(checkStatus)
.then(r => r.json())
.catch(() => getFallbackData().preactOrgRepos);
export const fetchRelease = repo =>
fetch(`${baseUrl}release?repo=${repo}`, {
credentials: 'include',
mode: 'no-cors',
priority: 'low'
})
.then(checkStatus)
.then(r => r.json())
.catch(() => {
const fallbackData = getFallbackData();
return {
version: fallbackData.preactVersion,
url: fallbackData.preactReleaseUrl
};
});