forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_pull_changelog.rb
89 lines (75 loc) · 2.81 KB
/
check_pull_changelog.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require "octokit"
##
# This script will validate that any pull request submitted against a github
# repository will contains changes to CHANGELOG file.
#
# If not the case, an helpful text will be commented on the pull request
# If ok, a thanksful message will be commented also containing a @mention to
# acts as a trigger for review notification by a human.
##
@bot="" # Put here your bot github username
@password="" # Put here your bot github password
@repository="logstash/logstash"
@mention="@jordansissel"
@missing_changelog_message = <<MISSING_CHANGELOG
Hello, I'm #{@bot}, I'm here to help you accomplish your pull request submission quest
You still need to accomplish these tasks:
* Please add a changelog information
Also note that your pull request name will appears in the details section
of the release notes, so please make it clear
MISSING_CHANGELOG
@ok_changelog_message = <<OK_CHANGELOG
You successfully completed the pre-requisite quest (aka updating CHANGELOG)
Also note that your pull request name will appears in the details section
of the release notes, so please make it clear, if not already done.
#{@mention} Dear master, would you please have a look to this humble request
OK_CHANGELOG
#Connect to Github
@client=Octokit::Client.new(:login => @bot, :password => @password)
#For each open pull
Octokit.pull_requests(@repository).each do |pull|
#Get botComment
botComment = nil
@client.issue_comments(@repository, pull.number, {
:sort => "created",
:direction => "desc"
}).each do |comment|
if comment.user.login == @bot
botComment = comment
break
end
end
if !botComment.nil? and botComment.body.start_with?("[BOT-OK]")
#Pull already validated by bot, nothing to do
puts "Pull request #{pull.number}, already ok for bot"
else
#Firt encounter, or previous [BOT-WARN] status
#Check for changelog
warnOnMissingChangeLog = true
@client.pull_request_files(@repository, pull.number).each do |changedFile|
if changedFile.filename == "CHANGELOG"
if changedFile.additions.to_i > 0
#Changelog looks good
warnOnMissingChangeLog = false
else
#No additions, means crazy deletion
warnOnMissingChangeLog = true
end
end
end
if warnOnMissingChangeLog
if botComment.nil?
puts "Pull request #{pull.number}, adding bot warning"
@client.add_comment(@repository, pull.number, "[BOT-WARN] #{@missing_changelog_message}")
else
puts "Pull request #{pull.number}, already warned, no changes yet"
end
else
if !botComment.nil?
@client.delete_comment(@repository,botComment.id)
end
puts "Pull request #{pull.number}, adding bot ok"
@client.add_comment(@repository, pull.number, "[BOT-OK] #{@ok_changelog_message}")
end
end
end