lita-buildkite 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/lib/lita-buildkite.rb +4 -0
- data/lib/lita/buildkite.rb +21 -0
- data/lib/lita/buildkite_event.rb +25 -0
- data/lib/lita/days_since_master_failure.rb +48 -0
- data/lib/lita/days_since_master_failure_repository.rb +49 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22989d66ceab9ce1f3a43b3df292832b2cf24d49
|
4
|
+
data.tar.gz: f4fe23a71981da40f06afda34e4e56b96abaaf66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bbe9a2fcc013f1282544a886c5e768eeff3c84f67f1f0ca9ebfe0e4e9b830c6f01b40e6c491726f2922834b3ff55cc9fb150bbc35fc9d88cad6c225dc92cdaf
|
7
|
+
data.tar.gz: d97d57b6c9bd821a91bbf468aa43463c8d46483104a384ab2dc3e3e5daea7761a371691df57286b0cfb4c6098e764a195122c2aba60854b69d634b3b3d9eb27d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 James Healy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# lita-buildkite
|
2
|
+
|
3
|
+
A lita plugin for interacting with buildkite.com, a Continuous Integration provider.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this gem to your lita installation by including the following line in your Gemfile:
|
8
|
+
|
9
|
+
gem "lita-buildkite"
|
10
|
+
|
11
|
+
## Externally triggered events
|
12
|
+
|
13
|
+
This handler can track completed builds and trigger a variety of activities as appropriate. To
|
14
|
+
get started, use the buildkite web interface to configure a webhook that POSTs "build.finished"
|
15
|
+
events to:
|
16
|
+
|
17
|
+
http://your-lita-bot.com/buildkite
|
18
|
+
|
19
|
+
### Days Since Master Failure
|
20
|
+
|
21
|
+
To track how long each project has managed to go without a master branch failure, edit your
|
22
|
+
lita\_config.rb to include the following line.
|
23
|
+
|
24
|
+
config.handlers.days_since_master_failure.channel_name = "channel-name"
|
25
|
+
|
26
|
+
As builds complete, occasional messages will be posted to the channel that congratulate for
|
27
|
+
a string of days with no failures, and commiserate when a master branch build fails.
|
28
|
+
|
29
|
+
## Chat commands
|
30
|
+
|
31
|
+
This handler provides no additional chat commands. Yet.
|
32
|
+
|
33
|
+
## TODO
|
34
|
+
|
35
|
+
Possible ideas for new features, either via chat commands or externally triggered events:
|
36
|
+
|
37
|
+
* more specs
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'lita/buildkite_event'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
# Receives buildkite webhooks and emits them onto the lita event bus
|
7
|
+
# so other handlers can do their thing
|
8
|
+
class Buildkite < Handler
|
9
|
+
|
10
|
+
http.post "/buildkite", :buildkite_event
|
11
|
+
|
12
|
+
def buildkite_event(request, response)
|
13
|
+
event = BuildkiteEvent.new(request.body.read)
|
14
|
+
robot.trigger(:buildkite_event, event: event)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
Lita.register_handler(Buildkite)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
# Value object that wraps raw buildkite webhook data and provides convenience
|
4
|
+
# methods for querying it
|
5
|
+
class BuildkiteEvent
|
6
|
+
def initialize(data)
|
7
|
+
@data = JSON.load(data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_finished?
|
11
|
+
@data.fetch("build", {}).fetch("finished_at", "") != ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def branch
|
15
|
+
@data.fetch("build", {}).fetch("branch", "")
|
16
|
+
end
|
17
|
+
|
18
|
+
def pipeline
|
19
|
+
@data.fetch("pipeline", {}).fetch("name", "")
|
20
|
+
end
|
21
|
+
|
22
|
+
def passed?
|
23
|
+
@data.fetch("build", {}).fetch("state", "") == "passed"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'lita/buildkite_event'
|
3
|
+
require 'lita/days_since_master_failure_repository'
|
4
|
+
|
5
|
+
module Lita
|
6
|
+
module Handlers
|
7
|
+
# Watch buildkite webhooks for build failures of the master branch, and track
|
8
|
+
# how long the team can go without a failure
|
9
|
+
class DaysSinceMasterFailure < Handler
|
10
|
+
config :channel_name
|
11
|
+
|
12
|
+
on :buildkite_event, :timestamp_failure
|
13
|
+
|
14
|
+
def timestamp_failure(payload)
|
15
|
+
event = payload[:event]
|
16
|
+
|
17
|
+
if event.branch == "master" && event.build_finished?
|
18
|
+
process_build_finished(event) do |msg|
|
19
|
+
robot.send_message(target, msg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def process_build_finished(event, &block)
|
27
|
+
repository.record_result(event.passed?) do |days_since_last_failure, prev_days_since_last_failure|
|
28
|
+
if days_since_last_failure < prev_days_since_last_failure
|
29
|
+
yield "Oh Oh, #{days_since_last_failure} day(s) since the last master failure"
|
30
|
+
elsif days_since_last_failure > prev_days_since_last_failure
|
31
|
+
yield "Congratulations! #{days_since_last_failure} day(s) since the last master failure"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def target
|
37
|
+
Source.new(room: Lita::Room.find_by_name(config.channel_name) || "general")
|
38
|
+
end
|
39
|
+
|
40
|
+
def repository
|
41
|
+
@repository ||= DaysSinceMasterFailureRepository.new(redis)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
Lita.register_handler(DaysSinceMasterFailure)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Provides all persistence logic for the DaysSinceMasterFailure handler, insulating
|
2
|
+
# the handler from any knowledge of redis
|
3
|
+
class DaysSinceMasterFailureRepository
|
4
|
+
def initialize(redis)
|
5
|
+
@redis = redis
|
6
|
+
|
7
|
+
initialise_last_failure_at_if_not_set
|
8
|
+
end
|
9
|
+
|
10
|
+
def record_result(success, &block)
|
11
|
+
touch_last_failure_at if !success
|
12
|
+
yield days_since_last_failure, last_reported_days
|
13
|
+
touch_last_reported_days
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def seconds_to_days(secs)
|
19
|
+
secs.to_i / 60 / 60 / 24
|
20
|
+
end
|
21
|
+
|
22
|
+
def days_since_last_failure
|
23
|
+
seconds_to_days(::Time.now.to_i - fetch_last_failure_at)
|
24
|
+
end
|
25
|
+
|
26
|
+
def touch_last_failure_at
|
27
|
+
@redis.set("last-failure-at", ::Time.now.to_i)
|
28
|
+
end
|
29
|
+
|
30
|
+
def touch_last_reported_days
|
31
|
+
set_last_reported_days(days_since_last_failure)
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_last_failure_at
|
35
|
+
@redis.get("last-failure-at").to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_last_reported_days(days)
|
39
|
+
@redis.set("last-reported-days", days.to_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
def last_reported_days
|
43
|
+
@redis.get("last-reported-days").to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialise_last_failure_at_if_not_set
|
47
|
+
@redis.setnx("last-failure-at", ::Time.now.to_i)
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-buildkite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Healy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lita
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Lita handler for interacting with buildkite.com, a continuous integration
|
84
|
+
provider
|
85
|
+
email:
|
86
|
+
- james.healy@theconversation.edu.au
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files:
|
90
|
+
- README.md
|
91
|
+
- MIT-LICENSE
|
92
|
+
files:
|
93
|
+
- MIT-LICENSE
|
94
|
+
- README.md
|
95
|
+
- lib/lita-buildkite.rb
|
96
|
+
- lib/lita/buildkite.rb
|
97
|
+
- lib/lita/buildkite_event.rb
|
98
|
+
- lib/lita/days_since_master_failure.rb
|
99
|
+
- lib/lita/days_since_master_failure_repository.rb
|
100
|
+
homepage: http://github.com/conversation/lita-buildkite
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata:
|
104
|
+
lita_plugin_type: handler
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.9.3
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Lita handler for interacting with buildkite.com, a continuous integration
|
125
|
+
provider
|
126
|
+
test_files: []
|