-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace GitHub.js and tomlify-j0.4 dependencies
With the official GitHub JS client and @ltd/j-toml respectively. As part of this, turn the JS files into modules and load the dependencies from inside the modules.
- Loading branch information
Showing
7 changed files
with
58 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,4 @@ <h3>TOML <a id="download" download="settings.toml"></a></h3> | |
|
||
<p>Note that the download link that appears above after converting YAML does not work in Internet Explorer or Edge. Users of those browsers will need to copy the content of the TOML text box into a <code>settings.toml</code> file they create themselves, or use a different browser</code>.</p> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/tomlify.min.js"></script> | ||
<script src="/js/convert.js"></script> | ||
<script src="/js/convert.js" type="module"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,4 @@ | |
<div id="progress" class="mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active"></div> | ||
</div> | ||
|
||
<script src="https://unpkg.com/[email protected]/dist/GitHub.bundle.min.js"></script> | ||
<script src="/js/credits.js"></script> | ||
<script src="/js/credits.js" type="module"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
'use strict'; | ||
import { load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs'; | ||
import TOML from 'https://cdn.skypack.dev/-/@ltd/[email protected]/dist=es2019,mode=imports/optimized/@ltd/j-toml.js'; | ||
|
||
function upgradeOldYaml(yaml) { | ||
if (yaml['Debug Verbosity'] && !yaml.enableDebugLogging) { | ||
|
@@ -37,20 +39,13 @@ function upgradeOldYaml(yaml) { | |
|
||
function yamlToToml(evt) { | ||
try { | ||
const settings = upgradeOldYaml(jsyaml.load(evt.target.value)); | ||
const settings = upgradeOldYaml(load(evt.target.value)); | ||
|
||
const options = { | ||
space: 2, | ||
replace: function(key, value) { | ||
if (typeof value === 'number') { | ||
/* Settings only use integers, no floats. */ | ||
return Math.round(value).toString(); | ||
} | ||
|
||
return false; | ||
} | ||
indent: 2, | ||
newline: '\n' | ||
} | ||
const toml = tomlify.toToml(settings, options); | ||
const toml = TOML.stringify(settings, options); | ||
|
||
document.getElementById('output').value = toml; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
'use strict'; | ||
import { Octokit } from "https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/rest.js"; | ||
import { throttling } from "https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/plugin-throttling.js"; | ||
|
||
function addToList(listElement, person) { | ||
const a = document.createElement('a'); | ||
|
@@ -45,12 +47,12 @@ function sortContributors(a,b) { | |
} | ||
|
||
function getStats(contributor) { | ||
const isAnon = contributor.author.type === 'Anonymous'; | ||
const isAnon = contributor.type === 'Anonymous'; | ||
return { | ||
contributions: contributor.total, | ||
name: isAnon ? contributor.author.name : contributor.author.login, | ||
avatar_url: isAnon ? undefined : contributor.author.avatar_url, | ||
html_url: isAnon ? 'mailto:' + contributor.author.email : contributor.author.html_url | ||
contributions: contributor.contributions, | ||
name: isAnon ? contributor.name : contributor.login, | ||
avatar_url: isAnon ? undefined : contributor.avatar_url, | ||
html_url: isAnon ? 'mailto:' + contributor.email : contributor.html_url | ||
}; | ||
} | ||
|
||
|
@@ -81,13 +83,26 @@ function getContributorsStats(contributors) { | |
} | ||
|
||
async function getContributors() { | ||
const github = new GitHub(); | ||
const ThrottledOctokit = Octokit.plugin(throttling); | ||
|
||
const reposResponse = await github.getOrganization('loot').getRepos(); | ||
const octokit = new ThrottledOctokit({ | ||
throttle: { | ||
onAbuseLimit: () => true, | ||
onRateLimit: () => true | ||
} | ||
}); | ||
|
||
const promises = reposResponse.data | ||
const repos = await octokit.paginate(octokit.rest.repos.listForOrg, { | ||
org: 'loot' | ||
}); | ||
|
||
const promises = repos | ||
.filter(repo => !repo.fork) | ||
.map(repo => github.getRepo('loot', repo.name).getContributors()); | ||
.map(repo => octokit.paginate(octokit.rest.repos.listContributors, { | ||
owner: 'loot', | ||
repo: repo.name, | ||
anon: true | ||
})); | ||
|
||
return Promise.all(promises).then(results => results.flat()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
'use strict'; | ||
import { Octokit } from 'https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/rest.js'; | ||
import { throttling } from 'https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/plugin-throttling.js'; | ||
import { dump, load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs'; | ||
|
||
// Globals | ||
/////////////////// | ||
|
@@ -76,13 +79,27 @@ function onSearchInit(evt) { | |
console.log("Loading masterlist..."); | ||
progress.classList.remove('hidden'); | ||
|
||
var repo = (new GitHub()) | ||
.getRepo('loot', gameButton.getAttribute('data-selected')) | ||
.getContents(undefined, 'masterlist.yaml', true) | ||
.then(readMasterlist) | ||
.catch(function() { | ||
document.getElementById('progress').classList.add('hidden'); | ||
}); | ||
const ThrottledOctokit = Octokit.plugin(throttling); | ||
|
||
const octokit = new ThrottledOctokit({ | ||
throttle: { | ||
onAbuseLimit: () => true, | ||
onRateLimit: () => true | ||
} | ||
}); | ||
|
||
octokit.rest.repos.getContent({ | ||
owner: 'loot', | ||
repo: gameButton.getAttribute('data-selected'), | ||
path: 'masterlist.yaml', | ||
mediaType: { | ||
format: 'raw' | ||
} | ||
}) | ||
.then(readMasterlist) | ||
.catch(function() { | ||
document.getElementById('progress').classList.add('hidden'); | ||
}); | ||
} | ||
|
||
function onGameSelect(evt) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,4 @@ | |
<div id="progress" class="mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active hidden"></div> | ||
<div id="results" class="mdl-shadow--2dp"></div> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/GitHub.bundle.min.js"></script> | ||
<script src="/js/search.js"></script> | ||
<script src="/js/search.js" type="module"></script> |