-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.js
39 lines (38 loc) · 1.13 KB
/
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
31
32
33
34
35
36
37
38
39
export async function createRepository(
repoName,
repoDescription,
isPrivate,
authToken
) {
try {
const response = await fetch(`https://api.github.com/user/repos`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({
name: repoName,
description: repoDescription,
private: isPrivate,
auto_init: true,
gitignore_template: "Node",
license_template: "mit",
}),
});
if (response.ok) {
const data = await response.json();
console.log(`Repository ${repoName} created successfully.`);
console.log(`URL: ${data.html_url}`);
return data.clone_url;
} else {
const errorData = await response.json();
console.error(`Error creating repository: ${errorData.message}`);
console.error(`Status code: ${response.status}`);
console.error(`Error details: ${JSON.stringify(errorData.errors)}`);
}
} catch (error) {
console.error(`Error creating repository: ${error.message}`);
console.error(`Error details: error`);
}
}