tutter-sppuppet 1.1.5 → 1.2.0

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
- YmUyNzAyYWM5NTYxOTZiYzgyYjY5ZWM2Zjk4MzNkOGRiY2FhZjczMw==
4
+ NzJiZTJkNjNlYjc3NzJkYWY1ZDNlNTdmMTA3ZGUwODRkNTI4ZGIzYw==
5
5
  data.tar.gz: !binary |-
6
- Mzk1ODNkODJjNTBkMjZhYTgxOGY2MTgyM2E5YzliZTZjN2M3Zjg0YQ==
6
+ Y2U5ODIzZmRmNGQ2YzZhNThmOGY0ZTNjODEyN2NmYTExY2ZiODYxMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzIxNzQyMzQ4OWUxMjJhOTVhYzUzZTc3ZGFkYTY3ZDc4ZTEwMmEyZGFhMjk5
10
- ODlmMGRhZjMwNGU2MWFlMzA0MDZiZTA4ZGIzN2U4OGJjYjhmMzMyOTQ3OTA3
11
- OGRmZWNiM2Q2ZDRkZWEwNTQwYjIwZGE3YzkzMjMyNGE2NGNiODE=
9
+ OGIxMDM2NDAyN2NmNWFiM2MzYmU1N2UyODhkZGZjMWNiZDFkMzNlZDhiY2Vj
10
+ MTk5NzRkOGM0YjhhOGEyMzM2ZTQ4MzIyN2YwZDA4MTc5YTMxOWJhZWI2NGI4
11
+ ZWVlODVlNmM0YTUyNzlkZWUxODA0N2I2NGI4YWU5NzY5OWE4MmE=
12
12
  data.tar.gz: !binary |-
13
- NjkxODI5MmU5MDYyYmU5ZmIyMWMxYTRjNDgzZTgyYmVmOTMyZTQxMTJiN2E5
14
- MGIxMjZlYWI4NDUzMjdiZTFkZDJmMDZkMTQ2YmM3MTRhYmQ1ODRhMDcwZmNl
15
- ZDhiMDU2NjEzM2EzMTg5NTQ5OWI5ZTU0YjIxYjVlZWFmOWU4NjU=
13
+ MDYwMjYzMzhkYTdhZjc3ZTIxODYxNjc4MWUwNjE3Y2RmOTIyNTU2N2YxNTcy
14
+ YzBhMGU4NWRiZjZhMDFlMzk1YjYwMzE1ZjdhNjlkNDE0ODk5OGI4MDA0ZmE1
15
+ YTRmY2I2ODNlMGMyM2FjY2U4YWJmZGExMzFiMWE2NmRhZjI3YzM=
data/README.md CHANGED
@@ -23,8 +23,6 @@ sppuppet specific settings (goes into tutter.yaml)
23
23
  plus_ones_required: 3
24
24
  post_instructions: true
25
25
  instructions: 'To merge, post 3 +1s and then !merge'
26
- generate_reports: true
27
- reports_dir: '/var/lib/tutter/reports'
28
26
 
29
27
  ### TODO
30
28
  * whitelist
@@ -2,11 +2,16 @@ require 'fileutils'
2
2
  require 'json'
3
3
 
4
4
  class Sppuppet
5
+ # Match regexps
6
+ MERGE_COMMENT = /(:shipit:|:ship:|!merge)/
7
+ PLUS_VOTE = /(:+1:|^\+1|^LGTM)/
8
+ MINUS_VOTE = /(:-1:|^-1)/
9
+ BLOCK_VOTE = /^(:poop:|:hankey:|-2)/ # Blocks merge
10
+ INCIDENT = /jira.*INCIDENT/
5
11
 
6
12
  def initialize(settings, client, project, data, event)
7
13
  @settings = settings
8
14
  @settings['plus_ones_required'] ||= 1
9
- @settings['reports_dir'] ||= '/var/lib/tutter/reports'
10
15
  @client = client
11
16
  @project = project
12
17
  @data = data
@@ -23,12 +28,11 @@ class Sppuppet
23
28
 
24
29
  pull_request_id = @data['issue']['number']
25
30
 
26
- merge_command = (@data['comment']['body'] == '!merge' ||
27
- @data['comment']['body'].start_with?(':shipit:'))
31
+ merge_command = MERGE_COMMENT.match @data['comment']['body']
28
32
 
29
33
  return 200, 'Not a merge comment' unless merge_command
30
34
 
31
- return maybe_merge(pull_request_id, true)
35
+ return maybe_merge(pull_request_id, true, @data['sender']['login'])
32
36
 
33
37
  when 'status'
34
38
  return 200, 'Merge state not clean' unless @data['state'] == 'success'
@@ -52,9 +56,8 @@ class Sppuppet
52
56
  end
53
57
  end
54
58
 
55
- def maybe_merge(pull_request_id, merge_command)
59
+ def maybe_merge(pull_request_id, merge_command, merger = nil)
56
60
  votes = {}
57
- merger = nil
58
61
  incident_merge_override = false
59
62
  pr = @client.pull_request @project, pull_request_id
60
63
 
@@ -70,7 +73,7 @@ class Sppuppet
70
73
  # We only want to check newer comments
71
74
  next if last_commit_date > i.created_at
72
75
 
73
- if i.body == '!merge' || i.body.start_with?(':shipit:') || i.body.start_with?(':ship:')
76
+ if MERGE_COMMENT.match i.body
74
77
  merger ||= i.attrs[:user].attrs[:login]
75
78
  # Count as a +1 if it is not the author
76
79
  unless pr.user.login == i.attrs[:user].attrs[:login]
@@ -78,22 +81,20 @@ class Sppuppet
78
81
  end
79
82
  end
80
83
 
81
- match = /^(:?([+-])1:?|LGTM)/.match(i.body)
82
- if match
83
- score = match[2] == '-' ? -1 : 1
84
- # pull request submitter cant +1
85
- unless pr.user.login == i.attrs[:user].attrs[:login]
86
- votes[i.attrs[:user].attrs[:login]] = score
87
- end
84
+ if PLUS_VOTE.match i.body && pr.user.login != i.attrs[:user].attrs[:login]
85
+ votes[i.attrs[:user].attrs[:login]] = 1
88
86
  end
89
87
 
90
- match = /^(:poop:|:hankey:|-2)/.match(i.body)
91
- if match
92
- msg = "Commit cannot be merged so long as a -2 comment appears in the PR."
88
+ if MINUS_VOTE.match i.body && pr.user.login != i.attrs[:user].attrs[:login]
89
+ votes[i.attrs[:user].attrs[:login]] = -1
90
+ end
91
+
92
+ if BLOCK_VOTE.match i.body
93
+ msg = 'Commit cannot be merged so long as a -2 comment appears in the PR.'
93
94
  return post_comment(pull_request_id, msg)
94
95
  end
95
96
 
96
- if /jira.*INCIDENT/.match(i.body)
97
+ if INCIDENT.match(i.body)
97
98
  incident_merge_override = true
98
99
  end
99
100
  end
@@ -118,15 +119,6 @@ class Sppuppet
118
119
  return post_comment(pull_request_id, msg)
119
120
  end
120
121
 
121
- json = { url: pr.url,
122
- title: pr.title,
123
- opened_by: pr.user.login,
124
- description: pr.body,
125
- commits: @client.pull_request_commits(@project, pr.number).map { |c| { author: c.author, message: c.commit.message, sha: c.commit.tree.sha } },
126
- head_sha: pr.head.sha,
127
- tests: @client.combined_status(@project, pr.head.sha).statuses.map { |s| {state: s.state, url: s.target_url, description: s.description } },
128
- reviewers: votes.keys,
129
- deployer: merger }
130
122
  # TODO: Word wrap description
131
123
  merge_msg = <<MERGE_MSG
132
124
  Title: #{pr.title}
@@ -146,14 +138,6 @@ MERGE_MSG
146
138
  rescue Octokit::MethodNotAllowed => e
147
139
  return post_comment(pull_request_id, "Pull request not mergeable: #{e.message}")
148
140
  end
149
- puts merge_commit.inspect
150
- json[:merge_sha] = merge_commit.sha
151
- report_directory = "#{@settings['reports_dir']}/#{merge_commit.sha[0..1]}/#{merge_commit.sha[2..3]}"
152
- report_path = "#{report_directory}/#{merge_commit.sha}.json"
153
- if @settings['generate_reports']
154
- FileUtils.mkdir_p report_directory
155
- File.open(report_path, 'w') { |f| f.write(JSON.pretty_generate(json)) }
156
- end
157
141
  return 200, "merging #{pull_request_id} #{@project}"
158
142
  end
159
143
 
@@ -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 = '1.1.5'
4
+ s.version = '1.2.0'
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: 1.1.5
4
+ version: 1.2.0
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-10-16 00:00:00.000000000 Z
13
+ date: 2015-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: tutter