mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Github API fixes
This commit is contained in:
parent
5dd2f5b0fe
commit
cdd205f3e6
@ -1,13 +1,20 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const fsp = require("fs/promises");
|
const fsp = require("fs/promises");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fetch = require("node-fetch");
|
const nodeFetch = require("node-fetch");
|
||||||
|
|
||||||
const APILink = "https://api.github.com/repos/tobspr/shapez.io";
|
const APILink = "https://api.github.com/repos/tobspr/shapez.io";
|
||||||
const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long
|
const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long
|
||||||
|
const personalAccessToken = "<INSERT_YOU_P.A.T_HERE";
|
||||||
|
|
||||||
const JSONFileLocation = path.join(__dirname, "..", "contributors.json");
|
const JSONFileLocation = path.join(__dirname, "..", "contributors.json");
|
||||||
|
|
||||||
|
function fetch(url) {
|
||||||
|
return nodeFetch(url, {
|
||||||
|
headers: [["Authorization", "token " + personalAccessToken]],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function JSONFileExists() {
|
function JSONFileExists() {
|
||||||
return fs.existsSync(JSONFileLocation);
|
return fs.existsSync(JSONFileLocation);
|
||||||
}
|
}
|
||||||
@ -46,7 +53,6 @@ function shouldDownloadPRs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function PRIsTranslation(link) {
|
function PRIsTranslation(link) {
|
||||||
// return true;
|
|
||||||
// We just say that if a PR only edits translation files, its a translation, all others are something else
|
// We just say that if a PR only edits translation files, its a translation, all others are something else
|
||||||
return fetch(link + "/files")
|
return fetch(link + "/files")
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
@ -55,6 +61,7 @@ function PRIsTranslation(link) {
|
|||||||
console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR");
|
console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR");
|
||||||
throw new Error("rate-limit reached");
|
throw new Error("rate-limit reached");
|
||||||
}
|
}
|
||||||
|
console.log(res);
|
||||||
for (let file of res) {
|
for (let file of res) {
|
||||||
if (!file.filename.startsWith("translations/")) return false;
|
if (!file.filename.startsWith("translations/")) return false;
|
||||||
}
|
}
|
||||||
@ -89,16 +96,16 @@ function reqPage(page) {
|
|||||||
.then(async res => {
|
.then(async res => {
|
||||||
const prs = [];
|
const prs = [];
|
||||||
|
|
||||||
for (let i = 0; i < res.length - 1; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
if (!res[i].merged_at) continue; // Skip files that were never merged
|
if (!res[i].merged_at) {
|
||||||
|
continue;
|
||||||
|
} // Skip files that were never merged
|
||||||
|
|
||||||
const prInfo = {
|
const prInfo = {
|
||||||
username: res[i].user.login,
|
username: res[i].user.login,
|
||||||
html_url: res[i].html_url,
|
html_url: res[i].html_url,
|
||||||
url: res[i].url,
|
url: res[i].url,
|
||||||
user_avatar: res[i].user.avatar_url,
|
|
||||||
title: res[i].title,
|
title: res[i].title,
|
||||||
time: res[i].createdAt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
prs.push(prInfo);
|
prs.push(prInfo);
|
||||||
@ -119,7 +126,7 @@ async function downloadAllPrs() {
|
|||||||
|
|
||||||
const prs = [];
|
const prs = [];
|
||||||
|
|
||||||
for (let i = 0; i < numOfPageReqs; i++) {
|
for (let i = 1; i < numOfPageReqs + 1; i++) {
|
||||||
prs.push(...(await reqPage(i))); // Yes promise.all would be good, but I wanna keep them in order (at least for now)
|
prs.push(...(await reqPage(i))); // Yes promise.all would be good, but I wanna keep them in order (at least for now)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +156,12 @@ async function updateContributors() {
|
|||||||
function gulpTaskContributors($, gulp) {
|
function gulpTaskContributors($, gulp) {
|
||||||
gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb));
|
gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb));
|
||||||
gulp.task("contributors.build.force", cb => updateContributors().then(() => cb));
|
gulp.task("contributors.build.force", cb => updateContributors().then(() => cb));
|
||||||
|
|
||||||
|
gulp.task("fetch.test", cb => {
|
||||||
|
fetch(APILink)
|
||||||
|
.then(res => console.log(res.headers.get("x-ratelimit-remaining")))
|
||||||
|
.then(cb);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -254,7 +254,6 @@ gulp.task(
|
|||||||
"imgres.copyImageResources",
|
"imgres.copyImageResources",
|
||||||
"imgres.copyNonImageResources",
|
"imgres.copyNonImageResources",
|
||||||
"translations.fullBuild",
|
"translations.fullBuild",
|
||||||
"contributors.build",
|
|
||||||
"css.dev",
|
"css.dev",
|
||||||
"html.dev"
|
"html.dev"
|
||||||
)
|
)
|
||||||
@ -273,17 +272,13 @@ gulp.task(
|
|||||||
"imgres.copyImageResources",
|
"imgres.copyImageResources",
|
||||||
"imgres.copyNonImageResources",
|
"imgres.copyNonImageResources",
|
||||||
"translations.fullBuild",
|
"translations.fullBuild",
|
||||||
"contributors.build",
|
|
||||||
"css.dev",
|
"css.dev",
|
||||||
"html.standalone-dev"
|
"html.standalone-dev"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Builds everything (staging)
|
// Builds everything (staging)
|
||||||
gulp.task(
|
gulp.task("step.staging.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.staging"));
|
||||||
"step.staging.code",
|
|
||||||
gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.staging")
|
|
||||||
);
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"step.staging.mainbuild",
|
"step.staging.mainbuild",
|
||||||
gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.staging.code")
|
gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.staging.code")
|
||||||
@ -292,10 +287,7 @@ gulp.task("step.staging.all", gulp.series("step.staging.mainbuild", "css.prod",
|
|||||||
gulp.task("build.staging", gulp.series("utils.cleanup", "step.staging.all", "step.postbuild"));
|
gulp.task("build.staging", gulp.series("utils.cleanup", "step.staging.all", "step.postbuild"));
|
||||||
|
|
||||||
// Builds everything (prod)
|
// Builds everything (prod)
|
||||||
gulp.task(
|
gulp.task("step.prod.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.prod"));
|
||||||
"step.prod.code",
|
|
||||||
gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.prod")
|
|
||||||
);
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"step.prod.mainbuild",
|
"step.prod.mainbuild",
|
||||||
gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.prod.code")
|
gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.prod.code")
|
||||||
@ -306,7 +298,7 @@ gulp.task("build.prod", gulp.series("utils.cleanup", "step.prod.all", "step.post
|
|||||||
// Builds everything (standalone-beta)
|
// Builds everything (standalone-beta)
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"step.standalone-beta.code",
|
"step.standalone-beta.code",
|
||||||
gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "contributors.build", "js.standalone-beta")
|
gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "js.standalone-beta")
|
||||||
);
|
);
|
||||||
gulp.task("step.standalone-beta.mainbuild", gulp.parallel("step.baseResources", "step.standalone-beta.code"));
|
gulp.task("step.standalone-beta.mainbuild", gulp.parallel("step.baseResources", "step.standalone-beta.code"));
|
||||||
gulp.task(
|
gulp.task(
|
||||||
@ -323,12 +315,7 @@ gulp.task(
|
|||||||
for (const prefix of ["", "china.", "wegame."]) {
|
for (const prefix of ["", "china.", "wegame."]) {
|
||||||
gulp.task(
|
gulp.task(
|
||||||
prefix + "step.standalone-prod.code",
|
prefix + "step.standalone-prod.code",
|
||||||
gulp.series(
|
gulp.series("sounds.fullbuildHQ", "translations.fullBuild", prefix + "js.standalone-prod")
|
||||||
"sounds.fullbuildHQ",
|
|
||||||
"translations.fullBuild",
|
|
||||||
"contributors.build",
|
|
||||||
prefix + "js.standalone-prod"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
|
|||||||
@ -35,7 +35,9 @@ export class CreditsState extends TextualGameState {
|
|||||||
</div>
|
</div>
|
||||||
<div class="contributors section">
|
<div class="contributors section">
|
||||||
<div class="title">Contributors: </div>
|
<div class="title">Contributors: </div>
|
||||||
<div id="loading">Loading... <div>
|
<div class="flex-people">
|
||||||
|
${this.getContributorsHTML()}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user