buildkite_graphql_ruby 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/buildkite_graphql_ruby +1 -7
- data/lib/buildkite_graphql_ruby.rb +5 -0
- data/lib/buildkite_graphql_ruby/cli.rb +16 -1
- data/lib/buildkite_graphql_ruby/commands/branch_status.rb +1 -1
- data/lib/buildkite_graphql_ruby/commands/command_map.rb +3 -1
- data/lib/buildkite_graphql_ruby/commands/pull_artifacts.rb +29 -0
- data/lib/buildkite_graphql_ruby/query_builder.rb +29 -0
- data/lib/buildkite_graphql_ruby/results_parsers/build.rb +8 -10
- data/lib/buildkite_graphql_ruby/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eebb44c22e64df704093d9c619a570d3fdc0d51d
|
4
|
+
data.tar.gz: 9cfe4004f3693dcc7ed45772b838c44d106dc393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: affc352d9fa6b36f242317163ece7af708b7b76a6221f32b0ff7b7325c2cab598f6a47baf434fe50019e939101f67f124b6d6bc7575e79433f8d0b8e6e3b005c
|
7
|
+
data.tar.gz: 3385d15f403325a192339aa77627b2d977c9ba4563ddea2ac9377a5652d7092f170096f0f7ed97828dd97ce03e52fc8b31e69c63a66e1ead88b5f93cda789072
|
data/bin/buildkite_graphql_ruby
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "buildkite_graphql_ruby/cli"
|
4
|
-
require "buildkite_graphql_ruby/query_builder"
|
5
|
-
require "buildkite_graphql_ruby/query_runner"
|
6
|
-
require "buildkite_graphql_ruby/commands/command_map"
|
7
|
-
require 'pry'
|
8
|
-
|
2
|
+
require "buildkite_graphql_ruby"
|
9
3
|
options = BuildkiteGraphqlRuby::CLI.parse(args: ARGV)
|
10
4
|
command = BuildkiteGraphqlRuby::Commands::CommandMap.get_command(command_string: options.command)
|
11
5
|
result = command.run!(options: options)
|
@@ -1,4 +1,9 @@
|
|
1
1
|
require "buildkite_graphql_ruby/version"
|
2
|
+
require "buildkite_graphql_ruby/cli"
|
3
|
+
require "buildkite_graphql_ruby/query_builder"
|
4
|
+
require "buildkite_graphql_ruby/query_runner"
|
5
|
+
require "buildkite_graphql_ruby/commands/command_map"
|
6
|
+
require 'pry'
|
2
7
|
|
3
8
|
module BuildkiteGraphqlRuby
|
4
9
|
end
|
@@ -26,8 +26,23 @@ module BuildkiteGraphqlRuby
|
|
26
26
|
options.branch = branch.chomp
|
27
27
|
end
|
28
28
|
|
29
|
+
opts.on("-a", "--artifact_to_pull ARTIFACT_TO_PULL",
|
30
|
+
"Artifact to pull for pull_artifacts command") do |artifact_to_pull|
|
31
|
+
options.artifact_to_pull = artifact_to_pull.chomp
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-o", "--output_artifact OUTPUT_ARTIFACT",
|
35
|
+
"Base name of output artifact for pull_artifacts command. Dir is always tmp") do |output_artifact|
|
36
|
+
options.output_artifact = output_artifact.chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-s", "--slug SLUG",
|
40
|
+
"Build slug to use for pull_artifacts command") do |slug|
|
41
|
+
options.slug = slug.chomp
|
42
|
+
end
|
43
|
+
|
29
44
|
opts.on("-C", "--command COMMAND",
|
30
|
-
"What type of query to run (default
|
45
|
+
"What type of query to run (default option: branch_status)") do |command|
|
31
46
|
# TODO: Error on unaccepted query types
|
32
47
|
options.command = command
|
33
48
|
end
|
@@ -16,7 +16,7 @@ module BuildkiteGraphqlRuby
|
|
16
16
|
|
17
17
|
return if report_if_no_builds(total_builds, options)
|
18
18
|
|
19
|
-
builds = builds_for_branch["edges"].map{|build_response| ResultsParsers::Build.from_response(build_response) }
|
19
|
+
builds = builds_for_branch["edges"].map{|build_response| ResultsParsers::Build.from_response(build_response['node']) }
|
20
20
|
|
21
21
|
return if report_if_no_finished_builds(builds, options)
|
22
22
|
|
@@ -2,9 +2,11 @@ module BuildkiteGraphqlRuby
|
|
2
2
|
module Commands
|
3
3
|
class CommandMap
|
4
4
|
require "buildkite_graphql_ruby/commands/branch_status"
|
5
|
+
require "buildkite_graphql_ruby/commands/pull_artifacts"
|
5
6
|
|
6
7
|
COMMAND_MAP = {
|
7
|
-
'branch_status' => BranchStatus
|
8
|
+
'branch_status' => BranchStatus,
|
9
|
+
'pull_artifacts' => PullArtifacts
|
8
10
|
}
|
9
11
|
|
10
12
|
def self.get_command(command_string:)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BuildkiteGraphqlRuby
|
2
|
+
module Commands
|
3
|
+
require 'rainbow'
|
4
|
+
require "buildkite_graphql_ruby/results_parsers/build"
|
5
|
+
require "buildkite_graphql_ruby/results_parsers/rspec_results"
|
6
|
+
|
7
|
+
class PullArtifacts
|
8
|
+
def run!(options:)
|
9
|
+
query = BuildkiteGraphqlRuby::QueryBuilder.new.artifacts_for_build_slug(slug: options.slug)
|
10
|
+
query_runner = BuildkiteGraphqlRuby::QueryRunner.new.run_query(query: query, options: options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def report_result(result:, options:)
|
14
|
+
build = ResultsParsers::Build.from_response(result['data']['build'])
|
15
|
+
all_jobs = build.jobs
|
16
|
+
all_artifacts = []
|
17
|
+
all_jobs.each do |job|
|
18
|
+
all_artifacts += job.artifacts.select{|a| a.path == options.artifact_to_pull}
|
19
|
+
end
|
20
|
+
|
21
|
+
all_artifacts.each_with_index do |artifact, index|
|
22
|
+
filename = "tmp/#{index} #{options.output_artifact}"
|
23
|
+
puts "Writing file: #{filename}"
|
24
|
+
File.open(filename, 'w') { |f| f.write(artifact.download) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,5 +1,34 @@
|
|
1
1
|
module BuildkiteGraphqlRuby
|
2
2
|
class QueryBuilder
|
3
|
+
def artifacts_for_build_slug(slug:)
|
4
|
+
query = <<~EOS
|
5
|
+
{
|
6
|
+
build(slug:"#{slug}") {
|
7
|
+
jobs(last: 50) {
|
8
|
+
edges {
|
9
|
+
node {
|
10
|
+
... on JobTypeCommand {
|
11
|
+
agent {
|
12
|
+
id
|
13
|
+
}
|
14
|
+
artifacts(first: 300) {
|
15
|
+
edges {
|
16
|
+
node {
|
17
|
+
id
|
18
|
+
path
|
19
|
+
downloadURL
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
EOS
|
30
|
+
end
|
31
|
+
|
3
32
|
def branch_status(branch:)
|
4
33
|
query = <<~EOS
|
5
34
|
{
|
@@ -31,18 +31,16 @@ module BuildkiteGraphqlRuby
|
|
31
31
|
# NOT_RUN
|
32
32
|
# The build wasn't run
|
33
33
|
|
34
|
-
def self.from_response(
|
35
|
-
|
36
|
-
|
37
|
-
jobs = node['jobs']["edges"].select{|j| j['node'].keys.count > 0 }.map{|build_response| ResultsParsers::Job.from_response(build_response) }
|
34
|
+
def self.from_response(build_response)
|
35
|
+
jobs = build_response['jobs']["edges"].select{|j| j['node'].keys.count > 0 }.map{|build_response| ResultsParsers::Job.from_response(build_response) }
|
38
36
|
|
39
37
|
new(
|
40
|
-
branch:
|
41
|
-
state:
|
42
|
-
url:
|
43
|
-
started_at:
|
44
|
-
finished_at:
|
45
|
-
pull_request:
|
38
|
+
branch: build_response['branch'],
|
39
|
+
state: build_response['state'],
|
40
|
+
url: build_response['url'],
|
41
|
+
started_at: build_response['startedAt'] && Time.parse(build_response['startedAt']),
|
42
|
+
finished_at: build_response['finishedAt'] && Time.parse(build_response['finishedAt']),
|
43
|
+
pull_request: build_response['pullRequest'],
|
46
44
|
jobs: jobs,
|
47
45
|
)
|
48
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buildkite_graphql_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Evanczuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-stack_explorer
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.9.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.4.9.3
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rainbow
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +125,7 @@ files:
|
|
111
125
|
- lib/buildkite_graphql_ruby/cli.rb
|
112
126
|
- lib/buildkite_graphql_ruby/commands/branch_status.rb
|
113
127
|
- lib/buildkite_graphql_ruby/commands/command_map.rb
|
128
|
+
- lib/buildkite_graphql_ruby/commands/pull_artifacts.rb
|
114
129
|
- lib/buildkite_graphql_ruby/query_builder.rb
|
115
130
|
- lib/buildkite_graphql_ruby/query_runner.rb
|
116
131
|
- lib/buildkite_graphql_ruby/results_parsers/artifact.rb
|