-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
53 lines (48 loc) · 1.68 KB
/
index.html
File metadata and controls
53 lines (48 loc) · 1.68 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html>
<head>
<title>Git File Creator</title>
</head>
<body>
<h1>Create a new file in a Git repository</h1>
<form id="create-file-form">
<label for="file-name">File Name:</label>
<input type="text" id="file-name" name="file-name" required>
<br>
<label for="file-contents">File Contents:</label>
<textarea id="file-contents" name="file-contents" required></textarea>
<br>
<button type="submit">Create File</button>
</form>
<script>
const form = document.querySelector('#create-file-form');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const fileName = document.querySelector('#file-name').value;
const fileContents = document.querySelector('#file-contents').value;
// Replace these values with your own access token and repository information
const accessToken = 'your_access_token';
const repository = 'your_user_name/your_repository';
// Set up the API request to create a new file
const url = `https://api.github.com/repos/${repository}/contents/${fileName}`;
const data = {
message: 'Creating new file',
content: btoa(fileContents),
};
// Send the API request
const response = await fetch(url, {
method: 'PUT',
headers: {
Authorization: `token ${accessToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
// Check the API response for success or failure
if (!response.ok) {
// Handle error
}
});
</script>
</body>
</html>