tutter-jenkins 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/.gemspec +1 -1
  3. data/lib/tutter/action/jenkins.rb +22 -17
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzdiODU5OTQ1OTM2ZDU2NmYwZGU4YzFkOWQyYjBiMTUyOWZjMjI3YQ==
4
+ MWJmNDY3MWFmZjg2MDYyOWU3NzY3OWQ4YmY2NDZmOWFhZjI4ZjdkNQ==
5
5
  data.tar.gz: !binary |-
6
- NmExMTg2YTE3NjczZmUzMDVmNWIwZjZlYWRlMTJjMWYzMDk0MDUwYw==
6
+ MDk5MzhkY2E4YmZiNGQyYWQyNmI2N2U2ZmUzNGZjZDcwZTFhNDA5Mw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2U4ZWNhNTc2Zjk5MDI4ZmQzN2QwMzlhOTdkMDgxYWVlMDAzNDA5Mzk0MmIx
10
- NjZmYzcyMDBkMTU2YzI2ZDgwNjUyYWYwNDk0MTQxMWFlNDEyZGQ4MGI4OWRm
11
- MDZjZGMwYTBhMjZiNGI1MTlhNmQ3ZGY1MTgwMmUyOThiNzY1ZmI=
9
+ MTJkMDFjYzI4ZDkyY2FkMjczNzkzYjc0MGNhYzczZjg1YjFmYTY1NmJhNjVi
10
+ YjQ3MDlmYjExZjRhZTFkZjAyODdkZGFmYjllMGE0MmEzNzEwZjBiMjhlZjAy
11
+ ZjVjZWFjMDMwZDNhYjI0ZThmNDAyYzZlZjZjMjJlMDRhMDlkODE=
12
12
  data.tar.gz: !binary |-
13
- OTZjMmEyZDY4MGIyNTU3ZmNlYzRmMmQyN2M5ZGM5MzliZTAwMzg4M2ViM2Yw
14
- YmU0ZThkOGI3YjM4MzZiNzc5MTNlMTY3ZmEwZjg4NzlmMTExMTBmYTE4MWYx
15
- OWI5NzhkYTUyNzk2ZTBjMDEzMzFlMzFhZDhhMDkxMGIzZTk2YWI=
13
+ NTA2Njk1MTY2MThlMzk0Nzk3NzJlNzkwOWNkNjBhZGM3N2ZkZGI3NGZhYTVm
14
+ MTlhMjBhYjNmZTQwZWQ4MzgzNzkxN2FmNzQ1NWIxMTc4MmUxMzVhNmU5NDA1
15
+ MDRiZDAyZmFlYjhhZjg0MGM1NmQxMjZkNzUyZTFjZTBiMDgzNWE=
data/.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'tutter-jenkins'
4
- s.version = '0.0.1'
4
+ s.version = '0.0.2'
5
5
  s.author = 'Alexey Lapitsky'
6
6
  s.email = ['alexey@spotify.com']
7
7
  s.homepage = 'https://ghe.spotify.net/io/tutter-jenkins'
@@ -1,48 +1,53 @@
1
1
  class Jenkins
2
2
  def initialize(settings, client, project, data)
3
- @settings = settings
3
+ @settings = settings || {}
4
4
  @client = client
5
5
  @project = project
6
6
  @data = data
7
+ @merge_request_comment = @settings['merge_request_comment']
8
+ @merge_request_comment ||= 'merge, my change is covered by tests'
7
9
  end
8
10
 
9
11
  def run
10
12
  pull_request_id = @data['issue']['number']
11
13
  puts "pull request id: #{pull_request_id}"
12
- pr = @client.pull_request @project, pull_request_id
13
14
 
14
- if pr.mergeable_state != 'clean'
15
- puts "merge state for #{@project} #{pull_request_id} is not clean. Current state: #{pr.mergeable_state}"
15
+ comments = @client.issue_comments(@project, pull_request_id)
16
+ last_comment = comments.last
17
+
18
+ asked_to_merge = last_comment && last_comment.body.strip.downcase == @merge_request_comment.strip.downcase
19
+ unless asked_to_merge
20
+ puts "not asked to merge"
16
21
  return false
17
22
  end
18
23
 
19
- # No comments, no need to go further.
20
- if pr.comments == 0
21
- puts 'no comments, skipping'
24
+ pr = @client.pull_request @project, pull_request_id
25
+ if pr.mergeable_state != 'clean'
26
+ @client.add_comment(@project, pull_request_id, "Please rebase your change, merge state is #{pr.mergeable_state}")
22
27
  return false
23
28
  end
24
29
 
25
- # Don't care about code we can't merge
26
30
  unless pr.mergeable
27
- puts 'not mergeable, skipping'
31
+ @client.add_comment(@project, pull_request_id, "Please rebase your change, pull request is not mergeable")
28
32
  return false
29
33
  end
30
34
 
31
- # We fetch the latest commit and it's date.
32
35
  last_commit = @client.pull_request_commits(@project, pull_request_id).last
33
36
  last_commit_date = last_commit.commit.committer.date
34
37
 
35
- comments = @client.issue_comments(@project, pull_request_id)
38
+ if last_comment.created_at < last_commit_date
39
+ @client.add_comment(@project, pull_request_id, "Please reopen pull request, found a new commit")
40
+ return false
41
+ end
42
+
36
43
  jenkins_last_comment = @client.issue_comments(@project, pull_request_id).select{|c| c.attrs[:user].attrs[:login] == 'jenkins'}.last
37
44
  jenkins_allows_merge = jenkins_last_comment && jenkins_last_comment.body =~ /PASS/
38
45
 
39
46
  if jenkins_allows_merge
40
- puts "the last comment from jenkins allows the merge"
41
- last_comment = comments.last
42
- if last_comment.created_at > last_commit_date && last_comment.body.strip.downcase == 'merge, my change is covered by tests'
43
- puts "merging #{pull_request_id} #{@project}"
44
- @client.merge_pull_request(@project, pull_request_id, 'ok, shipping!')
45
- end
47
+ puts "merging #{pull_request_id} #{@project}"
48
+ @client.merge_pull_request(@project, pull_request_id, 'ok, shipping!')
49
+ else
50
+ @client.add_comment(@project, pull_request_id, "Please make sure tests pass")
46
51
  end
47
52
  end
48
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tutter-jenkins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Lapitsky