-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandle-pull-request.rb
executable file
·76 lines (69 loc) · 2.17 KB
/
handle-pull-request.rb
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
72
73
74
75
#!/usr/bin/env ruby
require 'net/http'
require 'fileutils'
require 'rubygems'
require 'json'
require 'pp'
$LOAD_PATH << '.'
require './GitHub'
require './Build'
require './config'
def initialise_pull_request(filename)
lastPull = 0
if File.file?(filename)
lastPull = File.read(filename).to_i
end
return lastPull
end
if __FILE__ == $0
g = GitHub.new($org, $OAUTHTOKEN)
lastPullSeen = 0
lastPull = 0
filename = ""
$repositories.each do |repository|
result = g.get_pull_requests_for(repository)
lastPull = 0
lastPullSeen = 0
filename = ""
result.each do |doc|
if doc["state"] == "open"
filename = "#{doc["base"]["repo"]["owner"]["login"]}-#{repository}.last"
lastPull = initialise_pull_request(filename)
if lastPullSeen < doc["number"].to_i
lastPullSeen = doc["number"].to_i
end
if lastPull < doc["number"].to_i
commit_history = g.get_commit_history(repository, doc["number"])
commit_history.each do | commit |
if commit["commit"]["message"].split("\n")[0].match(/\bwip\b/i)
comment = "Please change the message for commit #{commit["sha"][0..6]}\n"
comment = comment + commit["commit"]["message"]
puts "Commit message: #{comment}"
g.post_comment(doc["_links"]["comments"]["href"], comment)
end
end
puts "Reading commit history from #{doc["commits_url"]}"
puts "Building pull #{doc["number"]} for #{repository}:"
b = Build.new(repository,
doc["base"]["repo"]["owner"]["login"], doc["base"]["ref"],
doc["head"]["repo"]["owner"]["login"], doc["head"]["ref"])
comment = b.run_test_suite()
puts "Comment: #{comment}"
g.post_comment(doc["_links"]["comments"]["href"], comment)
else
end
end
end
if lastPullSeen.to_i > lastPull
lastPull = lastPullSeen
end
if !filename.empty?
if File.file?(filename)
File.delete(filename)
end
lastFile = File.open(filename, "w+")
lastFile.syswrite("#{lastPull}")
lastFile.close
end
end
end