opencode-studio-server 1.21.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +60 -41
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1095,47 +1095,66 @@ async function getGitHubUser(token) {
|
|
|
1095
1095
|
return await response.json();
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
|
-
async function ensureGitHubRepo(token, repoName) {
|
|
1099
|
-
const owner = repoName.split('/')
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
const err = await createRes.text();
|
|
1133
|
-
throw new Error(`Failed to create repo: ${err}`);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
const err = await response.text();
|
|
1137
|
-
throw new Error(`Failed to check repo: ${err}`);
|
|
1138
|
-
}
|
|
1098
|
+
async function ensureGitHubRepo(token, repoName) {
|
|
1099
|
+
const [owner, repo] = repoName.split('/');
|
|
1100
|
+
|
|
1101
|
+
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
1102
|
+
headers: { 'Authorization': `Bearer ${token}` }
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
if (response.ok) {
|
|
1106
|
+
const data = await response.json();
|
|
1107
|
+
if (!data.default_branch) {
|
|
1108
|
+
await bootstrapEmptyRepo(token, owner, repo);
|
|
1109
|
+
}
|
|
1110
|
+
return data;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
if (response.status === 404) {
|
|
1114
|
+
const createRes = await fetch(`https://api.github.com/user/repos`, {
|
|
1115
|
+
method: 'POST',
|
|
1116
|
+
headers: {
|
|
1117
|
+
'Authorization': `Bearer ${token}`,
|
|
1118
|
+
'Content-Type': 'application/json'
|
|
1119
|
+
},
|
|
1120
|
+
body: JSON.stringify({
|
|
1121
|
+
name: repo,
|
|
1122
|
+
private: true,
|
|
1123
|
+
description: 'OpenCode Studio backup',
|
|
1124
|
+
auto_init: true
|
|
1125
|
+
})
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
if (createRes.ok) {
|
|
1129
|
+
return await createRes.json();
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
const err = await createRes.text();
|
|
1133
|
+
throw new Error(`Failed to create repo: ${err}`);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
const err = await response.text();
|
|
1137
|
+
throw new Error(`Failed to check repo: ${err}`);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
async function bootstrapEmptyRepo(token, owner, repo) {
|
|
1141
|
+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/contents/README.md`, {
|
|
1142
|
+
method: 'PUT',
|
|
1143
|
+
headers: {
|
|
1144
|
+
'Authorization': `Bearer ${token}`,
|
|
1145
|
+
'Content-Type': 'application/json'
|
|
1146
|
+
},
|
|
1147
|
+
body: JSON.stringify({
|
|
1148
|
+
message: 'Initial commit',
|
|
1149
|
+
content: Buffer.from('# OpenCode Studio Backup\n').toString('base64')
|
|
1150
|
+
})
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
if (!res.ok) {
|
|
1154
|
+
const err = await res.text();
|
|
1155
|
+
throw new Error(`Failed to bootstrap repo: ${err}`);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1139
1158
|
|
|
1140
1159
|
function collectBlobs(rootDir, basePath = '', blobs = []) {
|
|
1141
1160
|
const dir = basePath || rootDir;
|