tutter-sppuppet 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/tutter/action/sppuppet.rb +113 -78
- data/tutter-sppuppet.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWI0NDMwZWY2NmM5N2NhNDA4ZGQ4MWU4NmI3OWVhNGY0ODQyMjI0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmJjZmVmYmFkZGFlMjQwNGZmMGNmNmU4MjUxOTNmNWUyODliNWVjOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWI1YzBjYmI4NDljNDgyYzVlZWI4ZGQ5YThlODMxNjIxYWQ1NjQ2ODNjYjY4
|
10
|
+
MmU0ZWFkYzllOGRmZDNjZDg3YmMyMDRhYWNmNDA4ZjgyNjMxZWZiODc4Yjhj
|
11
|
+
MzIzOTg5Y2I0Mzc5ZDBkMzViNDUwNmFjMWQ4NzBhYzdlOTc5NzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjY1ODgzMDkwOWI3NWNmYjFiOTY2OTU5NzI3NDBiMGE5YzU0Nzk2ZDI3MWEy
|
14
|
+
MThmYmUzOTc3MDczNjYwMjM1NDI4NTFmYWY3ZTBlMGU4OTZhNmY3ODFiZjEz
|
15
|
+
ZTVmMjQ2ZmIzNTM0ZjlkYTljMjk3MGUyODM5MjAzZGNhOWQ1ZDM=
|
@@ -22,96 +22,28 @@ class Sppuppet
|
|
22
22
|
end
|
23
23
|
|
24
24
|
pull_request_id = @data['issue']['number']
|
25
|
-
pr = @client.pull_request @project, pull_request_id
|
26
|
-
votes = {}
|
27
25
|
|
28
|
-
|
26
|
+
merge_command = (@data['comment']['body'] == '!merge' ||
|
29
27
|
@data['comment']['body'].start_with?(':shipit:'))
|
30
28
|
|
31
|
-
return 200, 'Not a merge comment' unless
|
29
|
+
return 200, 'Not a merge comment' unless merge_command
|
32
30
|
|
33
|
-
|
34
|
-
msg = "Merge state for is not clean. Current state: #{pr.mergeable_state}\nHave the tests finished running?"
|
35
|
-
@client.add_comment(@project, pull_request_id, msg)
|
36
|
-
return 200, msg
|
37
|
-
end
|
38
|
-
|
39
|
-
# We fetch the latest commit and it's date.
|
40
|
-
last_commit = @client.pull_request_commits(@project, pull_request_id).last
|
41
|
-
last_commit_date = last_commit.commit.committer.date
|
42
|
-
|
43
|
-
comments = @client.issue_comments(@project, pull_request_id)
|
44
|
-
|
45
|
-
# Check each comment for +1 and merge comments
|
46
|
-
comments.each do |i|
|
47
|
-
# Comment is older than last commit.
|
48
|
-
# We only want to check for +1 in newer comments
|
49
|
-
next if last_commit_date > i.created_at
|
50
|
-
|
51
|
-
match = /^:?([+-])1:?/.match(i.body)
|
52
|
-
if match
|
53
|
-
score = match[1] == '+' ? 1 : -1
|
54
|
-
# pull request submitter cant +1
|
55
|
-
unless pr.user.login == i.attrs[:user].attrs[:login]
|
56
|
-
votes[i.attrs[:user].attrs[:login]] = score
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
31
|
+
return maybe_merge(pull_request_id, true)
|
60
32
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return
|
33
|
+
when 'status'
|
34
|
+
return 200, 'Merge state not clean' unless @data['state'] == 'success'
|
35
|
+
commit_sha = @data['commit']['sha']
|
36
|
+
@client.pull_requests(@project).each do |pr|
|
37
|
+
return maybe_merge(pr.number,false) if pr.head.sha == commit_sha
|
66
38
|
end
|
39
|
+
return 200, "Found no pull requests matching #{commit_sha}"
|
67
40
|
|
68
|
-
json = { url: pr.url,
|
69
|
-
title: pr.title,
|
70
|
-
author: pr.user.login,
|
71
|
-
description: pr.body,
|
72
|
-
commits: @client.pull_request_commits(@project, pr.number).map { |c| { author: c.author, message: c.commit.message, sha: c.commit.tree.sha } },
|
73
|
-
head_sha: pr.head.sha,
|
74
|
-
tests: @client.combined_status(@project, pr.head.sha).statuses.map { |s| {state: s.state, url: s.target_url, description: s.description } },
|
75
|
-
reviewers: votes.keys,
|
76
|
-
deployer: comments.last.user.login }
|
77
|
-
# TODO: Word wrap description
|
78
|
-
merge_msg = <<MERGE_MSG
|
79
|
-
Title: #{pr.title}
|
80
|
-
Description: #{pr.body}
|
81
|
-
Author: #{pr.user.login}
|
82
|
-
Reviewers: #{votes.keys.join ', '}
|
83
|
-
Deployer: #{comments.last.user.login}
|
84
|
-
URL: #{pr.url}
|
85
|
-
MERGE_MSG
|
86
|
-
begin
|
87
|
-
merge_commit = @client.merge_pull_request(@project, pull_request_id, merge_msg)
|
88
|
-
rescue Octokit::MethodNotAllowed => e
|
89
|
-
return 200, "Pull request not mergeable: #{e.message}"
|
90
|
-
end
|
91
|
-
puts merge_commit.inspect
|
92
|
-
json[:merge_sha] = merge_commit.sha
|
93
|
-
report_directory = "#{@settings['reports_dir']}/#{merge_commit.sha[0..1]}/#{merge_commit.sha[2..3]}"
|
94
|
-
report_path = "#{report_directory}/#{merge_commit.sha}.json"
|
95
|
-
if @settings['generate_reports']
|
96
|
-
FileUtils.mkdir_p report_directory
|
97
|
-
File.open(report_path, 'w') { |f| f.write(JSON.pretty_generate(json)) }
|
98
|
-
end
|
99
|
-
return 200, "merging #{pull_request_id} #{@project}"
|
100
41
|
when 'pull_request'
|
101
42
|
# If a new pull request is opened, comment with instructions
|
102
43
|
if @data['action'] == 'opened' && @settings['post_instructions']
|
103
44
|
issue = @data['number']
|
104
45
|
comment = @settings['instructions'] || "To merge at least #{@settings['plus_ones_required']} person other than the submitter needs to write a comment with saying _+1_ or :+1:. Then write _!merge_ or :shipit: to trigger the merging."
|
105
|
-
|
106
|
-
@client.add_comment(@project, issue, comment)
|
107
|
-
return 200, 'Commented!'
|
108
|
-
rescue Octokit::NotFound
|
109
|
-
return 404, 'Octokit returned 404, this could be an issue with your access token'
|
110
|
-
rescue Octokit::Unauthorized
|
111
|
-
return 401, "Authorization to #{@project} failed, please verify your access token"
|
112
|
-
rescue Octokit::TooManyLoginAttempts
|
113
|
-
return 429, "Account for #{@project} has been temporary locked down due to to many failed login attempts"
|
114
|
-
end
|
46
|
+
return post_comment(issue, comment)
|
115
47
|
else
|
116
48
|
return 200, 'Not posting instructions'
|
117
49
|
end
|
@@ -119,4 +51,107 @@ MERGE_MSG
|
|
119
51
|
return 200, "Unhandled event type #{@event}"
|
120
52
|
end
|
121
53
|
end
|
54
|
+
|
55
|
+
def maybe_merge(pull_request_id, merge_command)
|
56
|
+
votes = {}
|
57
|
+
merger = nil
|
58
|
+
pr = @client.pull_request @project, pull_request_id
|
59
|
+
|
60
|
+
unless pr.mergeable_state == 'clean'
|
61
|
+
msg = "Merge state for is not clean. Current state: #{pr.mergeable_state}\n"
|
62
|
+
reassure = "I will try to merge this for you when the builds turn green\n" +
|
63
|
+
'If your build fails or becomes stuck for some reason, just say \'rebuild\''
|
64
|
+
if merge_command
|
65
|
+
return post_comment(pull_request_id, msg + reassure)
|
66
|
+
else
|
67
|
+
return 200, msg
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# We fetch the latest commit and it's date.
|
72
|
+
last_commit = @client.pull_request_commits(@project, pull_request_id).last
|
73
|
+
last_commit_date = last_commit.commit.committer.date
|
74
|
+
|
75
|
+
comments = @client.issue_comments(@project, pull_request_id)
|
76
|
+
|
77
|
+
# Check each comment for +1 and merge comments
|
78
|
+
comments.each do |i|
|
79
|
+
# Comment is older than last commit.
|
80
|
+
# We only want to check newer comments
|
81
|
+
next if last_commit_date > i.created_at
|
82
|
+
|
83
|
+
if (i.body == '!merge' || i.body.start_with?(':shipit:'))
|
84
|
+
merger ||= i.attrs[:user]
|
85
|
+
# Count as a +1 if it is not the author
|
86
|
+
unless pr.user.login == i.attrs[:user].attrs[:login]
|
87
|
+
votes[i.attrs[:user].attrs[:login]] = 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
match = /^:?([+-])1:?/.match(i.body)
|
92
|
+
if match
|
93
|
+
score = match[1] == '+' ? 1 : -1
|
94
|
+
# pull request submitter cant +1
|
95
|
+
unless pr.user.login == i.attrs[:user].attrs[:login]
|
96
|
+
votes[i.attrs[:user].attrs[:login]] = score
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
return 200, "No merge comment found" unless merger
|
102
|
+
|
103
|
+
num_votes = votes.values.reduce(0) { |a, e| a + e }
|
104
|
+
if num_votes < @settings['plus_ones_required']
|
105
|
+
msg = "Not enough plus ones. #{@settings['plus_ones_required']} required, and only have #{num_votes}"
|
106
|
+
return post_comment(pull_request_id, msg)
|
107
|
+
end
|
108
|
+
|
109
|
+
json = { url: pr.url,
|
110
|
+
title: pr.title,
|
111
|
+
author: pr.user.login,
|
112
|
+
description: pr.body,
|
113
|
+
commits: @client.pull_request_commits(@project, pr.number).map { |c| { author: c.author, message: c.commit.message, sha: c.commit.tree.sha } },
|
114
|
+
head_sha: pr.head.sha,
|
115
|
+
tests: @client.combined_status(@project, pr.head.sha).statuses.map { |s| {state: s.state, url: s.target_url, description: s.description } },
|
116
|
+
reviewers: votes.keys,
|
117
|
+
deployer: merger }
|
118
|
+
# TODO: Word wrap description
|
119
|
+
merge_msg = <<MERGE_MSG
|
120
|
+
Title: #{pr.title}
|
121
|
+
Author: #{pr.user.login}
|
122
|
+
Reviewers: #{votes.keys.join ', '}
|
123
|
+
Deployer: #{merger}
|
124
|
+
URL: #{pr.url}
|
125
|
+
|
126
|
+
#{pr.body}
|
127
|
+
MERGE_MSG
|
128
|
+
begin
|
129
|
+
merge_commit = @client.merge_pull_request(@project, pull_request_id, merge_msg)
|
130
|
+
rescue Octokit::MethodNotAllowed => e
|
131
|
+
return post_comment(pull_request_id, "Pull request not mergeable: #{e.message}")
|
132
|
+
end
|
133
|
+
puts merge_commit.inspect
|
134
|
+
json[:merge_sha] = merge_commit.sha
|
135
|
+
report_directory = "#{@settings['reports_dir']}/#{merge_commit.sha[0..1]}/#{merge_commit.sha[2..3]}"
|
136
|
+
report_path = "#{report_directory}/#{merge_commit.sha}.json"
|
137
|
+
if @settings['generate_reports']
|
138
|
+
FileUtils.mkdir_p report_directory
|
139
|
+
File.open(report_path, 'w') { |f| f.write(JSON.pretty_generate(json)) }
|
140
|
+
end
|
141
|
+
return 200, "merging #{pull_request_id} #{@project}"
|
142
|
+
end
|
143
|
+
|
144
|
+
def post_comment(issue, comment)
|
145
|
+
begin
|
146
|
+
@client.add_comment(@project, issue, comment)
|
147
|
+
return 200, "Commented:\n" + comment
|
148
|
+
rescue Octokit::NotFound
|
149
|
+
return 404, 'Octokit returned 404, this could be an issue with your access token'
|
150
|
+
rescue Octokit::Unauthorized
|
151
|
+
return 401, "Authorization to #{@project} failed, please verify your access token"
|
152
|
+
rescue Octokit::TooManyLoginAttempts
|
153
|
+
return 429, "Account for #{@project} has been temporary locked down due to to many failed login attempts"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
122
157
|
end
|
data/tutter-sppuppet.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'tutter-sppuppet'
|
4
|
-
s.version = '0.0.
|
4
|
+
s.version = '0.0.22'
|
5
5
|
s.author = ['Johan Haals', 'Erik Dalén', 'Alexey Lapitsky']
|
6
6
|
s.email = ['johan.haals@gmail.com', 'dalen@spotify.com', 'alexey@spotify.com']
|
7
7
|
s.homepage = 'https://github.com/jhaals/tutter-sppuppet'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tutter-sppuppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Haals
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-03-
|
13
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tutter
|