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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzFmOWE1OWUyNTMyM2M1MTZjNzRkYjNjM2EzMTFjOWY4MDRlZDQzYg==
4
+ Mjk0NzA4MTRlYzkxMzQwOWZkMTI3YmMwZTFlYjI1OTMyNmYxMmI4MA==
5
5
  data.tar.gz: !binary |-
6
- ZGJmNjZiY2EwNDQ2ZWU5NGE3MTA0NzI2NGVjYTAyZTZmY2UxODU4NA==
6
+ NTU5NWY0NzRkNzkzYzc3MDQ1MDM5MzhmOTUxNzFhOGJjOWJlYzk5OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTJmZmFiNDJkMDUwMTJmZjZhZmY0NTBhMDFhYjc3YTBhY2Y0Y2NkOTY5MmM5
10
- ZjYwNTFjMWYyMmI2ZTMxOTEyOTc5MmJhYzcwOTE2NTBhNzZmZWM5NjQ5ZmE3
11
- MzEzZTA5NmE4NTc0ZTRiNmY5YTcxNzA5OTlkYzdkMjM2NzVjMDg=
9
+ YTljMTE1OGZhYTRkNzJlN2I4MmVhZTkyYjA2ZTI0NTJmODlkMWZlNDgzMTNj
10
+ MTBiMDg1MmI2NzA5NzZjMzM5NjY2ZTIxYzE1MTI5NTVkN2UzYzMwYzA0MDMx
11
+ YTAzZWI4ZDYyZjVjYzFjN2ExNGM4NDViNWViNWJkMTE1YjZkM2Y=
12
12
  data.tar.gz: !binary |-
13
- NTRlOTFjOTFmYjJlNDM4OWUyOGI0MzIzMDg0NWYwYjkzZjlmMTE0MDEwYTA4
14
- Yjg3YWQ4M2ZhMzA0YzA5Mzk5YTYyMjdlM2U1YTRhYzA0MWZjZmZhNDNlMjA1
15
- ZGQ4MDgzNWY1MTlkMTk0MmYxMjU3NDU3ZTUyNTUwYTNjODY0ZGM=
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
- # If a new pull request is opened, comment with instructions
22
- if @data['action'] == 'opened' && @settings['post_instructions']
23
- issue = @data['number']
24
- 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."
25
- begin
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
- pull_request_id = @data['issue']['number']
43
- pr = @client.pull_request @project, pull_request_id
44
- plus_one = {}
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
- if pr.mergeable_state != 'clean'
48
- return 200, "merge state for #{@project} #{pull_request_id} is not clean. Current state: #{pr.mergeable_state}"
49
- end
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
- # Don't care about code we can't merge
57
- return 200, 'merge state not clean' unless pr.mergeable
32
+ # No comments, no need to go further.
33
+ return 200, 'no comments, skipping' if pr.comments == 0
58
34
 
59
- # We fetch the latest commit and it's date.
60
- last_commit = @client.pull_request_commits(@project, pull_request_id).last
61
- last_commit_date = last_commit.commit.committer.date
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
- comments = @client.issue_comments(@project, pull_request_id)
39
+ comments = @client.issue_comments(@project, pull_request_id)
64
40
 
65
- # Check each comment for +1 and merge comments
66
- comments.each do |i|
41
+ # Check each comment for +1 and merge comments
42
+ comments.each do |i|
67
43
 
68
- # Comment is older than last commit. We only want to check for +1 in newer comments
69
- next if last_commit_date > i.created_at
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
- if /^(\+1|:\+1)/.match i.body
72
- # pull request submitter cant +1
73
- unless pr.user.login == i.attrs[:user].attrs[:login]
74
- plus_one[i.attrs[:user].attrs[:login]] = 1
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
- # TODO it should calculate the +1's - the -1's
79
- # Never merge if someone says -1
80
- if /^(\-1|:\-1:)/.match i.body
81
- return 200, "#{@project} #{pull_request_id} has a -1. I will not take the blame"
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
- if plus_one.count >= @settings['plus_ones_required'] && merge
88
- json = { url: pr.url,
89
- title: pr.title,
90
- author: pr.user.login,
91
- description: pr.body,
92
- commits: @client.pull_request_commits(@project, pr.number).map { |c| { author: c.author, message: c.commit.message, sha: c.commit.tree.sha } },
93
- head_sha: pr.head.sha,
94
- tests: @client.combined_status(@project, pr.head.sha).statuses.map { |s| {state: s.state, url: s.target_url, description: s.description } },
95
- reviewers: plus_one.keys,
96
- deployer: comments.last.user.login }
97
- # TODO: Word wrap description
98
- merge_msg = <<MERGE_MSG
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
- merge_commit = @client.merge_pull_request(@project, pull_request_id, merge_msg)
107
- json[:merge_sha] = merge_commit.sha
108
- report_directory = "#{@settings['reports_dir']}/#{merge_commit.sha[0..1]}/#{merge_commit.sha[2..3]}"
109
- report_path = "#{report_directory}/#{merge_commit.sha}.json"
110
- if @settings['generate_reports']
111
- FileUtils.mkdir_p report_directory
112
- File.open(report_path, 'w') { |f| f.write(JSON.pretty_generate(json)) }
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, "not enough +1, have #{plus_one.count} but need #{@settings['plus_ones_required']}"
121
+ return 200, "Unhandled event type #{@event}"
119
122
  end
120
123
  end
121
124
  end
@@ -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.17'
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'
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.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Haals