tutter-sppuppet 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/tutter/action/sppuppet.rb +83 -80
- data/tutter-sppuppet.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Mjk0NzA4MTRlYzkxMzQwOWZkMTI3YmMwZTFlYjI1OTMyNmYxMmI4MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTU5NWY0NzRkNzkzYzc3MDQ1MDM5MzhmOTUxNzFhOGJjOWJlYzk5OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTljMTE1OGZhYTRkNzJlN2I4MmVhZTkyYjA2ZTI0NTJmODlkMWZlNDgzMTNj
|
10
|
+
MTBiMDg1MmI2NzA5NzZjMzM5NjY2ZTIxYzE1MTI5NTVkN2UzYzMwYzA0MDMx
|
11
|
+
YTAzZWI4ZDYyZjVjYzFjN2ExNGM4NDViNWViNWJkMTE1YjZkM2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzdkY2RkNjY1MGFkMzNiMWNiZmEzOGVkZTQ2ZmQ5ZDhmOGJjNjUyOTQwNDcy
|
14
|
+
ZTM2MDAzMzJlNjZlNDA0ZDg4MDlkNjQ1NTEyNzUyZjI1MGY1NjAxNjBiOGE4
|
15
|
+
YzRiZDI5NGNiODBmMTllMDBlM2FkNmQ2MDQ2ODk1ZmNlZGE4NTY=
|
@@ -13,89 +13,66 @@ class Sppuppet
|
|
13
13
|
@event = event
|
14
14
|
end
|
15
15
|
|
16
|
-
def debug(message)
|
17
|
-
puts message if @debug
|
18
|
-
end
|
19
|
-
|
20
16
|
def run
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@client.add_comment(@project, issue, comment)
|
27
|
-
return 200, "Commented!"
|
28
|
-
rescue Octokit::NotFound
|
29
|
-
return 404, "Octokit returned 404, this could be an issue with your access token"
|
30
|
-
rescue Octokit::Unauthorized
|
31
|
-
return 401, "Authorization to #{@project} failed, please verify your access token"
|
32
|
-
rescue Octokit::TooManyLoginAttempts
|
33
|
-
return 429, "Account for #{@project} has been temporary locked down due to to many failed login attempts"
|
17
|
+
case @event
|
18
|
+
when 'issue_comment'
|
19
|
+
if @data['action'] != 'created'
|
20
|
+
# Not a new comment, ignore
|
21
|
+
return 200, 'not a new comment, skipping'
|
34
22
|
end
|
35
|
-
end
|
36
|
-
|
37
|
-
if @data['action'] != 'created'
|
38
|
-
# Not a new comment, ignore
|
39
|
-
return 200, 'not a new comment, skipping'
|
40
|
-
end
|
41
23
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
merge = false
|
24
|
+
pull_request_id = @data['issue']['number']
|
25
|
+
pr = @client.pull_request @project, pull_request_id
|
26
|
+
plus_one = {}
|
46
27
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# No comments, no need to go further.
|
52
|
-
if pr.comments == 0
|
53
|
-
return 200, 'no comments, skipping'
|
54
|
-
end
|
28
|
+
unless pr.mergeable
|
29
|
+
return 200, "merge state for #{@project} #{pull_request_id} is not clean. Current state: #{pr.mergeable_state}"
|
30
|
+
end
|
55
31
|
|
56
|
-
|
57
|
-
|
32
|
+
# No comments, no need to go further.
|
33
|
+
return 200, 'no comments, skipping' if pr.comments == 0
|
58
34
|
|
59
|
-
|
60
|
-
|
61
|
-
|
35
|
+
# We fetch the latest commit and it's date.
|
36
|
+
last_commit = @client.pull_request_commits(@project, pull_request_id).last
|
37
|
+
last_commit_date = last_commit.commit.committer.date
|
62
38
|
|
63
|
-
|
39
|
+
comments = @client.issue_comments(@project, pull_request_id)
|
64
40
|
|
65
|
-
|
66
|
-
|
41
|
+
# Check each comment for +1 and merge comments
|
42
|
+
comments.each do |i|
|
67
43
|
|
68
|
-
|
69
|
-
|
44
|
+
# Comment is older than last commit. We only want to check for +1 in newer comments
|
45
|
+
next if last_commit_date > i.created_at
|
70
46
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
47
|
+
if /^(\+1|:\+1)/.match i.body
|
48
|
+
# pull request submitter cant +1
|
49
|
+
unless pr.user.login == i.attrs[:user].attrs[:login]
|
50
|
+
plus_one[i.attrs[:user].attrs[:login]] = 1
|
51
|
+
end
|
75
52
|
end
|
76
|
-
end
|
77
53
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
54
|
+
# TODO it should calculate the +1's - the -1's
|
55
|
+
# Never merge if someone says -1
|
56
|
+
if /^(\-1|:\-1:)/.match i.body
|
57
|
+
return 200, "#{@project} #{pull_request_id} has a -1. I will not take the blame"
|
58
|
+
end
|
82
59
|
end
|
83
|
-
end
|
84
|
-
|
85
|
-
merge = (comments.last.body == '!merge' || comments.last.body.start_with?(':shipit:'))
|
86
60
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
61
|
+
merge = (@data['comment']['body'] == '!merge' ||
|
62
|
+
@data['comment']['body'].start_with?(':shipit:'))
|
63
|
+
|
64
|
+
if plus_one.count >= @settings['plus_ones_required'] && merge
|
65
|
+
json = { url: pr.url,
|
66
|
+
title: pr.title,
|
67
|
+
author: pr.user.login,
|
68
|
+
description: pr.body,
|
69
|
+
commits: @client.pull_request_commits(@project, pr.number).map { |c| { author: c.author, message: c.commit.message, sha: c.commit.tree.sha } },
|
70
|
+
head_sha: pr.head.sha,
|
71
|
+
tests: @client.combined_status(@project, pr.head.sha).statuses.map { |s| {state: s.state, url: s.target_url, description: s.description } },
|
72
|
+
reviewers: plus_one.keys,
|
73
|
+
deployer: comments.last.user.login }
|
74
|
+
# TODO: Word wrap description
|
75
|
+
merge_msg = <<MERGE_MSG
|
99
76
|
Title: #{pr.title}
|
100
77
|
Description: #{pr.body}
|
101
78
|
Author: #{pr.user.login}
|
@@ -103,19 +80,45 @@ Reviewers: #{plus_one.keys.join ', '}
|
|
103
80
|
Deployer: #{comments.last.user.login}
|
104
81
|
URL: #{pr.url}
|
105
82
|
MERGE_MSG
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
83
|
+
begin
|
84
|
+
merge_commit = @client.merge_pull_request(@project, pull_request_id, merge_msg)
|
85
|
+
rescue Octokit::MethodNotAllowed => e
|
86
|
+
return 200, "Pull request not mergeable: #{e.message}"
|
87
|
+
end
|
88
|
+
puts merge_commit.inspect
|
89
|
+
json[:merge_sha] = merge_commit.sha
|
90
|
+
report_directory = "#{@settings['reports_dir']}/#{merge_commit.sha[0..1]}/#{merge_commit.sha[2..3]}"
|
91
|
+
report_path = "#{report_directory}/#{merge_commit.sha}.json"
|
92
|
+
if @settings['generate_reports']
|
93
|
+
FileUtils.mkdir_p report_directory
|
94
|
+
File.open(report_path, 'w') { |f| f.write(JSON.pretty_generate(json)) }
|
95
|
+
end
|
96
|
+
return 200, "merging #{pull_request_id} #{@project}"
|
97
|
+
elsif plus_one.count >= @settings['plus_ones_required']
|
98
|
+
return 200, "have enough +1, but no merge command"
|
99
|
+
else
|
100
|
+
return 200, "not enough +1, have #{plus_one.count} but need #{@settings['plus_ones_required']}"
|
101
|
+
end
|
102
|
+
when 'pull_request'
|
103
|
+
# If a new pull request is opened, comment with instructions
|
104
|
+
if @data['action'] == 'opened' && @settings['post_instructions']
|
105
|
+
issue = @data['number']
|
106
|
+
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."
|
107
|
+
begin
|
108
|
+
@client.add_comment(@project, issue, comment)
|
109
|
+
return 200, "Commented!"
|
110
|
+
rescue Octokit::NotFound
|
111
|
+
return 404, "Octokit returned 404, this could be an issue with your access token"
|
112
|
+
rescue Octokit::Unauthorized
|
113
|
+
return 401, "Authorization to #{@project} failed, please verify your access token"
|
114
|
+
rescue Octokit::TooManyLoginAttempts
|
115
|
+
return 429, "Account for #{@project} has been temporary locked down due to to many failed login attempts"
|
116
|
+
end
|
117
|
+
else
|
118
|
+
return 200, 'Not posting instructions'
|
113
119
|
end
|
114
|
-
return 200, "merging #{pull_request_id} #{@project}"
|
115
|
-
elsif plus_one.count >= @settings['plus_ones_required']
|
116
|
-
return 200, "have enough +1, but no merge command"
|
117
120
|
else
|
118
|
-
return 200, "
|
121
|
+
return 200, "Unhandled event type #{@event}"
|
119
122
|
end
|
120
123
|
end
|
121
124
|
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.18'
|
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'
|