diff options
Diffstat (limited to 'includes/fetcher/index.js')
-rw-r--r-- | includes/fetcher/index.js | 132 |
1 files changed, 85 insertions, 47 deletions
diff --git a/includes/fetcher/index.js b/includes/fetcher/index.js index 0f3dcac..0b36111 100644 --- a/includes/fetcher/index.js +++ b/includes/fetcher/index.js @@ -12,9 +12,9 @@ let gitlabProjectsRaw; if (smallestId > 0) { - gitlabProjectsRaw = (await axios.get(`https://gitlab.minteck.org/api/v4/projects?order_by=id&archived=false&simple=true&id_before=${smallestId}`)).data; + gitlabProjectsRaw = (await axios.get(`https://gitlab.minteck.org/api/v4/users/minteck/projects?order_by=id&archived=false&simple=true&id_before=${smallestId}`)).data; } else { - gitlabProjectsRaw = (await axios.get(`https://gitlab.minteck.org/api/v4/projects?order_by=id&archived=false&simple=true`)).data; + gitlabProjectsRaw = (await axios.get(`https://gitlab.minteck.org/api/v4/users/minteck/projects?order_by=id&archived=false&simple=true`)).data; } for (let project of gitlabProjectsRaw) { gitlabProjects.push({ @@ -25,7 +25,9 @@ issues: null, vcs: project.http_url_to_repo, web: project.web_url, - showcase: project.topics.includes("Showcase") + icon: project.avatar_url, + showcase: project.topics.includes("Showcase"), + date: project.last_activity_at }) smallestId = project.id; } @@ -35,37 +37,84 @@ } console.log("Fetching projects... YouTrack"); - const youtrackProjectsRaw = (await axios.get(`https://youtrack.minteck.org/api/admin/projects?fields=id,name,shortName,description`)).data; let youtrackProjects = []; - - for (let project of youtrackProjectsRaw) { - youtrackProjects.push({ - gitlab_id: null, - youtrack_id: project.id, - name: project.name, - description: project.description, - issues: project.shortName, - vcs: null, - web: null, - showcase: false - }) - } - - console.log("Merging data...") + let unusedBase = []; + let unusedYoutrackProjects = []; let projects = {}; let projectsPlusYoutrack = {}; - for (let project of youtrackProjects) { - nameCompareYoutrack = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); - descCompareYoutrack = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); - for (let gprj of gitlabProjects) { - nameCompareGitlab = gprj.name.toLowerCase().replace(/[^a-z]+/gm, ""); - descCompareGitlab = gprj.description.toLowerCase().replace(/[^a-z]+/gm, ""); + try { + const youtrackProjectsRaw = (await axios.get(`https://youtrack.minteck.org/api/admin/projects?fields=id,name,shortName,description`)).data; + for (let project of youtrackProjectsRaw) { + youtrackProjects.push({ + gitlab_id: null, + youtrack_id: project.id, + name: project.name, + description: project.description, + issues: project.shortName, + vcs: null, + web: null, + icon: null, + showcase: false, + date: null + }) + } + + console.log("Merging data...") + for (let project of youtrackProjects) { + nameCompareYoutrack = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); + descCompareYoutrack = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); + + for (let gprj of gitlabProjects) { + nameCompareGitlab = gprj.name.toLowerCase().replace(/[^a-z]+/gm, ""); + descCompareGitlab = gprj.description.toLowerCase().replace(/[^a-z]+/gm, ""); - if (nameCompareGitlab === nameCompareYoutrack || descCompareGitlab === descCompareYoutrack) { - gprj.youtrack_id = project.youtrack_id; + if (nameCompareGitlab === nameCompareYoutrack || descCompareGitlab === descCompareYoutrack) { + gprj.youtrack_id = project.youtrack_id; + gprj.issues = "https://youtrack.minteck.org/issues/" + project.youtrack_id; + } + + if (gprj.youtrack_id === null) { + id = crypto.createHash('sha1').update(gprj.gitlab_id.toString() + "null").digest('hex'); + } else { + id = crypto.createHash('sha1').update(gprj.gitlab_id.toString() + gprj.youtrack_id.toString()).digest('hex'); + projectsPlusYoutrack[id] = gprj; + } + projects[id] = gprj; } + } + const knownYoutrackIds = Object.keys(projectsPlusYoutrack).map((i) => { return projectsPlusYoutrack[i].youtrack_id; }); + for (let project of youtrackProjectsRaw) { + if (!knownYoutrackIds.includes(project.id)) { + project.name_compare = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); + project.description_compare = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); + unusedYoutrackProjects.push(project); + } + } + + for (let project of gitlabProjects) { + project.name_compare = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); + project.description_compare = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); + unusedBase.push(project); + } + + projects = Object.keys(projects).map((i) => { + return { + id: i, + ...projects[i] + } + }) + projects.sort((a, b) => (new Date(b.date) - new Date(a.date))); + + fs.writeFileSync("projects.json", JSON.stringify(projects, null, 4)); + fs.writeFileSync("unused-live.json", JSON.stringify(unusedYoutrackProjects, null, 4)); + fs.writeFileSync("unused-base.json", JSON.stringify(unusedBase, null, 4)); + console.log("Done merging, found " + Object.keys(projects).length + " projects (" + Object.keys(projectsPlusYoutrack).length + " on YouTrack, " + unusedYoutrackProjects.length + " unused)"); + } catch (e) { + console.log("Failed to fetch YouTrack projects (" + e.message + ")"); + + for (let gprj of gitlabProjects) { if (gprj.youtrack_id === null) { id = crypto.createHash('sha1').update(gprj.gitlab_id.toString() + "null").digest('hex'); } else { @@ -74,27 +123,16 @@ } projects[id] = gprj; } - } - const knownYoutrackIds = Object.keys(projectsPlusYoutrack).map((i) => { return projectsPlusYoutrack[i].youtrack_id; }); - let unusedYoutrackProjects = []; - for (let project of youtrackProjectsRaw) { - if (!knownYoutrackIds.includes(project.id)) { - project.name_compare = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); - project.description_compare = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); - unusedYoutrackProjects.push(project); - } - } + projects = Object.keys(projects).map((i) => { + return { + id: i, + ...projects[i] + } + }) + projects.sort((a, b) => (new Date(b.date) - new Date(a.date))); - let unusedBase = []; - for (let project of gitlabProjects) { - project.name_compare = project.name.toLowerCase().replace(/[^a-z]+/gm, ""); - project.description_compare = project.description.toLowerCase().replace(/[^a-z]+/gm, ""); - unusedBase.push(project); + fs.writeFileSync("projects.json", JSON.stringify(projects, null, 4)); + console.log("Done fetching, found " + Object.keys(projects).length + " projects"); } - - fs.writeFileSync("projects.json", JSON.stringify(projects, false, 4)); - fs.writeFileSync("unused-live.json", JSON.stringify(unusedYoutrackProjects, false, 4)); - fs.writeFileSync("unused-base.json", JSON.stringify(unusedBase, false, 4)); - console.log("Done merging, found " + Object.keys(projects).length + " projects (" + Object.keys(projectsPlusYoutrack).length + " on YouTrack, " + unusedYoutrackProjects.length + " unused)"); })()
\ No newline at end of file |