-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
71 lines (54 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var fs = require('fs');
if(!fs.existsSync('./config.js')) {
console.log("Please configure config.js.example and copy it to config.js.");
process.exit(1);
}
var github = require('octonode')
, j5 = require('johnny-five')
, config = require('./config');
var board = j5.Board();
//add your github token
var client = github.client(config.apiToken);
//enter your repository, it must be a repository where you have pull rights, and it needs to have CI incorporated.
var repo = client.repo(config.repo);
var red, green, blue;
var lights = function(status){
if(status == 'success'){
green.on();
red.off();
blue.off();
} else if(status == 'pending') {
red.off();
green.off();
blue.on();
} else {
red.on();
green.off();
blue.off();
}
}
var getStatus = function() {
repo.statuses('master', function(err, status, body){
//do whatever you'd like with the most recent status!
console.log(status[0].state);
//change the color based on the last status
lights(status[0].state);
});
};
board.on('ready', function (){
// Create three instances of LEDs
red = new j5.Led({pin : 11});
green = new j5.Led({pin : 10});
blue = new j5.Led({pin: 9});
if(config.ledType === "common-anode") {
swapOffOn(red);
swapOffOn(blue);
swapOffOn(green);
}
setInterval(getStatus, 500);
});
function swapOffOn(led) {
var tmp = led.off;
led.off = led.on;
led.on = tmp;
};