lita-buildkite 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f2d6d1cbb193523fc730a4fca088c95df973b850
4
- data.tar.gz: 0c7b5cb7886c4d1c158b171a4ede9691ee44cbc6
2
+ SHA256:
3
+ metadata.gz: 953eff0635c21e6f0ba534ae8f83f2e03f25e8bb3601df454ab4a6a4deba7884
4
+ data.tar.gz: 3445aeec102832ad704e80e1dee4be328d22cc40311956bea6fa8d5966f8c3af
5
5
  SHA512:
6
- metadata.gz: bc9b1cd17771c91682069cb3b95055bc3d5297ee9b1ce3e38f09ff4e12097f3d38ce7fe230a8ec26df5a25bbab2cec313e6b422df6455172b0d49c2957a19620
7
- data.tar.gz: f5aa95d1bafa05f914d192e4ee24ddd059454028ddfc67fc752d3ce7ebfd076be65aab089ac06ebe832bb6943cd3e6787a6e57101f556513730679babbfb9a90
6
+ metadata.gz: b8f366eba228d5c038f4e101c51fdcac0865ffa878af7fb0a55e5bda3196d27e8ac53b06f1c540bad6a218b96040b29f34d98788a716488abff1b65d67994104
7
+ data.tar.gz: f2937b54070e20ae5364ba75d97b884fe05cb3177c5a51c4f00803fe26df3e6804dc93b3a5cb6301bd82de91ef233982def94b99a3c4d5f8d6c969fbd7b32ba6
@@ -0,0 +1,26 @@
1
+ class BuildStatusReport
2
+ def initialize(event, days_since_last_failure, prev_days_since_last_failure, most_successful_days)
3
+ @event = event
4
+ @days_since_last_failure = days_since_last_failure
5
+ @prev_days_since_last_failure = prev_days_since_last_failure
6
+ @most_successful_days = most_successful_days
7
+
8
+ yield message if message
9
+ end
10
+
11
+ private
12
+
13
+ def message
14
+ @message ||= begin
15
+ if @days_since_last_failure > @prev_days_since_last_failure
16
+ "#{@event.pipeline} is #{@days_since_last_failure} days without a failure"
17
+ elsif @days_since_last_failure < @prev_days_since_last_failure
18
+ if @prev_days_since_last_failure >= @most_successful_days
19
+ "#{@event.pipeline} ended it's record breaking run of #{@prev_days_since_last_failure} days without a failure 😢"
20
+ else
21
+ "#{@event.pipeline} failed after #{@prev_days_since_last_failure} days, previous best was #{@most_successful_days}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -29,6 +29,10 @@ class BuildkiteBuildFinishedEvent
29
29
  @data.fetch("pipeline", {}).fetch("slug", "")
30
30
  end
31
31
 
32
+ def build_web_url
33
+ @data.fetch("build", {}).fetch("web_url", "")
34
+ end
35
+
32
36
  def passed?
33
37
  @data.fetch("build", {}).fetch("state", "") == "passed"
34
38
  end
@@ -24,16 +24,15 @@ module Lita
24
24
  private
25
25
 
26
26
  def process_build_finished(event, &block)
27
- repository = DaysSinceMasterFailureRepository.new(redis, event.pipeline)
28
- repository.record_result(event.passed?) do |days_since_last_failure, prev_days_since_last_failure|
29
- if days_since_last_failure < prev_days_since_last_failure
30
- yield "Oh Oh, #{days_since_last_failure} day(s) since the last master failure on #{event.pipeline}"
31
- elsif days_since_last_failure > prev_days_since_last_failure
32
- yield "Congratulations! #{days_since_last_failure} day(s) since the last master failure on #{event.pipeline}"
33
- end
27
+ repository(event).record_result(event) do |message|
28
+ yield message
34
29
  end
35
30
  end
36
31
 
32
+ def repository(event)
33
+ DaysSinceMasterFailureRepository.new(redis, event.pipeline)
34
+ end
35
+
37
36
  def target
38
37
  Source.new(room: Lita::Room.find_by_name(config.channel_name) || "general")
39
38
  end
@@ -1,3 +1,5 @@
1
+ require 'lita/build_status_report'
2
+
1
3
  # Provides all persistence logic for the DaysSinceMasterFailure handler, insulating
2
4
  # the handler from any knowledge of redis
3
5
  class DaysSinceMasterFailureRepository
@@ -5,18 +7,29 @@ class DaysSinceMasterFailureRepository
5
7
  @redis = redis
6
8
  @last_failure_key = "last-failure-at-#{pipeline_name}"
7
9
  @last_reported_days_key = "last-reported-days-#{pipeline_name}"
10
+ @most_successful_days_key = "most-successful-days-#{pipeline_name}"
8
11
 
9
12
  initialise_last_failure_at_if_not_set
13
+ initialise_most_successful_days_if_not_set
10
14
  end
11
15
 
12
- def record_result(success, &block)
13
- touch_last_failure_at if !success
14
- yield days_since_last_failure, last_reported_days
16
+ def record_result(event, &block)
17
+ touch_last_failure_at if !event.passed?
18
+ touch_most_successful_days if !event.passed? && new_record?
19
+
20
+ BuildStatusReport.new(event, days_since_last_failure, last_reported_days, most_successful_days) do |message|
21
+ yield message
22
+ end
23
+
15
24
  touch_last_reported_days
16
25
  end
17
26
 
18
27
  private
19
28
 
29
+ def new_record?
30
+ last_reported_days > most_successful_days
31
+ end
32
+
20
33
  def seconds_to_days(secs)
21
34
  secs.to_i / 60 / 60 / 24
22
35
  end
@@ -33,6 +46,10 @@ class DaysSinceMasterFailureRepository
33
46
  set_last_reported_days(days_since_last_failure)
34
47
  end
35
48
 
49
+ def touch_most_successful_days
50
+ set_most_successful_days(last_reported_days)
51
+ end
52
+
36
53
  def fetch_last_failure_at
37
54
  @redis.get(@last_failure_key).to_i
38
55
  end
@@ -41,11 +58,23 @@ class DaysSinceMasterFailureRepository
41
58
  @redis.set(@last_reported_days_key, days.to_i)
42
59
  end
43
60
 
61
+ def set_most_successful_days(days)
62
+ @redis.set(@most_successful_days_key, days.to_i)
63
+ end
64
+
44
65
  def last_reported_days
45
66
  @redis.get(@last_reported_days_key).to_i
46
67
  end
47
68
 
69
+ def most_successful_days
70
+ @redis.get(@most_successful_days_key).to_i
71
+ end
72
+
48
73
  def initialise_last_failure_at_if_not_set
49
74
  @redis.setnx(@last_failure_key, ::Time.now.to_i)
50
75
  end
76
+
77
+ def initialise_most_successful_days_if_not_set
78
+ @redis.setnx(@most_successful_days_key, days_since_last_failure)
79
+ end
51
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-buildkite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -93,6 +93,7 @@ files:
93
93
  - MIT-LICENSE
94
94
  - README.md
95
95
  - lib/lita-buildkite.rb
96
+ - lib/lita/build_status_report.rb
96
97
  - lib/lita/buildkite.rb
97
98
  - lib/lita/buildkite_build_finished_event.rb
98
99
  - lib/lita/buildkite_event.rb
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  version: '0'
122
123
  requirements: []
123
124
  rubyforge_project:
124
- rubygems_version: 2.5.1
125
+ rubygems_version: 2.7.3
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Lita handler for interacting with buildkite.com, a continuous integration