Skip to content
This repository has been archived by the owner on Dec 28, 2017. It is now read-only.

Commit

Permalink
adding forgotten CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBruant committed Feb 23, 2014
1 parent 085d347 commit 801cb39
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 34 deletions.
14 changes: 14 additions & 0 deletions Firefox/data/github-repo-response-stats.css
@@ -0,0 +1,14 @@
ul.sunken-menu-group li[aria-label="Issues"] div.response-time-stats{
padding: 0 5px;
}

ul.sunken-menu-group li[aria-label="Issues"] div.response-time-stats span{
display: block;
}

ul.sunken-menu-group li[aria-label="Issues"] div.response-time-stats h1{
font-size: 1em;
font-weight: bold;
text-decoration: underline;
margin: 0;
}
56 changes: 32 additions & 24 deletions Firefox/data/github-repo-response-stats.js
Expand Up @@ -2,38 +2,46 @@

var ISSUES_LI_SELECTOR = 'ul.sunken-menu-group li[aria-label="Issues"]';

/*
{
issuesConsidered: issuesNb,
commentlessIssues: commentlessIssuesCount,
responseTimes: delays
}
*/
var documentReadyP = new Promise( resolve => {
document.addEventListener('DOMContentLoaded', function listener(){
resolve(document);
document.removeEventListener('DOMContentLoaded', listener);
});
});

var ONE_DAY = 24*60*60*1000; // ms

self.port.on('repo-response-stats', stats => {
/*
{
issuesConsidered: issuesNb,
commentlessIssues: commentlessIssuesCount,
responseTimes: delays
}
*/
console.log('integrate stats to content', stats);

var responseTimes = stats.responseTimes;

// Unlikely race condition: the document might not be ready yet (and so the following code might fail)
var issuesLi = document.body.querySelector(ISSUES_LI_SELECTOR);
if(!issuesLi)
throw new Error('No element matching ('+ISSUES_LI_SELECTOR+'). No idea where to put the results :-(');

var responseTimeStatsDiv = document.createElement('div');
responseTimeStatsDiv.classList.add('response-time-stats');

var commentLessIssuesPercent = (stats.commentlessIssues/stats.issuesConsidered)*100;
var averageResponseTime = responseTimes.reduce( (acc, curr) => {return acc+curr}, 0 )/responseTimes.length;
var averageResponseDays = averageResponseTime/ONE_DAY;
documentReadyP.then(document => {
var issuesLi = document.body.querySelector(ISSUES_LI_SELECTOR);
if(!issuesLi)
throw new Error('No element matching ('+ISSUES_LI_SELECTOR+'). No idea where to put the results :-(');

var responseTimeStatsDiv = document.createElement('div');
responseTimeStatsDiv.classList.add('response-time-stats');

var commentLessIssuesPercent = (stats.commentlessIssues/stats.issuesConsidered)*100;
var averageResponseTime = responseTimes.reduce( (acc, curr) => {return acc+curr}, 0 )/responseTimes.length;
var averageResponseDays = averageResponseTime/ONE_DAY;

responseTimeStatsDiv.innerHTML =
'<h1>Over the latest '+stats.issuesConsidered+' open issues</h1>' +
'<span>Commentless: '+commentLessIssuesPercent.toFixed(1)+'%</span>'+
'<span>Average response time: '+ averageResponseDays.toFixed(1) + ' days</span>';

issuesLi.appendChild(responseTimeStatsDiv);
})

responseTimeStatsDiv.innerHTML =
'<h1>Over the latest '+stats.issuesConsidered+' open issues</h1>' +
'<span>Commentless: '+commentLessIssuesPercent.toFixed(1)+'%</span>'+
'<span>Average response time: '+ averageResponseDays.toFixed(1) + ' days</span>';

issuesLi.appendChild(responseTimeStatsDiv);
})
Binary file removed Firefox/data/icon/icon.png
Binary file not shown.
5 changes: 0 additions & 5 deletions Firefox/data/icon/readme.md

This file was deleted.

Binary file removed Firefox/data/icon/tribal-33147.png
Binary file not shown.
4 changes: 2 additions & 2 deletions Firefox/lib/githubAPI.js
Expand Up @@ -30,8 +30,8 @@ module.exports = function(token){
Request({
url: BASE_URL+'users', // any url could work
onComplete: function (response) {
if(response.status === 200)
def.resolve(token);
if(response.status < 400)

This comment has been minimized.

Copy link
@DavidBruant

DavidBruant Feb 23, 2014

Author Owner

Fixed a bug related to 304s

def.resolve(token); // 200 or 304 usually
else // 401
def.reject('fail '+token);
},
Expand Down
9 changes: 6 additions & 3 deletions Firefox/lib/main.js
Expand Up @@ -32,11 +32,9 @@ var storage = require("sdk/simple-storage").storage;

var Github = require('githubAPI');

console.log('Promise', typeof Promise, this.Promise);

exports.main = function(){

var pageMod; // TODO pageMod.destroy when token changes
var pageMod;
var gh;

var tokenPanel = Panel({
Expand Down Expand Up @@ -90,6 +88,9 @@ exports.main = function(){
});

function getReadyForGithubRepoPages(token){
if(pageMod)
pageMod.destroy();

This comment has been minimized.

Copy link
@DavidBruant

DavidBruant Feb 23, 2014

Author Owner

Token is changing, no need to keep old pageMod around


pageMod = PageMod({
include: /^https:\/\/github\.com\/([^\/]+\/[^\/]+)\/?$/,

Expand Down Expand Up @@ -125,6 +126,8 @@ exports.main = function(){
var issueCreatorId;
var issueCreationDate;

// TODO omit issues by repo collaborators

if(issue.comments === 0)
commentlessIssuesCount++;
else{
Expand Down

0 comments on commit 801cb39

Please sign in to comment.