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

GitHub datasource #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
128 changes: 128 additions & 0 deletions examples/swift_repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"version": 1,
"allow_edit": true,
"plugins": [],
"panes": [
{
"title": "libswiftnav",
"width": 1,
"row": {
"3": 1
},
"col": {
"3": 1
},
"col_width": 1,
"widgets": [
{
"type": "text_widget",
"settings": {
"title": "Pull Requests",
"size": "regular",
"value": "datasources[\"libswiftnav\"][\"num_pull_requests\"]",
"animate": true
}
},
{
"type": "text_widget",
"settings": {
"title": "Open Issues",
"size": "regular",
"value": "datasources[\"libswiftnav\"][\"num_open_issues\"]",
"animate": true
}
},
{
"type": "indicator",
"settings": {
"title": "Build Status (master)",
"value": "datasources[\"libswiftnav\"][\"build_status\"]",
"on_text": "passing"
}
},
{
"type": "text_widget",
"settings": {
"title": "Code Coverage",
"size": "regular",
"value": "datasources[\"libswiftnav\"][\"code_coverage\"]",
"animate": true,
"units": "%"
}
}
]
},
{
"title": "piksi_firmware",
"width": 1,
"row": {
"3": 1
},
"col": {
"3": 2
},
"col_width": 1,
"widgets": [
{
"type": "text_widget",
"settings": {
"title": "Pull Requests",
"size": "regular",
"value": "datasources[\"piksi_firmware\"][\"num_pull_requests\"]",
"animate": true
}
},
{
"type": "text_widget",
"settings": {
"title": "Open Issues",
"size": "regular",
"value": "datasources[\"piksi_firmware\"][\"num_open_issues\"]",
"animate": true
}
},
{
"type": "indicator",
"settings": {
"title": "Build Status (master)",
"value": "datasources[\"piksi_firmware\"][\"build_status\"]",
"on_text": "passing"
}
}
]
}
],
"datasources": [
{
"name": "libswiftnav",
"type": "GitHub",
"settings": {
"user": "swift-nav",
"repo": "libswiftnav",
"auth": false,
"client_id": "",
"client_secret": "",
"use_travis": true,
"use_coveralls": true,
"branch": "master",
"refresh": 120
}
},
{
"name": "piksi_firmware",
"type": "GitHub",
"settings": {
"user": "swift-nav",
"repo": "piksi_firmware",
"auth": false,
"client_id": "",
"client_secret": "",
"use_travis": true,
"use_coveralls": false,
"branch": "master",
"refresh": 120
}
}
],
"columns": 3
}
1 change: 1 addition & 0 deletions index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lib/js/freeboard/freeboard.js",

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

Expand Down
4 changes: 2 additions & 2 deletions js/freeboard.min.js

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions js/freeboard.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,3 +1700,140 @@ 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');
}
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.

Loading