1
0
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:
Edward Badel 2021-06-27 01:16:40 -04:00
parent 5dd2f5b0fe
commit cdd205f3e6
3 changed files with 27 additions and 25 deletions

View File

@ -1,13 +1,20 @@
const fs = require("fs");
const fsp = require("fs/promises");
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 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");
function fetch(url) {
return nodeFetch(url, {
headers: [["Authorization", "token " + personalAccessToken]],
});
}
function JSONFileExists() {
return fs.existsSync(JSONFileLocation);
}
@ -46,7 +53,6 @@ function shouldDownloadPRs() {
}
function PRIsTranslation(link) {
// return true;
// We just say that if a PR only edits translation files, its a translation, all others are something else
return fetch(link + "/files")
.then(res => res.json())
@ -55,6 +61,7 @@ function PRIsTranslation(link) {
console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR");
throw new Error("rate-limit reached");
}
console.log(res);
for (let file of res) {
if (!file.filename.startsWith("translations/")) return false;
}
@ -89,16 +96,16 @@ function reqPage(page) {
.then(async res => {
const prs = [];
for (let i = 0; i < res.length - 1; i++) {
if (!res[i].merged_at) continue; // Skip files that were never merged
for (let i = 0; i < res.length; i++) {
if (!res[i].merged_at) {
continue;
} // Skip files that were never merged
const prInfo = {
username: res[i].user.login,
html_url: res[i].html_url,
url: res[i].url,
user_avatar: res[i].user.avatar_url,
title: res[i].title,
time: res[i].createdAt,
};
prs.push(prInfo);
@ -119,7 +126,7 @@ async function downloadAllPrs() {
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)
}
@ -149,6 +156,12 @@ async function updateContributors() {
function gulpTaskContributors($, gulp) {
gulp.task("contributors.build", cb => tryToUpdateContributors().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 = {

View File

@ -254,7 +254,6 @@ gulp.task(
"imgres.copyImageResources",
"imgres.copyNonImageResources",
"translations.fullBuild",
"contributors.build",
"css.dev",
"html.dev"
)
@ -273,17 +272,13 @@ gulp.task(
"imgres.copyImageResources",
"imgres.copyNonImageResources",
"translations.fullBuild",
"contributors.build",
"css.dev",
"html.standalone-dev"
)
);
// Builds everything (staging)
gulp.task(
"step.staging.code",
gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.staging")
);
gulp.task("step.staging.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.staging"));
gulp.task(
"step.staging.mainbuild",
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"));
// Builds everything (prod)
gulp.task(
"step.prod.code",
gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.prod")
);
gulp.task("step.prod.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.prod"));
gulp.task(
"step.prod.mainbuild",
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)
gulp.task(
"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(
@ -323,12 +315,7 @@ gulp.task(
for (const prefix of ["", "china.", "wegame."]) {
gulp.task(
prefix + "step.standalone-prod.code",
gulp.series(
"sounds.fullbuildHQ",
"translations.fullBuild",
"contributors.build",
prefix + "js.standalone-prod"
)
gulp.series("sounds.fullbuildHQ", "translations.fullBuild", prefix + "js.standalone-prod")
);
gulp.task(

View File

@ -35,7 +35,9 @@ export class CreditsState extends TextualGameState {
</div>
<div class="contributors section">
<div class="title">Contributors: </div>
<div id="loading">Loading... <div>
<div class="flex-people">
${this.getContributorsHTML()}
</div>
</div>
`;
}