create-amytis 0.1.0 → 0.1.1
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 +9 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,12 +22,20 @@ function prompt(question, defaultVal = "") {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
function fetchJson(url) {
|
|
25
|
+
const headers = { "User-Agent": "create-amytis-cli" };
|
|
26
|
+
if (process.env.GITHUB_TOKEN) {
|
|
27
|
+
headers["Authorization"] = `Bearer ${process.env.GITHUB_TOKEN}`;
|
|
28
|
+
}
|
|
25
29
|
return new Promise((resolve2, reject) => {
|
|
26
|
-
https.get(url, { headers
|
|
30
|
+
https.get(url, { headers }, (res) => {
|
|
27
31
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
28
32
|
fetchJson(res.headers.location).then(resolve2).catch(reject);
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
35
|
+
if (res.statusCode === 403) {
|
|
36
|
+
reject(new Error("GitHub API rate limit exceeded. Set GITHUB_TOKEN env var to increase the limit."));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
31
39
|
if (res.statusCode !== 200) {
|
|
32
40
|
reject(new Error(`GitHub API returned ${res.statusCode} for ${url}`));
|
|
33
41
|
return;
|