chicanery 0.1.9 → 0.2.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
2
  SHA256:
3
- metadata.gz: 496b85a08502668e3852df9db9f99132d09b2974b5b2e8f7f9adbcfff5a667ed
4
- data.tar.gz: 6a2e6113783e2bdc409bb9834a4d7e089a72b54c15ba3208c6c245a072f989d4
3
+ metadata.gz: 664f7b6ae3baab7e4822886b65cdec4b295615fc003b9b78319ea2c9d86e7d22
4
+ data.tar.gz: 03f6d7e1087acf778dda1d83f3f30f13a41af8f6bfc591ab69f6d0e06edd48ac
5
5
  SHA512:
6
- metadata.gz: 583955a38c81e0f4f5ea0f90569c688b8050092e56ebf0f022afba40cd7df96d7cf17e011f34abc3fce15302921852003dc4339b35bd76168736211e98d8e73a
7
- data.tar.gz: 5d74241181416c8df9b59b1150dd3adb12dd9e6dceb829c86588fa51c99c507459cd6c5b44aee6ba7921a4d724937bec262eb2cc96e28f71e2af8294ca10bae4
6
+ metadata.gz: 10eec19b65a6b884f09c5c0a8e2c2ff672594702c8a2504646ccc12088d1bb97a2103182269f112b8fb96af3ce737521334815eaf918b6117a6535fe12dbd604
7
+ data.tar.gz: 2845ffca1a6197be2e8f7727bd2dd352265283c6e5e93bcf5c94c7cb770628718a9abd434033a215131a5babd8124a1ce5b9dfa891fabd4ab1a41555842e6c35
@@ -0,0 +1,24 @@
1
+ require "chicanery/semaphore"
2
+
3
+ include Chicanery::Semaphore
4
+
5
+ token = ENV.fetch("SEMAPHORE_TOKEN")
6
+ project_branch_1 = ENV.fetch("BRANCH_1")
7
+
8
+ semaphore(
9
+ "build 1",
10
+ "https://semaphoreci.com/api/v1/projects/#{project_branch_1}?auth_token=#{token}",
11
+ )
12
+
13
+ when_broken do |job_name, job|
14
+ puts "#{job_name} is broken"
15
+ end
16
+
17
+ when_fixed do |job_name, job|
18
+ puts "#{job_name} is fixed"
19
+ end
20
+
21
+ when_run do |state|
22
+ require "pp"
23
+ pp state
24
+ end
@@ -0,0 +1,69 @@
1
+ require 'chicanery/site'
2
+ require 'date'
3
+ require 'json'
4
+
5
+ module Chicanery
6
+ module Semaphore
7
+ def self.new *args
8
+ Semaphore::Server.new *args
9
+ end
10
+
11
+ def semaphore *args
12
+ server Semaphore::Server.new *args
13
+ end
14
+
15
+ class Server < Chicanery::Site
16
+ def jobs
17
+ jobs = {}
18
+
19
+ response = JSON.parse(get)
20
+ project_name = response['project_name']
21
+ branch = response['branch_name']
22
+ name = "#{project_name} #{branch}"
23
+
24
+ sorted_builds = response['builds'].sort_by do |build|
25
+ build['build_number']
26
+ end.reverse
27
+
28
+ completed = %w[passed failed].include?(sorted_builds.first["result"])
29
+
30
+ most_recent_completed_build = sorted_builds.find do |build|
31
+ %w[passed failed].include?(build["result"])
32
+ end
33
+
34
+ build_number = most_recent_completed_build["build_number"]
35
+ build_url = most_recent_completed_build["build_url"]
36
+ result = most_recent_completed_build['result']
37
+ commit_url = most_recent_completed_build['commit']['url']
38
+ committer = most_recent_completed_build['commit']['author_name']
39
+ time = most_recent_completed_build["finished_at"]
40
+
41
+ jobs[name] = {
42
+ activity: completed ? :sleeping : :building,
43
+ last_build_status: parse_build_status(result),
44
+ last_build_time: parse_build_time(time),
45
+ url: build_url,
46
+ last_label: build_number,
47
+ commit_url: commit_url,
48
+ committer: committer
49
+ }
50
+
51
+ jobs
52
+ end
53
+
54
+ def parse_build_time time
55
+ return 0 if time.nil? || time.empty? || time == '0'
56
+
57
+ DateTime.parse(time).to_time.to_i
58
+ end
59
+
60
+ def parse_build_status status
61
+ case status
62
+ when /^passed/ then :success
63
+ when /^failed/ then :failure
64
+ else :unknown
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module Chicanery
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chicanery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -114,6 +114,7 @@ files:
114
114
  - examples/baby_steps.rb
115
115
  - examples/blinky.rb
116
116
  - examples/chicanery.rb
117
+ - examples/semaphore.rb
117
118
  - fixtures/vcr_cassettes/broken.yml
118
119
  - fixtures/vcr_cassettes/idle.yml
119
120
  - fixtures/vcr_cassettes/no_projects.yml
@@ -127,6 +128,7 @@ files:
127
128
  - lib/chicanery/handlers.rb
128
129
  - lib/chicanery/persistence.rb
129
130
  - lib/chicanery/repos.rb
131
+ - lib/chicanery/semaphore.rb
130
132
  - lib/chicanery/servers.rb
131
133
  - lib/chicanery/site.rb
132
134
  - lib/chicanery/sites.rb