-
Notifications
You must be signed in to change notification settings - Fork 1
/
circleci.rb
47 lines (38 loc) · 1.09 KB
/
circleci.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "rest-client"
require "json"
class CircleCi
def initialize(api_token, username, project)
@api_token = api_token
@username = username
@project = project
@base = "https://circleci.com/api/v1"
end
def recent_builds
response = RestClient.get("#{@base}/project/#{@username}/#{@project}", options)
JSON.parse(response.to_str)
end
def get_build(build_number)
response = RestClient.get("#{@base}/project/#{@username}/#{@project}/#{build_number}", options)
JSON.parse(response.to_str)
end
def cancel_build(build_number)
response = RestClient.post("#{@base}/project/#{@username}/#{@project}/#{build_number}/cancel", nil, options)
JSON.parse(response.to_str)
end
def is_build_in_deploy(build_number)
branch = get_build(build_number)["branch"]
return if branch == "deploy"
recent_builds.any? do |build|
build["subject"].split("from gumroad/").last == branch && build["branch"] == "deploy"
end
end
private
def options
{
accept: :json,
params: {
"circle-token" => @api_token
}
}
end
end