Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check function for maximum page count of issue list #855

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 60 additions & 42 deletions reviews/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,54 +114,70 @@ <h2 class="notoc">Filter results</h2>
var totals=0
var counter=maxpages

function getAllData () {
for (var p=1;p<maxpages+1;p++) fetchIssues(p)
var timer = setInterval(function() {
if (counter === 0) {
clearInterval(timer)
if (debug) console.log('finished','Issue length:',issues.length, sections)

// group issues by label, adding to the labels array
for (var i=0; i<issues.length; i++) { // for each issue grabbed from GH
sLabelFound = ''
if (issues[i].labels) { // if that issue has some labels
for (var l=0;l<issues[i].labels.length;l++) { // for each label in that issue
if (issues[i].labels[l].name.startsWith('s:')) {
sLabelFound = issues[i].labels[l].name.replace(/^s:/,'')
if (sections[sLabelFound]) sections[sLabelFound].push(issues[i])
else {
sections[sLabelFound] = []
sections[sLabelFound].push(issues[i])
}
if (debug) console.log(sLabelFound)
}
//if (labels[issues[i].labels[l].name]) labels[issues[i].labels[l].name].push(issues[i])
}
}
}

checkDates()
}
else if (debug) console.log('Counter',counter)
}, 50)
function getAllData (maxpages_new) {
var farr = [];
for (var p=1;p<maxpages_new+1;p++) { farr.push(fetchIssues(p)); }
Promise.all(farr)
.then(() => {
if (debug) console.log('finished','Issue length:',issues.length, sections)
// group issues by label, adding to the labels array
for (var i=0; i<issues.length; i++) { // for each issue grabbed from GH
sLabelFound = ''
if (issues[i].labels) { // if that issue has some labels
for (var l=0;l<issues[i].labels.length;l++) { // for each label in that issue
if (issues[i].labels[l].name.startsWith('s:')) {
sLabelFound = issues[i].labels[l].name.replace(/^s:/,'')
if (sections[sLabelFound]) sections[sLabelFound].push(issues[i])
else {
sections[sLabelFound] = []
sections[sLabelFound].push(issues[i])
}
if (debug) console.log(sLabelFound)
}
//if (labels[issues[i].labels[l].name]) labels[issues[i].labels[l].name].push(issues[i])
}
}
}
checkDates()
});
}


// Grab all the open issues on GitHub and add them to the issues array
function fetchIssues(page) {
var request = new XMLHttpRequest();
request.open('get','https://api.github.com/repos/w3c/i18n-activity/issues?per_page=100&page='+page)
request.onload = function () {
var temp = JSON.parse(request.responseText)
for (var i=0;i<temp.length;i++) {
issues.push(temp[i])
}
totals += issues.length;
if (debug) console.log('Issue length:',issues.length,'Totals',totals,'Page:',page,'Counter:', counter)
counter--
return fetch('https://api.github.com/repos/w3c/i18n-activity/issues?per_page=100&page='+page, { cache: 'no-cache', method: 'GET', redirect: 'follow'})
.then((res) => {
if (res.ok) { return res.json(); }
throw Error(page + ',' + res.status);
}).then((json) => {
for (var i=0;i<json.length;i++) {
issues.push(json[i]);
}
request.send();
totals += issues.length;
if (debug) console.log('Issue length: ', issues.length, ' Totals: ', totals, ' Page: ',page, ' Counter: ', counter);
counter--;
}).catch((err) => { console.log('fetch error: ', err.message); })
}

function fetchIssuesCount() {
var req = new Request('https://api.github.com/repos/w3c/i18n-activity/issues?per_page=100&page=1', { method: "HEAD" });
fetch(req)
.then((response) => {
var last = 1;
if (response.headers.has('Link')) {
var links = response.headers.get('Link');
links.split(',').forEach(link => {
var link_val = link.match(/<.*page=([0-9]+)>; rel="(.*)"/);
if ((link_val) && (link_val[2] == 'last')) {
last = link_val[1];
}
});
} else {
last = maxpages; // if not found, set default
}
getAllData(parseInt(last, 10));
});
}


function checkDates () {
Expand Down Expand Up @@ -415,7 +431,9 @@ <h2 class="notoc">Filter results</h2>
document.getElementById('total').textContent = "There are "+filteredIssues+" issues."
}
</script>
<script>window.onload = getAllData()</script>
<script>
window.addEventListener('load', fetchIssuesCount);
</script>

<footer id="thefooter"></footer>
<script type="text/javascript">document.getElementById('thefooter').innerHTML = g.bottomOfPage</script>
Expand Down