-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
43 lines (40 loc) · 1.63 KB
/
Copy pathgithub.js
File metadata and controls
43 lines (40 loc) · 1.63 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
'use strict';
// GitHub API communication via background service worker
async function listRepoFiles() {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
{ type: 'GITHUB_LIST_FILES', config: githubConfig },
(response) => {
if (chrome.runtime.lastError) reject(new Error(chrome.runtime.lastError.message));
else if (response.success) resolve(response.data);
else reject(new Error(response.error));
}
);
});
}
async function fetchFromGitHub(filePath) {
const configWithPath = { ...githubConfig, filePath: filePath || resolvedFilePath };
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
{ type: 'GITHUB_FETCH', config: configWithPath },
(response) => {
if (chrome.runtime.lastError) reject(new Error(chrome.runtime.lastError.message));
else if (response.success) resolve(response.data);
else reject(new Error(response.error));
}
);
});
}
async function commitToGitHub(content, sha) {
const configWithPath = { ...githubConfig, filePath: resolvedFilePath };
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
{ type: 'GITHUB_COMMIT', config: configWithPath, content, sha },
(response) => {
if (chrome.runtime.lastError) reject(new Error(chrome.runtime.lastError.message));
else if (response.success) resolve(response.data);
else reject(new Error(response.error));
}
);
});
}