Games now pull issues from Github.
This commit is contained in:
parent
aab4b23c12
commit
1da19ecfb8
|
@ -6,6 +6,7 @@ const logger = require('winston');
|
||||||
|
|
||||||
const sanitizeHtml = require('sanitize-html');
|
const sanitizeHtml = require('sanitize-html');
|
||||||
|
|
||||||
|
const request = require('request-promise');
|
||||||
const toml = require('toml');
|
const toml = require('toml');
|
||||||
const tomlify = require('tomlify-j0.4');
|
const tomlify = require('tomlify-j0.4');
|
||||||
const blackfriday = require('./blackfriday.js');
|
const blackfriday = require('./blackfriday.js');
|
||||||
|
@ -38,125 +39,189 @@ function getDirectories (srcpath) {
|
||||||
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
|
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getGithubIssues() {
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
// Force the while loop out after 10 calls.
|
||||||
|
for (var page = 0; page <= 3; page++) {
|
||||||
|
let options = {
|
||||||
|
url: `https://api.github.com/repos/citra-emu/citra/issues?per_page=99&page=${page}&client_id=fca88d03a8f4e3ae45f8&client_secret=97c8f5633b5f03a78bfa84f0ab50659db1303035`,
|
||||||
|
headers: { 'User-Agent': 'citrabot' }
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.verbose(`Requesting Github Issue Page ${page}.`);
|
||||||
|
var body = await request.get(options);
|
||||||
|
var obj = JSON.parse(body);
|
||||||
|
|
||||||
|
if (obj == null || obj.length == 0) {
|
||||||
|
logger.verbose(`No more Github issues found -- on page ${page}.`);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
results = results.concat(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch game information stored in Github repository.
|
// Fetch game information stored in Github repository.
|
||||||
gitPull(fsPathCode, 'https://github.com/citra-emu/citra-games-wiki.git');
|
gitPull(fsPathCode, 'https://github.com/citra-emu/citra-games-wiki.git');
|
||||||
|
|
||||||
// Fetch game articles stored in Github wiki.
|
// Fetch game articles stored in Github wiki.
|
||||||
gitPull(fsPathWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');
|
gitPull(fsPathWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');
|
||||||
|
|
||||||
// Make sure the output directories in Hugo exist.
|
// Fetch all issues from Github.
|
||||||
[fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) {
|
var githubIssues = null;
|
||||||
if (fs.existsSync(path) == false) {
|
|
||||||
logger.info(`Creating Hugo output directory: ${path}`);
|
|
||||||
fs.mkdirSync(path);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
getGithubIssues()
|
||||||
// Loop through each game folder.
|
.then(function(issues) {
|
||||||
getDirectories(fsPathCode).forEach(function(game) {
|
logger.info(`Imported ${issues.length} issues from Github.`);
|
||||||
try {
|
githubIssues = issues;
|
||||||
if (game == '.git') { return; }
|
})
|
||||||
|
.then(function() {
|
||||||
logger.info(`Processing game: ${game}`);
|
// Make sure the output directories in Hugo exist.
|
||||||
|
[fsPathHugoContent, fsPathHugoBoxart, fsPathHugoIcon, fsPathHugoSavefiles, fsPathHugoScreenshots].forEach(function (path) {
|
||||||
// Copy the boxart for the game.
|
if (fs.existsSync(path) == false) {
|
||||||
fsextra.copySync(`${fsPathCode}/${game}/boxart.png`, `${fsPathHugoBoxart}/${game}.png`);
|
logger.info(`Creating Hugo output directory: ${path}`);
|
||||||
|
fs.mkdirSync(path);
|
||||||
// Copy the icon for the game.
|
|
||||||
fsextra.copySync(`${fsPathCode}/${game}/icon.png`, `${fsPathHugoIcon}/${game}.png`);
|
|
||||||
|
|
||||||
var model = toml.parse(fs.readFileSync(`${fsPathCode}/${game}/game.dat`, 'utf8'));
|
|
||||||
let currentDate = new Date();
|
|
||||||
model.date = `${currentDate.toISOString()}`;
|
|
||||||
|
|
||||||
// SHORTCUTS BLOCK
|
|
||||||
// Parse testcase information out of the dat to reinject as shortcut values.
|
|
||||||
if (model.testcases == null || model.testcases.length == 0) {
|
|
||||||
model.compatibility = "99";
|
|
||||||
model.testcase_date = "2000-01-01";
|
|
||||||
} else {
|
|
||||||
let recent = model.testcases[0];
|
|
||||||
model.compatibility = recent.compatibility;
|
|
||||||
model.testcase_date = recent.date;
|
|
||||||
}
|
|
||||||
// END SHORTCUTS BLOCK
|
|
||||||
|
|
||||||
// SAVEFILE BLOCK
|
|
||||||
var fsPathCodeSavefilesGame = `${fsPathCode}/${game}/savefiles/`;
|
|
||||||
var fsPathHugoSavefilesGame = `${fsPathHugoSavefiles}/${game}/`;
|
|
||||||
if (fs.existsSync(fsPathCodeSavefilesGame)) {
|
|
||||||
// Create the savefile directory for the game.
|
|
||||||
if (fs.existsSync(fsPathHugoSavefilesGame) == false) {
|
|
||||||
fs.mkdirSync(fsPathHugoSavefilesGame);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy all savefiles into the output folder, and read their data.
|
|
||||||
model.savefiles = [];
|
|
||||||
fs.readdirSync(fsPathCodeSavefilesGame).forEach(file => {
|
|
||||||
if (path.extname(file) == '.zip') {
|
|
||||||
fsextra.copySync(`${fsPathCodeSavefilesGame}/${file}`, `${fsPathHugoSavefilesGame}/${file}`);
|
|
||||||
} else if (path.extname(file) == '.dat') {
|
|
||||||
// Read the data file into an object.
|
|
||||||
let savefile = toml.parse(fs.readFileSync(`${fsPathCodeSavefilesGame}/${file}`, 'utf8'));
|
|
||||||
|
|
||||||
let stats = fs.statSync(`${fsPathCodeSavefilesGame}/${file}`);
|
|
||||||
|
|
||||||
// Store the contents of the file in memory for adding it into the markdown later.
|
|
||||||
model.savefiles.push({
|
|
||||||
date: new Date(util.inspect(stats.mtime)),
|
|
||||||
filename: file.replace('.dat', '.zip'),
|
|
||||||
title: savefile.title,
|
|
||||||
description: savefile.description,
|
|
||||||
author: savefile.author,
|
|
||||||
title_id: savefile.title_id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Finished copying all savefiles into the output folder, and reading their data.
|
|
||||||
}
|
|
||||||
// END SAVEFILE BLOCK
|
|
||||||
|
|
||||||
// Copy the screenshots for the game.
|
|
||||||
let fsPathScreenshotInputGame = `${fsPathCode}/${game}/screenshots/`;
|
|
||||||
let fsPathScreenshotOutputGame = `${fsPathHugoScreenshots}/${game}/`;
|
|
||||||
if (fs.existsSync(fsPathScreenshotInputGame)) {
|
|
||||||
// Create the savefile directory for each game.
|
|
||||||
if (fs.existsSync(fsPathScreenshotOutputGame) == false) {
|
|
||||||
fs.mkdirSync(fsPathScreenshotOutputGame);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy all screenshots into the output folder.
|
|
||||||
fs.readdirSync(fsPathScreenshotInputGame).forEach(file => {
|
|
||||||
if (path.extname(file) == '.png') {
|
|
||||||
fsextra.copySync(`${fsPathScreenshotInputGame}/${file}`, `${fsPathScreenshotOutputGame}/${file}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// WIKI BLOCK
|
|
||||||
var wikiText = "";
|
|
||||||
let fsPathWikiGame = `${fsPathWiki}/${game}.md`;
|
|
||||||
if (fs.existsSync(fsPathWikiGame)) {
|
|
||||||
wikiText = fs.readFileSync(fsPathWikiGame, 'utf8');
|
|
||||||
|
|
||||||
// Fix Blackfriday markdown rendering differences.
|
|
||||||
wikiText = blackfriday.fixLists(wikiText);
|
|
||||||
wikiText = blackfriday.fixLinks(wikiText);
|
|
||||||
} else {
|
|
||||||
wikiText = "## No wiki exists yet for this game.";
|
|
||||||
}
|
|
||||||
// END WIKI BLOCK
|
|
||||||
|
|
||||||
let modelText = tomlify(model, null, 2);
|
|
||||||
|
|
||||||
let contentOutput = `+++\r\n${modelText}\r\n+++\r\n\r\n${wikiText}\r\n`;
|
|
||||||
fs.writeFileSync(`${fsPathHugoContent}/${game}.md`, contentOutput);
|
|
||||||
} catch (ex) {
|
|
||||||
logger.warn(`${game} failed to generate: ${ex}`);
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (ex) {
|
})
|
||||||
logger.error(ex);
|
.then(function() {
|
||||||
|
// Loop through each game and process it.
|
||||||
|
getDirectories(fsPathCode).forEach(function(game) {
|
||||||
|
processGame(game);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
logger.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
function processGame(game) {
|
||||||
|
try {
|
||||||
|
if (game == '.git' || game == '_validation') { return; }
|
||||||
|
|
||||||
|
logger.info(`Processing game: ${game}`);
|
||||||
|
|
||||||
|
// Copy the boxart for the game.
|
||||||
|
fsextra.copySync(`${fsPathCode}/${game}/boxart.png`, `${fsPathHugoBoxart}/${game}.png`);
|
||||||
|
|
||||||
|
// Copy the icon for the game.
|
||||||
|
fsextra.copySync(`${fsPathCode}/${game}/icon.png`, `${fsPathHugoIcon}/${game}.png`);
|
||||||
|
|
||||||
|
var model = toml.parse(fs.readFileSync(`${fsPathCode}/${game}/game.dat`, 'utf8'));
|
||||||
|
let currentDate = new Date();
|
||||||
|
model.date = `${currentDate.toISOString()}`;
|
||||||
|
|
||||||
|
// SHORTCUTS BLOCK
|
||||||
|
// Parse testcase information out of the dat to reinject as shortcut values.
|
||||||
|
if (model.testcases == null || model.testcases.length == 0) {
|
||||||
|
model.compatibility = "99";
|
||||||
|
model.testcase_date = "2000-01-01";
|
||||||
|
} else {
|
||||||
|
let recent = model.testcases[0];
|
||||||
|
model.compatibility = recent.compatibility;
|
||||||
|
model.testcase_date = recent.date;
|
||||||
|
}
|
||||||
|
// END SHORTCUTS BLOCK
|
||||||
|
|
||||||
|
// SAVEFILE BLOCK
|
||||||
|
var fsPathCodeSavefilesGame = `${fsPathCode}/${game}/savefiles/`;
|
||||||
|
var fsPathHugoSavefilesGame = `${fsPathHugoSavefiles}/${game}/`;
|
||||||
|
if (fs.existsSync(fsPathCodeSavefilesGame)) {
|
||||||
|
// Create the savefile directory for the game.
|
||||||
|
if (fs.existsSync(fsPathHugoSavefilesGame) == false) {
|
||||||
|
fs.mkdirSync(fsPathHugoSavefilesGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy all savefiles into the output folder, and read their data.
|
||||||
|
model.savefiles = [];
|
||||||
|
fs.readdirSync(fsPathCodeSavefilesGame).forEach(file => {
|
||||||
|
if (path.extname(file) == '.zip') {
|
||||||
|
fsextra.copySync(`${fsPathCodeSavefilesGame}/${file}`, `${fsPathHugoSavefilesGame}/${file}`);
|
||||||
|
} else if (path.extname(file) == '.dat') {
|
||||||
|
// Read the data file into an object.
|
||||||
|
let savefile = toml.parse(fs.readFileSync(`${fsPathCodeSavefilesGame}/${file}`, 'utf8'));
|
||||||
|
|
||||||
|
let stats = fs.statSync(`${fsPathCodeSavefilesGame}/${file}`);
|
||||||
|
|
||||||
|
// Store the contents of the file in memory for adding it into the markdown later.
|
||||||
|
model.savefiles.push({
|
||||||
|
date: new Date(util.inspect(stats.mtime)),
|
||||||
|
filename: file.replace('.dat', '.zip'),
|
||||||
|
title: savefile.title,
|
||||||
|
description: savefile.description,
|
||||||
|
author: savefile.author,
|
||||||
|
title_id: savefile.title_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Finished copying all savefiles into the output folder, and reading their data.
|
||||||
|
}
|
||||||
|
// END SAVEFILE BLOCK
|
||||||
|
|
||||||
|
// GITHUB ISSUES BLOCK
|
||||||
|
if (model.github_issues != null && model.github_issues.length > 0) {
|
||||||
|
model.issues = [];
|
||||||
|
model.closed_issues = [];
|
||||||
|
|
||||||
|
model.github_issues.forEach(function(number) {
|
||||||
|
let issue = githubIssues.find(x => x.number == number);
|
||||||
|
if (issue == null) {
|
||||||
|
model.closed_issues.push(number);
|
||||||
|
} else {
|
||||||
|
model.issues.push({
|
||||||
|
number: issue.number.toString(),
|
||||||
|
title: issue.title,
|
||||||
|
state: issue.state,
|
||||||
|
created_at: issue.created_at,
|
||||||
|
updated_at: issue.updated_at,
|
||||||
|
labels: issue.labels.map(function(x) { return { name: x.name, color: x.color } })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
github_issues = null;
|
||||||
|
}
|
||||||
|
// END GITHUB ISSUES BLOCK
|
||||||
|
|
||||||
|
// Copy the screenshots for the game.
|
||||||
|
let fsPathScreenshotInputGame = `${fsPathCode}/${game}/screenshots/`;
|
||||||
|
let fsPathScreenshotOutputGame = `${fsPathHugoScreenshots}/${game}/`;
|
||||||
|
if (fs.existsSync(fsPathScreenshotInputGame)) {
|
||||||
|
// Create the savefile directory for each game.
|
||||||
|
if (fs.existsSync(fsPathScreenshotOutputGame) == false) {
|
||||||
|
fs.mkdirSync(fsPathScreenshotOutputGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy all screenshots into the output folder.
|
||||||
|
fs.readdirSync(fsPathScreenshotInputGame).forEach(file => {
|
||||||
|
if (path.extname(file) == '.png') {
|
||||||
|
fsextra.copySync(`${fsPathScreenshotInputGame}/${file}`, `${fsPathScreenshotOutputGame}/${file}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// WIKI BLOCK
|
||||||
|
var wikiText = "";
|
||||||
|
let fsPathWikiGame = `${fsPathWiki}/${game}.md`;
|
||||||
|
if (fs.existsSync(fsPathWikiGame)) {
|
||||||
|
wikiText = fs.readFileSync(fsPathWikiGame, 'utf8');
|
||||||
|
|
||||||
|
// Fix Blackfriday markdown rendering differences.
|
||||||
|
wikiText = blackfriday.fixLists(wikiText);
|
||||||
|
wikiText = blackfriday.fixLinks(wikiText);
|
||||||
|
} else {
|
||||||
|
wikiText = "## No wiki exists yet for this game.";
|
||||||
|
}
|
||||||
|
// END WIKI BLOCK
|
||||||
|
|
||||||
|
let modelText = tomlify(model, null, 2);
|
||||||
|
|
||||||
|
let contentOutput = `+++\r\n${modelText}\r\n+++\r\n\r\n${wikiText}\r\n`;
|
||||||
|
fs.writeFileSync(`${fsPathHugoContent}/${game}.md`, contentOutput);
|
||||||
|
} catch (ex) {
|
||||||
|
logger.warn(`${game} failed to generate: ${ex}`);
|
||||||
|
logger.error(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"delete": "^0.3.2",
|
"delete": "^0.3.2",
|
||||||
"fs-extra": "^3.0.1",
|
"fs-extra": "^3.0.1",
|
||||||
|
"request": "^2.81.0",
|
||||||
|
"request-promise": "^4.2.1",
|
||||||
"rimraf": "^2.6.1",
|
"rimraf": "^2.6.1",
|
||||||
"sanitize-html": "^1.14.1",
|
"sanitize-html": "^1.14.1",
|
||||||
"sync-exec": "^0.6.2",
|
"sync-exec": "^0.6.2",
|
||||||
|
|
|
@ -99,38 +99,70 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if (where (readDir "/static/savefiles") "Name" .File.BaseFileName) }}
|
<!-- Github Issues -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h2>Savefiles</h2>
|
<h2>Known Issues</h2>
|
||||||
<table class="table table-responsive table-striped">
|
{{- if isset .Params "issues" }}
|
||||||
<thead>
|
<table class="table table-responsive table-striped">
|
||||||
<tr>
|
<thead>
|
||||||
<th>Name</th>
|
<tr>
|
||||||
<th>Description</th>
|
<th>Title</th>
|
||||||
<th>Uploaded By</th>
|
<th>Created</th>
|
||||||
<th>Date</th>
|
<th>Last Updated</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range .Params.savefiles }}
|
{{- range .Params.issues }}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/savefiles/{{ $gameName }}/{{ .filename }}">{{ .title }}</a></td>
|
<th><a href="https://github.com/citra-emu/citra/issues/{{ .number }}">{{ .title }}</a></th>
|
||||||
<td>{{ .description }}</td>
|
<td>{{ dateFormat "January 2, 2006" .created_at }}</td>
|
||||||
<td><a href="https://community.citra-emu.org/u/{{ .author }}/summary">{{ .author }}</a></td>
|
<td>{{ dateFormat "January 2, 2006" .updated_at }}</td>
|
||||||
<td>{{ dateFormat "January 2, 2006" .date }}</td>
|
</tr>
|
||||||
</tr>
|
{{- end }}
|
||||||
{{ end }}
|
</tbody>
|
||||||
</tbody>
|
</table>
|
||||||
</table>
|
{{- else }}
|
||||||
</div>
|
<p>No issues have been reported for this game.</p>
|
||||||
|
{{- end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
</div>
|
||||||
|
|
||||||
{{ if (where (readDir "/static/images/screenshots0") "Name" .File.BaseFileName) }}
|
<!-- Savefiles -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h2>Screenshots</h2>
|
<h2>Savefiles</h2>
|
||||||
|
{{ if (where (readDir "/static/savefiles") "Name" .File.BaseFileName) }}
|
||||||
|
<table class="table table-responsive table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Uploaded By</th>
|
||||||
|
<th>Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range .Params.savefiles }}
|
||||||
|
<tr>
|
||||||
|
<td><a href="/savefiles/{{ $gameName }}/{{ .filename }}">{{ .title }}</a></td>
|
||||||
|
<td>{{ .description }}</td>
|
||||||
|
<td><a href="https://community.citra-emu.org/u/{{ .author }}/summary">{{ .author }}</a></td>
|
||||||
|
<td>{{ dateFormat "January 2, 2006" .date }}</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{ else }}
|
||||||
|
<p>No savefiles have been uploaded for this game.</p>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h2>Screenshots</h2>
|
||||||
|
{{ if (where (readDir "/static/images/screenshots0") "Name" .File.BaseFileName) }}
|
||||||
{{ $files := readDir (printf "/static/images/screenshots0/%s/" .File.BaseFileName) }}
|
{{ $files := readDir (printf "/static/images/screenshots0/%s/" .File.BaseFileName) }}
|
||||||
{{ range $index, $element := $files }}
|
{{ range $index, $element := $files }}
|
||||||
<div class="popup-gallery col-lg-3 col-md-4 col-xs-6 thumb">
|
<div class="popup-gallery col-lg-3 col-md-4 col-xs-6 thumb">
|
||||||
|
@ -139,10 +171,11 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
{{ else }}
|
||||||
|
<p>No screenshots have been uploaded for this game.</p>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
</div>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "scripts" }}
|
{{ define "scripts" }}
|
||||||
|
|
Reference in New Issue