bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 1 | require 'rugged' |
| 2 | require 'fileutils' |
| 3 | require 'cgi' |
bigbiff bigbiff | 43606e6 | 2016-09-24 11:10:11 -0400 | [diff] [blame] | 4 | require 'httparty' |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 5 | |
| 6 | module Jekyll |
| 7 | module GitActivity |
| 8 | |
bigbiff bigbiff | 43606e6 | 2016-09-24 11:10:11 -0400 | [diff] [blame] | 9 | def gitactivity(devicetree) |
| 10 | repo = devicetree.split("/")[4] |
| 11 | puts repo |
| 12 | url = "https://api.github.com/repos/TeamWin/" + repo + "/commits" |
| 13 | token = File.read("/home/jenkins/token").chomp |
| 14 | user = "Teamwin-Gerrit" |
| 15 | auth = {:username=>user, :password=>token} |
| 16 | resp = HTTParty.get(url, :basic_auth=>auth, :headers=>{"User-Agent"=>"twrpme"}) |
| 17 | json = JSON.parse(resp.body) |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 18 | messages = "" |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 19 | messages += "<div class='page-heading'>Changelog:</div><div>" |
| 20 | messages += "<hr/>" |
| 21 | messages += "<ul>" |
bigbiff bigbiff | 43606e6 | 2016-09-24 11:10:11 -0400 | [diff] [blame] | 22 | count = 0 |
| 23 | json.each do |sha| |
| 24 | break if count == 5 |
| 25 | begin |
| 26 | url = "https://api.github.com/repos/TeamWin/" + repo + "/commits?&sha=" + sha["sha"] |
| 27 | resp2 = HTTParty.get(url, :basic_auth=>auth, :headers=>{"User-Agent"=>"twrpme"}) |
| 28 | json2 = JSON.parse(resp2.body) |
| 29 | messages += "<li>" |
| 30 | messages += json2[0]["commit"]["author"]["name"] |
| 31 | messages += "<br/>" |
| 32 | messages += json2[0]["commit"]["author"]["date"].to_s() |
| 33 | messages += "<br/>" |
| 34 | messages += json2[0]["commit"]["message"] |
| 35 | messages += "</li><br/>" |
| 36 | rescue |
| 37 | puts "skipping" |
| 38 | end |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 39 | count = count + 1 |
| 40 | end |
| 41 | messages += "</ul></div>" |
bigbiff bigbiff | 43606e6 | 2016-09-24 11:10:11 -0400 | [diff] [blame] | 42 | #puts messages |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 43 | "#{messages}" |
| 44 | end |
bigbiff bigbiff | 43606e6 | 2016-09-24 11:10:11 -0400 | [diff] [blame] | 45 | end |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 46 | end |
bigbiff bigbiff | a5f9f6b | 2016-06-26 20:53:19 -0400 | [diff] [blame] | 47 | Liquid::Template.register_filter(Jekyll::GitActivity) |