chicanery 0.1.9 → 0.2.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 +4 -4
- data/examples/semaphore.rb +24 -0
- data/lib/chicanery/semaphore.rb +69 -0
- data/lib/chicanery/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 664f7b6ae3baab7e4822886b65cdec4b295615fc003b9b78319ea2c9d86e7d22
|
4
|
+
data.tar.gz: 03f6d7e1087acf778dda1d83f3f30f13a41af8f6bfc591ab69f6d0e06edd48ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/chicanery/version.rb
CHANGED
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.
|
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
|