-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
30 lines (24 loc) · 872 Bytes
/
github.js
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
const { GITHUB_TOKEN } = process.env;
const baseURL = 'https://api.github.com';
const headers = {
Authorization: `token ${GITHUB_TOKEN}`,
Accept: 'application/vnd.github.v3+json'
};
const createRepositoryURL = (user, repo) => `git@github.com:${user}/${repo}.git`;
const createRepository = endpoint => (options = {}) => fetch(endpoint, {
body: JSON.stringify(options),
headers,
method: 'POST'
});
const createUserRepository = createRepository(`${baseURL}/user/repos`);
const createOrganizationRepository = organization => createRepository(`${baseURL}/orgs/${organization}/repos`);
const deleteRepository = owner => repository => fetch(`${baseURL}/repos/${owner}/${repository}`, {
headers,
method: 'DELETE'
});
module.exports = {
createRepositoryURL,
createUserRepository,
createOrganizationRepository,
deleteRepository,
};