tutter-sppuppet 0.0.18 → 0.0.19

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
- Mjk0NzA4MTRlYzkxMzQwOWZkMTI3YmMwZTFlYjI1OTMyNmYxMmI4MA==
4
+ MjA4YjAxMWIwYjI2ZmJkZmE2YjljMTVjMzgxMDBiMDQxYzYyZTVjZQ==
5
5
  data.tar.gz: !binary |-
6
- NTU5NWY0NzRkNzkzYzc3MDQ1MDM5MzhmOTUxNzFhOGJjOWJlYzk5OA==
6
+ Y2M5NGY1YzFlYjI0ZjA4MTM2OTFiYjdjN2M4Yjk1NTBkMzI1MmZkZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTljMTE1OGZhYTRkNzJlN2I4MmVhZTkyYjA2ZTI0NTJmODlkMWZlNDgzMTNj
10
- MTBiMDg1MmI2NzA5NzZjMzM5NjY2ZTIxYzE1MTI5NTVkN2UzYzMwYzA0MDMx
11
- YTAzZWI4ZDYyZjVjYzFjN2ExNGM4NDViNWViNWJkMTE1YjZkM2Y=
9
+ ZmU2YmJlOGExNmFjZjVlMGE4ZWMzYzRmY2EwOTg1MmZmZGY5MjhjMzVhMTBk
10
+ YjBlYzkyZmZiZDZjYTYwNWE0ZTczYzIxODkyYzI4NDdmMmRkNmU5MmQ4NjVm
11
+ M2JiNmJlYTk5ZTE0ODdjNWRiZjZkNDMzN2Q1ZTRiZjVjNGMxMDA=
12
12
  data.tar.gz: !binary |-
13
- NzdkY2RkNjY1MGFkMzNiMWNiZmEzOGVkZTQ2ZmQ5ZDhmOGJjNjUyOTQwNDcy
14
- ZTM2MDAzMzJlNjZlNDA0ZDg4MDlkNjQ1NTEyNzUyZjI1MGY1NjAxNjBiOGE4
15
- YzRiZDI5NGNiODBmMTllMDBlM2FkNmQ2MDQ2ODk1ZmNlZGE4NTY=
13
+ NjJmY2Q1OWM5ZDU5NGU0YWM3ZTJiNTljYjVmMzUzODZkMjA2MmIwNDc0OWI0
14
+ NGVmZGNhNzhmZmFmZjJlMWUxMzk5OGJjNzBhNmJlOTNiZGE4MzZiMDhkOTU4
15
+ Y2ZlOWY5ZTQwNDBjNWNkZWI1MDBkMTZkMWE1YWMxMGYxYjg0ODU=
@@ -23,14 +23,18 @@ class Sppuppet
23
23
 
24
24
  pull_request_id = @data['issue']['number']
25
25
  pr = @client.pull_request @project, pull_request_id
26
- plus_one = {}
26
+ votes = {}
27
27
 
28
- unless pr.mergeable
29
- return 200, "merge state for #{@project} #{pull_request_id} is not clean. Current state: #{pr.mergeable_state}"
30
- end
28
+ merge = (@data['comment']['body'] == '!merge' ||
29
+ @data['comment']['body'].start_with?(':shipit:'))
30
+
31
+ return 200, 'Not a merge comment' unless merge
31
32
 
32
- # No comments, no need to go further.
33
- return 200, 'no comments, skipping' if pr.comments == 0
33
+ unless pr.mergeable_state == 'clean'
34
+ msg = "Merge state for #{@project} #{pull_request_id} is not clean. Current state: #{pr.mergeable_state}"
35
+ @client.add_comment(@project, pull_request_id, msg)
36
+ return 200, msg
37
+ end
34
38
 
35
39
  # We fetch the latest commit and it's date.
36
40
  last_commit = @client.pull_request_commits(@project, pull_request_id).last
@@ -40,39 +44,38 @@ class Sppuppet
40
44
 
41
45
  # Check each comment for +1 and merge comments
42
46
  comments.each do |i|
43
-
44
- # Comment is older than last commit. We only want to check for +1 in newer comments
47
+ # Comment is older than last commit.
48
+ # We only want to check for +1 in newer comments
45
49
  next if last_commit_date > i.created_at
46
50
 
47
- if /^(\+1|:\+1)/.match i.body
51
+ match = /^:?([+-])1:?/.match(i.body)
52
+ if match
53
+ score = match[1] == '+' ? 1 : -1
48
54
  # pull request submitter cant +1
49
55
  unless pr.user.login == i.attrs[:user].attrs[:login]
50
- plus_one[i.attrs[:user].attrs[:login]] = 1
56
+ votes[i.attrs[:user].attrs[:login]] = score
51
57
  end
52
58
  end
53
-
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
59
59
  end
60
60
 
61
- merge = (@data['comment']['body'] == '!merge' ||
62
- @data['comment']['body'].start_with?(':shipit:'))
61
+ num_votes = votes.values.reduce(0) { |a, e| a + e }
62
+ if num_votes < @settings['plus_ones_required']
63
+ msg = "Not enough plus ones. #{@settings['plus_ones_required']} required, and only have #{num_votes}"
64
+ @client.add_comment(@project, pull_request_id, msg)
65
+ return 200, msg
66
+ end
63
67
 
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
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: plus_one.keys,
76
+ deployer: comments.last.user.login }
77
+ # TODO: Word wrap description
78
+ merge_msg = <<MERGE_MSG
76
79
  Title: #{pr.title}
77
80
  Description: #{pr.body}
78
81
  Author: #{pr.user.login}
@@ -80,25 +83,20 @@ Reviewers: #{plus_one.keys.join ', '}
80
83
  Deployer: #{comments.last.user.login}
81
84
  URL: #{pr.url}
82
85
  MERGE_MSG
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']}"
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)) }
101
98
  end
99
+ return 200, "merging #{pull_request_id} #{@project}"
102
100
  when 'pull_request'
103
101
  # If a new pull request is opened, comment with instructions
104
102
  if @data['action'] == 'opened' && @settings['post_instructions']
@@ -106,9 +104,9 @@ MERGE_MSG
106
104
  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
105
  begin
108
106
  @client.add_comment(@project, issue, comment)
109
- return 200, "Commented!"
107
+ return 200, 'Commented!'
110
108
  rescue Octokit::NotFound
111
- return 404, "Octokit returned 404, this could be an issue with your access token"
109
+ return 404, 'Octokit returned 404, this could be an issue with your access token'
112
110
  rescue Octokit::Unauthorized
113
111
  return 401, "Authorization to #{@project} failed, please verify your access token"
114
112
  rescue Octokit::TooManyLoginAttempts
@@ -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.18'
4
+ s.version = '0.0.19'
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.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Haals