2016-01-12 23:14:56 +02:00
|
|
|
use "std"
|
|
|
|
use "http"
|
|
|
|
use "json"
|
|
|
|
use "functional"
|
|
|
|
|
|
|
|
header = "* Prints current GitHub timeline *"
|
|
|
|
println "*" * length(header)
|
|
|
|
println header
|
|
|
|
println "*" * length(header)
|
|
|
|
|
|
|
|
// Executes in main thread
|
|
|
|
//http("https://api.github.com/events", def(r) {
|
|
|
|
// foreach(jsondecode(r), ::show_github_events)
|
|
|
|
//})
|
|
|
|
|
|
|
|
// Executes in new thread
|
|
|
|
thread(::http, "https://api.github.com/events", def(r) {
|
|
|
|
foreach(jsondecode(r), ::show_github_events)
|
|
|
|
})
|
|
|
|
|
|
|
|
def show_github_events(event) {
|
2016-01-13 00:09:44 +02:00
|
|
|
println event.created_at
|
|
|
|
actor = event.actor
|
|
|
|
println "User: https://github.com/" + actor.login
|
2016-01-12 23:14:56 +02:00
|
|
|
println github_event_type(event)
|
|
|
|
println "-" * 50
|
|
|
|
}
|
|
|
|
|
|
|
|
def github_event_type(event) {
|
2016-01-13 00:09:44 +02:00
|
|
|
type = event.type
|
|
|
|
repo = "https://github.com/" + event.repo.name
|
|
|
|
payload = event.payload
|
2016-01-12 23:14:56 +02:00
|
|
|
|
|
|
|
if (type == "CommitCommentEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return "commented commit in " + repo + "\n" + payload.comment.body
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "CreateEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return "created " + payload.ref_type + " on " + repo
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "DeleteEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return "deleted " + payload.ref_type + " on " + repo
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "ForkEvent") {
|
|
|
|
return "forked repository " + repo
|
|
|
|
}
|
|
|
|
if (type == "IssueCommentEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return "commented issue " + payload.issue.title + " on " + repo + "\n" + payload.comment.body
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "IssuesEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return payload.action + " issue '" + payload.issue.title + "' on " + repo
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "PullRequestEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
pr = payload.pull_request
|
|
|
|
return payload.action + " pull request #" + payload.number + " '" + pr.title + "' on " + repo
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "PushEvent") {
|
2016-01-13 00:09:44 +02:00
|
|
|
return "pushed " + length(payload.commits) + " commits to " + repo
|
2016-01-12 23:14:56 +02:00
|
|
|
}
|
|
|
|
if (type == "WatchEvent") {
|
|
|
|
return "start watching repository " + repo
|
|
|
|
}
|
|
|
|
return type + " on " + repo
|
|
|
|
}
|