Skip to content

Commit

Permalink
Move github plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fnoble committed Jan 16, 2016
1 parent ef47d18 commit 87934ff
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"lib/js/freeboard/freeboard.js",

"plugins/freeboard/freeboard.datasources.js",
"plugins/freeboard/github.datasources.js",
"plugins/freeboard/freeboard.widgets.js",
"plugins/thirdparty/github.js",
"examples/plugin_example.js",

// *** Load more plugins here ***
Expand Down
138 changes: 138 additions & 0 deletions js/freeboard.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,3 +1700,141 @@ freeboard.loadDatasourcePlugin({
});

}());

// ┌────────────────────────────────────────────────────────────────────┐ \\
// │ GitHub Data Source Plugin │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright © 2015 Fergus Noble │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Licensed under the MIT license. │ \\
// └────────────────────────────────────────────────────────────────────┘ \\

(function () {
var jsonDatasource = function (settings, updateCallback) {
var self = this;
var updateTimer = null;
var currentSettings = settings;

function updateRefresh(refreshTime) {
if (updateTimer) {
clearInterval(updateTimer);
}

updateTimer = setInterval(function () {
self.updateNow();
}, refreshTime);
}

updateRefresh(currentSettings.refresh * 1000);

this.updateNow = function () {
var auth = currentSettings.auth ?
"?client_id=" + currentSettings.client_id +
"&client_secret=" + currentSettings.client_secret : "";
var path = currentSettings.user + "/" + currentSettings.repo;

$.when(
$.get("https://api.github.com/repos/" + path + auth),
$.get("https://api.github.com/repos/" + path + "/pulls" + auth),
currentSettings.use_travis ? $.get("https://api.travis-ci.org/repos/" + path + "/branches/" + currentSettings.branch) : null,
currentSettings.use_coveralls ? $.get("http://cors.io/?u=https://coveralls.io/github/" + path + ".json?branch=" + currentSettings.branch) : null
).then(function(github, github_pr, travis, coveralls) {

var data = {};
data["num_pull_requests"] = github_pr[0].length;
data["pull_requests"] = github_pr[0];
data["num_open_issues"] = github[0]['open_issues_count'];
data["github_repo"] = github[0];
if (travis) {
data["build_status"] = travis[0]['branch']['state'];
data["travis"] = travis[0];
}
if (coveralls) {
data["coveralls"] = JSON.parse(coveralls[0]);
var cc = data["coveralls"]["covered_percent"];
data["code_coverage"] = Number(Math.round(cc+'e2')+'e-2');
}
console.log(data);
updateCallback(data);

});
}

this.onDispose = function () {
clearInterval(updateTimer);
updateTimer = null;
}

this.onSettingsChanged = function (newSettings) {
currentSettings = newSettings;
updateRefresh(currentSettings.refresh * 1000);
self.updateNow();
}
};

freeboard.loadDatasourcePlugin({
type_name: "GitHub",
settings: [
{
name: "user",
display_name: "GitHub user / organization",
type: "text"
},
{
name: "repo",
display_name: "GitHub repo",
type: "text"
},
{
name: "auth",
display_name: "Use Authentication",
type: "boolean",
default_value: false
},
{
name: "client_id",
display_name: "Client ID",
description: 'GitHub Application Client ID',
type: "text"
},
{
name: "client_secret",
display_name: "Client Secret",
description: 'GitHub Application Client Secret',
type: "text"
},
{
name: "use_travis",
display_name: "Use Travis",
description: 'Pull CI status from TravisCI',
type: "boolean",
default_value: true
},
{
name: "use_coveralls",
display_name: "Use Coveralls",
description: 'Pull code coverage from Coveralls',
type: "boolean",
default_value: true
},
{
name: "branch",
display_name: "Branch",
description: 'Branch for build and coverage status',
type: "text",
default_value: "master"
},
{
name: "refresh",
display_name: "Refresh Every",
type: "number",
suffix: "seconds",
default_value: 120
},
],
newInstance: function (settings, newInstanceCallback, updateCallback) {
newInstanceCallback(new jsonDatasource(settings, updateCallback));
}
});

}());
2 changes: 1 addition & 1 deletion js/freeboard.plugins.min.js

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions js/freeboard_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -4723,3 +4723,141 @@ freeboard.loadDatasourcePlugin({
});

}());

// ┌────────────────────────────────────────────────────────────────────┐ \\
// │ GitHub Data Source Plugin │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Copyright © 2015 Fergus Noble │ \\
// ├────────────────────────────────────────────────────────────────────┤ \\
// │ Licensed under the MIT license. │ \\
// └────────────────────────────────────────────────────────────────────┘ \\

(function () {
var jsonDatasource = function (settings, updateCallback) {
var self = this;
var updateTimer = null;
var currentSettings = settings;

function updateRefresh(refreshTime) {
if (updateTimer) {
clearInterval(updateTimer);
}

updateTimer = setInterval(function () {
self.updateNow();
}, refreshTime);
}

updateRefresh(currentSettings.refresh * 1000);

this.updateNow = function () {
var auth = currentSettings.auth ?
"?client_id=" + currentSettings.client_id +
"&client_secret=" + currentSettings.client_secret : "";
var path = currentSettings.user + "/" + currentSettings.repo;

$.when(
$.get("https://api.github.com/repos/" + path + auth),
$.get("https://api.github.com/repos/" + path + "/pulls" + auth),
currentSettings.use_travis ? $.get("https://api.travis-ci.org/repos/" + path + "/branches/" + currentSettings.branch) : null,
currentSettings.use_coveralls ? $.get("http://cors.io/?u=https://coveralls.io/github/" + path + ".json?branch=" + currentSettings.branch) : null
).then(function(github, github_pr, travis, coveralls) {

var data = {};
data["num_pull_requests"] = github_pr[0].length;
data["pull_requests"] = github_pr[0];
data["num_open_issues"] = github[0]['open_issues_count'];
data["github_repo"] = github[0];
if (travis) {
data["build_status"] = travis[0]['branch']['state'];
data["travis"] = travis[0];
}
if (coveralls) {
data["coveralls"] = JSON.parse(coveralls[0]);
var cc = data["coveralls"]["covered_percent"];
data["code_coverage"] = Number(Math.round(cc+'e2')+'e-2');
}
console.log(data);
updateCallback(data);

});
}

this.onDispose = function () {
clearInterval(updateTimer);
updateTimer = null;
}

this.onSettingsChanged = function (newSettings) {
currentSettings = newSettings;
updateRefresh(currentSettings.refresh * 1000);
self.updateNow();
}
};

freeboard.loadDatasourcePlugin({
type_name: "GitHub",
settings: [
{
name: "user",
display_name: "GitHub user / organization",
type: "text"
},
{
name: "repo",
display_name: "GitHub repo",
type: "text"
},
{
name: "auth",
display_name: "Use Authentication",
type: "boolean",
default_value: false
},
{
name: "client_id",
display_name: "Client ID",
description: 'GitHub Application Client ID',
type: "text"
},
{
name: "client_secret",
display_name: "Client Secret",
description: 'GitHub Application Client Secret',
type: "text"
},
{
name: "use_travis",
display_name: "Use Travis",
description: 'Pull CI status from TravisCI',
type: "boolean",
default_value: true
},
{
name: "use_coveralls",
display_name: "Use Coveralls",
description: 'Pull code coverage from Coveralls',
type: "boolean",
default_value: true
},
{
name: "branch",
display_name: "Branch",
description: 'Branch for build and coverage status',
type: "text",
default_value: "master"
},
{
name: "refresh",
display_name: "Refresh Every",
type: "number",
suffix: "seconds",
default_value: 120
},
],
newInstance: function (settings, newInstanceCallback, updateCallback) {
newInstanceCallback(new jsonDatasource(settings, updateCallback));
}
});

}());
2 changes: 1 addition & 1 deletion js/freeboard_plugins.min.js

Large diffs are not rendered by default.

File renamed without changes.

0 comments on commit 87934ff

Please sign in to comment.