buildkite-ding 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 704d8ccdd7cdea341d1c67dda5a4d371ef805516
4
+ data.tar.gz: 8f422b3b6dd28b88ef12879f8cb26287db535380
5
+ SHA512:
6
+ metadata.gz: c80d45408703bf8a8a91bd6f2494c9f7bd1581ddb54995240bf1d5a2c372358bf8b9d4d33c473af9e754bb8b12457872c99671aa3f5efcfa02be50b133811339
7
+ data.tar.gz: a248fc7ffbc85f3a1aeea06b58e908262352691886363eca4fe0d40e30e0a553f1a597f65ee4b3bc011eadc8d5624288e48dbfd077c4c75068f56d05f3dd7d7f
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'buildkite-ding'
4
+ require 'daemons'
5
+
6
+ BuildkiteDing.load_config
7
+
8
+ Daemons.run_proc('buildkite-ding') do
9
+ BuildkiteDing.run_client
10
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,103 @@
1
+ require 'ptools' # Used to find appropriate play command
2
+ # require 'win32-file' # Required for File.which on Windows
3
+ require 'buildkit'
4
+ require 'json'
5
+ require 'date'
6
+
7
+ CONFIG_PATH = "#{ENV['HOME']}/.bkdingrc".freeze
8
+ DATA_PATH = File.join(File.dirname(File.expand_path(__FILE__)), '../data')
9
+
10
+ BUILD_EVENTS = {
11
+ 'running' => {
12
+ 'action' => 'ding once!',
13
+ 'sound' => 'w_1'
14
+ },
15
+ 'passed' => {
16
+ 'action' => 'ding twice!!',
17
+ 'sound' => 'w_2'
18
+ },
19
+ 'failed' => {
20
+ 'action' => 'lots of dings!!!!!',
21
+ 'sound' => 'w_many'
22
+ }
23
+ }.freeze
24
+
25
+ # Goes 'ding' when your builds fail. or pass. or start.
26
+ #
27
+ # To run without daemon/binary:
28
+ # BuildkiteDing.run
29
+ #
30
+ class BuildkiteDing
31
+ def self.run # Alternative to starting with the bin
32
+ BuildkiteDing.load_config
33
+ BuildkiteDing.run_client
34
+ end
35
+
36
+ def self.load_config
37
+ if File.exist?(CONFIG_PATH)
38
+ @config = JSON.parse(File.read(CONFIG_PATH), symbolize_names: true)
39
+ puts "Loaded configuration from #{CONFIG_PATH}"
40
+ else
41
+ BuildkiteDing.generate_config
42
+ end
43
+ end
44
+
45
+ def self.generate_config
46
+ @config = {}
47
+ puts "No .bkdingrc file detected in #{CONFIG_PATH}
48
+ Please provide a Buildkite API access token with read_builds scope:
49
+ ( Generate at https://buildkite.com/user/api-access-tokens/new )"
50
+ @config[:buildkite_api_token] = STDIN.gets.chomp
51
+ File.open(CONFIG_PATH, 'w') do |f|
52
+ f.write(JSON.pretty_generate(@config))
53
+ end
54
+ end
55
+
56
+ def self.run_client
57
+ @client = Buildkit.new(token: @config[:buildkite_api_token])
58
+ @tracked_builds = {} # Simple hash tracking build id and state
59
+ @last_check = Time.now.utc
60
+ loop do
61
+ puts 'Checking builds...'
62
+ BuildkiteDing.check_builds
63
+ @last_check = Time.now.utc
64
+ sleep(5)
65
+ end
66
+ end
67
+
68
+ def self.check_builds
69
+ new_builds = @client.builds(created_from: @last_check.iso8601) +
70
+ @client.builds(finished_from: @last_check.iso8601)
71
+ new_builds.each do |b|
72
+ if @tracked_builds.key?(b['id']) && @tracked_builds[b['id']] == b['state']
73
+ next
74
+ end
75
+ BuildkiteDing.interogate_build(b)
76
+ end
77
+ end
78
+
79
+ def self.interogate_build(build)
80
+ puts "Build is new or updated: #{build['message']}"
81
+ @tracked_builds[build['id']] = build['state']
82
+ return unless BUILD_EVENTS.key? build['state']
83
+ print "Build #{build['state']} - "
84
+ BuildkiteDing.take_action(BUILD_EVENTS[build['state']])
85
+ end
86
+
87
+ def self.take_action(action)
88
+ puts action['action']
89
+ BuildkiteDing.play_sound(action['sound'])
90
+ end
91
+
92
+ def self.play_sound(sound) # Sound name standard is class_numberofdings
93
+ puts 'Finding play command...'
94
+ if File.which('afplay') # Included in MacOS
95
+ puts 'Found afplay (this is probably MacOS)'
96
+ puts "Playing #{DATA_PATH}/#{sound}.mp3"
97
+ system "afplay #{DATA_PATH}/#{sound}.mp3"
98
+ elsif File.which('play') # Sox package?
99
+ puts 'Found play (this is presumably Linux)'
100
+ system "play #{DATA_PATH}/#{sound}.mp3"
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildkite-ding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Effy Elden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: daemons
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: ptools
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: buildkit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |-
56
+ Ultra simple audible alerts for Buildkite build events,
57
+ inspired by the ambiance of Melbourne
58
+ email: dev@effy.is
59
+ executables:
60
+ - buildkite-ding
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - bin/buildkite-ding
65
+ - data/w_1.mp3
66
+ - data/w_2.mp3
67
+ - data/w_many.mp3
68
+ - lib/buildkite_ding.rb
69
+ homepage: https://github.com/ineffyble/buildkite-ding
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.8
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Simple audible alerts for Buildkite build events
93
+ test_files: []