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
|
# File 'lib/percy/client/builds.rb', line 4
def create_build(repo, options = {})
pull_request_number = options[:pull_request_number] ||
Percy::Client::Environment.pull_request_number
commit_data = options[:commit_data] || Percy::Client::Environment.commit
resources = options[:resources]
data = {
'data' => {
'type' => 'builds',
'attributes' => {
'branch' => commit_data[:branch],
'commit-sha' => commit_data[:sha],
'commit-committed-at' => commit_data[:committed_at],
'commit-author-name' => commit_data[:author_name],
'commit-author-email' => commit_data[:author_email],
'commit-committer-name' => commit_data[:committer_name],
'commit-committer-email' => commit_data[:committer_email],
'commit-message' => commit_data[:message],
'pull-request-number' => pull_request_number,
},
}
}
if resources
if !resources.respond_to?(:each)
raise ArgumentError.new(
'resources argument must be an iterable of Percy::Client::Resource objects')
end
relationships_data = {
'relationships' => {
'resources' => {
'data' => resources.map { |r| r.serialize },
},
},
}
data['data'].merge!(relationships_data)
end
post("#{config.api_url}/repos/#{repo}/builds/", data)
end
|