jsrepo 1.12.2 → 1.12.3
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/dist/index.js +33 -34
- package/package.json +1 -1
- package/src/utils/git-providers.ts +40 -31
package/dist/index.js
CHANGED
|
@@ -1211,8 +1211,20 @@ var get2 = () => {
|
|
|
1211
1211
|
|
|
1212
1212
|
// src/utils/git-providers.ts
|
|
1213
1213
|
var octokit = new Octokit({});
|
|
1214
|
+
var manifestErrorMessage = (info, defaultBranch) => {
|
|
1215
|
+
return Err(
|
|
1216
|
+
`There was an error fetching the \`${color4.bold(OUTPUT_FILE)}\` from ${color4.bold(info.url)}.
|
|
1217
|
+
|
|
1218
|
+
${color4.bold("This may be for one of the following reasons:")}
|
|
1219
|
+
1. The \`${color4.bold(OUTPUT_FILE)}\` actually doesn't exist
|
|
1220
|
+
2. Your repository path is incorrect (wrong branch, wrong tag) default branches other than \`${color4.bold(defaultBranch)}\` must be specified \`${color4.bold("github/<owner>/<name>/tree/<branch>")}\`
|
|
1221
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
1222
|
+
`
|
|
1223
|
+
);
|
|
1224
|
+
};
|
|
1214
1225
|
var github = {
|
|
1215
1226
|
name: () => "github",
|
|
1227
|
+
defaultBranch: () => "main",
|
|
1216
1228
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
1217
1229
|
const info = await github.info(repoPath);
|
|
1218
1230
|
return new URL(
|
|
@@ -1221,13 +1233,8 @@ var github = {
|
|
|
1221
1233
|
);
|
|
1222
1234
|
},
|
|
1223
1235
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
1224
|
-
const
|
|
1225
|
-
const
|
|
1226
|
-
return Err(
|
|
1227
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.
|
|
1228
|
-
Error: ${err}`
|
|
1229
|
-
);
|
|
1230
|
-
};
|
|
1236
|
+
const info = await github.info(repoPath);
|
|
1237
|
+
const url = await github.resolveRaw(info, resourcePath);
|
|
1231
1238
|
try {
|
|
1232
1239
|
const token = get2().get(`${github.name()}-token`);
|
|
1233
1240
|
const headers = new Headers();
|
|
@@ -1236,11 +1243,11 @@ var github = {
|
|
|
1236
1243
|
}
|
|
1237
1244
|
const response = await fetch(url, { headers });
|
|
1238
1245
|
if (!response.ok) {
|
|
1239
|
-
return
|
|
1246
|
+
return manifestErrorMessage(info, github.defaultBranch());
|
|
1240
1247
|
}
|
|
1241
1248
|
return Ok(await response.text());
|
|
1242
|
-
} catch
|
|
1243
|
-
return
|
|
1249
|
+
} catch {
|
|
1250
|
+
return manifestErrorMessage(info, github.defaultBranch());
|
|
1244
1251
|
}
|
|
1245
1252
|
},
|
|
1246
1253
|
fetchManifest: async (repoPath) => {
|
|
@@ -1253,12 +1260,12 @@ var github = {
|
|
|
1253
1260
|
if (typeof repoPath !== "string") return repoPath;
|
|
1254
1261
|
const repo = repoPath.replaceAll(/(https:\/\/github.com\/)|(github\/)/g, "");
|
|
1255
1262
|
const [owner, repoName, ...rest] = repo.split("/");
|
|
1256
|
-
let ref =
|
|
1263
|
+
let ref = github.defaultBranch();
|
|
1257
1264
|
if (rest[0] === "tree") {
|
|
1258
1265
|
ref = rest[1];
|
|
1259
1266
|
}
|
|
1260
1267
|
let refs = "heads";
|
|
1261
|
-
if (ref !==
|
|
1268
|
+
if (ref !== github.defaultBranch()) {
|
|
1262
1269
|
try {
|
|
1263
1270
|
const { data: tags } = await octokit.rest.git.listMatchingRefs({
|
|
1264
1271
|
owner,
|
|
@@ -1286,6 +1293,7 @@ var github = {
|
|
|
1286
1293
|
};
|
|
1287
1294
|
var gitlab = {
|
|
1288
1295
|
name: () => "gitlab",
|
|
1296
|
+
defaultBranch: () => "main",
|
|
1289
1297
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
1290
1298
|
const info = await gitlab.info(repoPath);
|
|
1291
1299
|
return new URL(
|
|
@@ -1294,13 +1302,8 @@ var gitlab = {
|
|
|
1294
1302
|
);
|
|
1295
1303
|
},
|
|
1296
1304
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1299
|
-
return Err(
|
|
1300
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.
|
|
1301
|
-
Error: ${err}`
|
|
1302
|
-
);
|
|
1303
|
-
};
|
|
1305
|
+
const info = await github.info(repoPath);
|
|
1306
|
+
const url = await gitlab.resolveRaw(info, resourcePath);
|
|
1304
1307
|
try {
|
|
1305
1308
|
const token = get2().get(`${gitlab.name()}-token`);
|
|
1306
1309
|
const headers = new Headers();
|
|
@@ -1309,11 +1312,11 @@ var gitlab = {
|
|
|
1309
1312
|
}
|
|
1310
1313
|
const response = await fetch(url, { headers });
|
|
1311
1314
|
if (!response.ok) {
|
|
1312
|
-
return
|
|
1315
|
+
return manifestErrorMessage(info, gitlab.defaultBranch());
|
|
1313
1316
|
}
|
|
1314
1317
|
return Ok(await response.text());
|
|
1315
|
-
} catch
|
|
1316
|
-
return
|
|
1318
|
+
} catch {
|
|
1319
|
+
return manifestErrorMessage(info, gitlab.defaultBranch());
|
|
1317
1320
|
}
|
|
1318
1321
|
},
|
|
1319
1322
|
fetchManifest: async (repoPath) => {
|
|
@@ -1326,7 +1329,7 @@ var gitlab = {
|
|
|
1326
1329
|
if (typeof repoPath !== "string") return repoPath;
|
|
1327
1330
|
const repo = repoPath.replaceAll(/(https:\/\/gitlab.com\/)|(gitlab\/)/g, "");
|
|
1328
1331
|
const [owner, repoName, ...rest] = repo.split("/");
|
|
1329
|
-
let ref =
|
|
1332
|
+
let ref = gitlab.defaultBranch();
|
|
1330
1333
|
let refs = "heads";
|
|
1331
1334
|
if (rest[0] === "-" && rest[1] === "tree") {
|
|
1332
1335
|
if (rest[2].includes("?")) {
|
|
@@ -1355,6 +1358,7 @@ var gitlab = {
|
|
|
1355
1358
|
};
|
|
1356
1359
|
var bitbucket = {
|
|
1357
1360
|
name: () => "bitbucket",
|
|
1361
|
+
defaultBranch: () => "master",
|
|
1358
1362
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
1359
1363
|
const info = await bitbucket.info(repoPath);
|
|
1360
1364
|
return new URL(
|
|
@@ -1363,13 +1367,8 @@ var bitbucket = {
|
|
|
1363
1367
|
);
|
|
1364
1368
|
},
|
|
1365
1369
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
1366
|
-
const
|
|
1367
|
-
const
|
|
1368
|
-
return Err(
|
|
1369
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.
|
|
1370
|
-
Error: ${err}`
|
|
1371
|
-
);
|
|
1372
|
-
};
|
|
1370
|
+
const info = await bitbucket.info(repoPath);
|
|
1371
|
+
const url = await bitbucket.resolveRaw(info, resourcePath);
|
|
1373
1372
|
try {
|
|
1374
1373
|
const token = get2().get(`${bitbucket.name()}-token`);
|
|
1375
1374
|
const headers = new Headers();
|
|
@@ -1378,11 +1377,11 @@ var bitbucket = {
|
|
|
1378
1377
|
}
|
|
1379
1378
|
const response = await fetch(url, { headers });
|
|
1380
1379
|
if (!response.ok) {
|
|
1381
|
-
return
|
|
1380
|
+
return manifestErrorMessage(info, bitbucket.defaultBranch());
|
|
1382
1381
|
}
|
|
1383
1382
|
return Ok(await response.text());
|
|
1384
|
-
} catch
|
|
1385
|
-
return
|
|
1383
|
+
} catch {
|
|
1384
|
+
return manifestErrorMessage(info, bitbucket.defaultBranch());
|
|
1386
1385
|
}
|
|
1387
1386
|
},
|
|
1388
1387
|
fetchManifest: async (repoPath) => {
|
|
@@ -1396,7 +1395,7 @@ var bitbucket = {
|
|
|
1396
1395
|
const repo = repoPath.replaceAll(/(https:\/\/bitbucket.org\/)|(bitbucket\/)/g, "");
|
|
1397
1396
|
const [owner, repoName, ...rest] = repo.split("/");
|
|
1398
1397
|
const refs = "heads";
|
|
1399
|
-
let ref =
|
|
1398
|
+
let ref = bitbucket.defaultBranch();
|
|
1400
1399
|
if (rest[0] === "src") {
|
|
1401
1400
|
ref = rest[1];
|
|
1402
1401
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import color from 'chalk';
|
|
2
2
|
import { Octokit } from 'octokit';
|
|
3
3
|
import * as v from 'valibot';
|
|
4
|
+
import * as ascii from './ascii';
|
|
4
5
|
import type { RemoteBlock } from './blocks';
|
|
5
6
|
import { Err, Ok, type Result } from './blocks/types/result';
|
|
6
7
|
import { type Category, categorySchema } from './build';
|
|
@@ -25,6 +26,11 @@ export interface Provider {
|
|
|
25
26
|
* @returns the name of the provider
|
|
26
27
|
*/
|
|
27
28
|
name: () => string;
|
|
29
|
+
/** Get the name of the default branch
|
|
30
|
+
*
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
defaultBranch: () => string;
|
|
28
34
|
/** Returns a URL to the raw path of the resource provided in the resourcePath
|
|
29
35
|
*
|
|
30
36
|
* @param repoPath
|
|
@@ -60,6 +66,18 @@ export interface Provider {
|
|
|
60
66
|
matches: (repoPath: string) => boolean;
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
const manifestErrorMessage = (info: Info, defaultBranch: string) => {
|
|
70
|
+
return Err(
|
|
71
|
+
`There was an error fetching the \`${color.bold(OUTPUT_FILE)}\` from ${color.bold(info.url)}.
|
|
72
|
+
|
|
73
|
+
${color.bold('This may be for one of the following reasons:')}
|
|
74
|
+
1. The \`${color.bold(OUTPUT_FILE)}\` actually doesn't exist
|
|
75
|
+
2. Your repository path is incorrect (wrong branch, wrong tag) default branches other than \`${color.bold(defaultBranch)}\` must be specified \`${color.bold('github/<owner>/<name>/tree/<branch>')}\`
|
|
76
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
77
|
+
`
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
63
81
|
/** Valid paths
|
|
64
82
|
*
|
|
65
83
|
* `https://github.com/<owner>/<repo>/[tree]/[ref]`
|
|
@@ -68,6 +86,7 @@ export interface Provider {
|
|
|
68
86
|
*/
|
|
69
87
|
const github: Provider = {
|
|
70
88
|
name: () => 'github',
|
|
89
|
+
defaultBranch: () => 'main',
|
|
71
90
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
72
91
|
const info = await github.info(repoPath);
|
|
73
92
|
|
|
@@ -77,13 +96,9 @@ const github: Provider = {
|
|
|
77
96
|
);
|
|
78
97
|
},
|
|
79
98
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
80
|
-
const
|
|
99
|
+
const info = await github.info(repoPath);
|
|
81
100
|
|
|
82
|
-
const
|
|
83
|
-
return Err(
|
|
84
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.\n Error: ${err}`
|
|
85
|
-
);
|
|
86
|
-
};
|
|
101
|
+
const url = await github.resolveRaw(info, resourcePath);
|
|
87
102
|
|
|
88
103
|
try {
|
|
89
104
|
const token = persisted.get().get(`${github.name()}-token`);
|
|
@@ -97,12 +112,12 @@ const github: Provider = {
|
|
|
97
112
|
const response = await fetch(url, { headers });
|
|
98
113
|
|
|
99
114
|
if (!response.ok) {
|
|
100
|
-
return
|
|
115
|
+
return manifestErrorMessage(info, github.defaultBranch());
|
|
101
116
|
}
|
|
102
117
|
|
|
103
118
|
return Ok(await response.text());
|
|
104
|
-
} catch
|
|
105
|
-
return
|
|
119
|
+
} catch {
|
|
120
|
+
return manifestErrorMessage(info, github.defaultBranch());
|
|
106
121
|
}
|
|
107
122
|
},
|
|
108
123
|
fetchManifest: async (repoPath) => {
|
|
@@ -121,7 +136,7 @@ const github: Provider = {
|
|
|
121
136
|
|
|
122
137
|
const [owner, repoName, ...rest] = repo.split('/');
|
|
123
138
|
|
|
124
|
-
let ref =
|
|
139
|
+
let ref = github.defaultBranch();
|
|
125
140
|
|
|
126
141
|
if (rest[0] === 'tree') {
|
|
127
142
|
ref = rest[1];
|
|
@@ -130,7 +145,7 @@ const github: Provider = {
|
|
|
130
145
|
// checks if the type of the ref is tags or heads
|
|
131
146
|
let refs: 'heads' | 'tags' = 'heads';
|
|
132
147
|
// no need to check if ref is main
|
|
133
|
-
if (ref !==
|
|
148
|
+
if (ref !== github.defaultBranch()) {
|
|
134
149
|
try {
|
|
135
150
|
const { data: tags } = await octokit.rest.git.listMatchingRefs({
|
|
136
151
|
owner,
|
|
@@ -173,6 +188,7 @@ const github: Provider = {
|
|
|
173
188
|
*/
|
|
174
189
|
const gitlab: Provider = {
|
|
175
190
|
name: () => 'gitlab',
|
|
191
|
+
defaultBranch: () => 'main',
|
|
176
192
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
177
193
|
const info = await gitlab.info(repoPath);
|
|
178
194
|
|
|
@@ -182,13 +198,9 @@ const gitlab: Provider = {
|
|
|
182
198
|
);
|
|
183
199
|
},
|
|
184
200
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
185
|
-
const
|
|
201
|
+
const info = await github.info(repoPath);
|
|
186
202
|
|
|
187
|
-
const
|
|
188
|
-
return Err(
|
|
189
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.\n Error: ${err}`
|
|
190
|
-
);
|
|
191
|
-
};
|
|
203
|
+
const url = await gitlab.resolveRaw(info, resourcePath);
|
|
192
204
|
|
|
193
205
|
try {
|
|
194
206
|
const token = persisted.get().get(`${gitlab.name()}-token`);
|
|
@@ -202,12 +214,12 @@ const gitlab: Provider = {
|
|
|
202
214
|
const response = await fetch(url, { headers });
|
|
203
215
|
|
|
204
216
|
if (!response.ok) {
|
|
205
|
-
return
|
|
217
|
+
return manifestErrorMessage(info, gitlab.defaultBranch());
|
|
206
218
|
}
|
|
207
219
|
|
|
208
220
|
return Ok(await response.text());
|
|
209
|
-
} catch
|
|
210
|
-
return
|
|
221
|
+
} catch {
|
|
222
|
+
return manifestErrorMessage(info, gitlab.defaultBranch());
|
|
211
223
|
}
|
|
212
224
|
},
|
|
213
225
|
fetchManifest: async (repoPath) => {
|
|
@@ -226,7 +238,7 @@ const gitlab: Provider = {
|
|
|
226
238
|
|
|
227
239
|
const [owner, repoName, ...rest] = repo.split('/');
|
|
228
240
|
|
|
229
|
-
let ref =
|
|
241
|
+
let ref = gitlab.defaultBranch();
|
|
230
242
|
let refs: Info['refs'] = 'heads';
|
|
231
243
|
|
|
232
244
|
if (rest[0] === '-' && rest[1] === 'tree') {
|
|
@@ -271,6 +283,7 @@ const gitlab: Provider = {
|
|
|
271
283
|
*/
|
|
272
284
|
const bitbucket: Provider = {
|
|
273
285
|
name: () => 'bitbucket',
|
|
286
|
+
defaultBranch: () => 'master',
|
|
274
287
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
275
288
|
const info = await bitbucket.info(repoPath);
|
|
276
289
|
|
|
@@ -280,13 +293,9 @@ const bitbucket: Provider = {
|
|
|
280
293
|
);
|
|
281
294
|
},
|
|
282
295
|
fetchRaw: async (repoPath, resourcePath) => {
|
|
283
|
-
const
|
|
296
|
+
const info = await bitbucket.info(repoPath);
|
|
284
297
|
|
|
285
|
-
const
|
|
286
|
-
return Err(
|
|
287
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.\n Error: ${err}`
|
|
288
|
-
);
|
|
289
|
-
};
|
|
298
|
+
const url = await bitbucket.resolveRaw(info, resourcePath);
|
|
290
299
|
|
|
291
300
|
try {
|
|
292
301
|
const token = persisted.get().get(`${bitbucket.name()}-token`);
|
|
@@ -300,12 +309,12 @@ const bitbucket: Provider = {
|
|
|
300
309
|
const response = await fetch(url, { headers });
|
|
301
310
|
|
|
302
311
|
if (!response.ok) {
|
|
303
|
-
return
|
|
312
|
+
return manifestErrorMessage(info, bitbucket.defaultBranch());
|
|
304
313
|
}
|
|
305
314
|
|
|
306
315
|
return Ok(await response.text());
|
|
307
|
-
} catch
|
|
308
|
-
return
|
|
316
|
+
} catch {
|
|
317
|
+
return manifestErrorMessage(info, bitbucket.defaultBranch());
|
|
309
318
|
}
|
|
310
319
|
},
|
|
311
320
|
fetchManifest: async (repoPath) => {
|
|
@@ -327,7 +336,7 @@ const bitbucket: Provider = {
|
|
|
327
336
|
// pretty sure this just auto detects
|
|
328
337
|
const refs = 'heads';
|
|
329
338
|
|
|
330
|
-
let ref =
|
|
339
|
+
let ref = bitbucket.defaultBranch();
|
|
331
340
|
|
|
332
341
|
if (rest[0] === 'src') {
|
|
333
342
|
ref = rest[1];
|