ciflows 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ciflows.gemspec +45 -0
- data/exe/flow +4 -0
- data/lib/ciflows.rb +7 -0
- data/lib/ciflows/cli.rb +88 -0
- data/lib/ciflows/constants.rb +4 -0
- data/lib/ciflows/graphql.rb +62 -0
- data/lib/ciflows/graphql_v2.rb +62 -0
- data/lib/ciflows/project.rb +89 -0
- data/lib/ciflows/version.rb +3 -0
- metadata +232 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 278ae40f06b7ee59a6ef831d626a9f6c58b69983aa7178f2f3a60455360a8290
|
4
|
+
data.tar.gz: 3ef0044ce5c0b143a8642772820f18e15cac18dd3c7cd8e92167a9f40c7eae8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0e935f033545ca0a1c12f4b43b06c7fa7862dfac9c43644a51444f5be78fc21647ee54640671b2b0089c64b7d732ae1dcda96c9e710bcdd53ba673e3bcb1b77
|
7
|
+
data.tar.gz: 33f01f1980439d909ac7d53f0d66d304bb09b47c74769fad7b6fc05a943e1d9337ee0191b239eeb6a69dd0e3eb26c994ca36a8f47a2cb3b53c9c0da93655e159
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.6
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ciflows (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.4)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
addressable (2.7.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
awesome_print (1.6.1)
|
17
|
+
byebug (11.0.1)
|
18
|
+
concurrent-ruby (1.1.5)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
domain_name (0.5.20190701)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
faraday (0.17.1)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
faraday_middleware (0.13.1)
|
25
|
+
faraday (>= 0.7.4, < 1.0)
|
26
|
+
git (1.5.0)
|
27
|
+
graphlient (0.3.6)
|
28
|
+
faraday
|
29
|
+
faraday_middleware
|
30
|
+
graphql-client
|
31
|
+
graphql (1.8.17)
|
32
|
+
graphql-client (0.14.0)
|
33
|
+
activesupport (>= 3.0, < 6.0)
|
34
|
+
graphql (~> 1.6)
|
35
|
+
http-accept (1.7.0)
|
36
|
+
http-cookie (1.0.3)
|
37
|
+
domain_name (~> 0.5)
|
38
|
+
i18n (1.7.0)
|
39
|
+
concurrent-ruby (~> 1.0)
|
40
|
+
launchy (2.4.3)
|
41
|
+
addressable (~> 2.3)
|
42
|
+
mime-types (3.3)
|
43
|
+
mime-types-data (~> 3.2015)
|
44
|
+
mime-types-data (3.2019.1009)
|
45
|
+
minitest (5.13.0)
|
46
|
+
multipart-post (2.1.1)
|
47
|
+
netrc (0.11.0)
|
48
|
+
public_suffix (4.0.1)
|
49
|
+
rake (13.0.1)
|
50
|
+
rest-client (2.1.0)
|
51
|
+
http-accept (>= 1.7.0, < 2.0)
|
52
|
+
http-cookie (>= 1.0.2, < 2.0)
|
53
|
+
mime-types (>= 1.16, < 4.0)
|
54
|
+
netrc (~> 0.8)
|
55
|
+
rspec (3.9.0)
|
56
|
+
rspec-core (~> 3.9.0)
|
57
|
+
rspec-expectations (~> 3.9.0)
|
58
|
+
rspec-mocks (~> 3.9.0)
|
59
|
+
rspec-core (3.9.0)
|
60
|
+
rspec-support (~> 3.9.0)
|
61
|
+
rspec-expectations (3.9.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.9.0)
|
64
|
+
rspec-mocks (3.9.0)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.9.0)
|
67
|
+
rspec-support (3.9.0)
|
68
|
+
thor (0.20.3)
|
69
|
+
thread_safe (0.3.6)
|
70
|
+
tzinfo (1.2.5)
|
71
|
+
thread_safe (~> 0.1)
|
72
|
+
unf (0.1.4)
|
73
|
+
unf_ext
|
74
|
+
unf_ext (0.0.7.6)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
ruby
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
awesome_print
|
81
|
+
bundler (~> 2.0.2)
|
82
|
+
byebug
|
83
|
+
ciflows!
|
84
|
+
git
|
85
|
+
graphlient (= 0.3.6)
|
86
|
+
graphql (~> 1.8.11)
|
87
|
+
graphql-client (= 0.14)
|
88
|
+
launchy
|
89
|
+
rake
|
90
|
+
rest-client (~> 2.1)
|
91
|
+
rspec (~> 3.0)
|
92
|
+
thor
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 cuong.ngo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Ciflows
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ciflows`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ciflows'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ciflows
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ciflows.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ciflows"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ciflows.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ciflows/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'ciflows'
|
9
|
+
spec.version = Ciflows::VERSION
|
10
|
+
spec.authors = ['cuong.ngo']
|
11
|
+
spec.email = ['cuong.ngo@employmenthero.com']
|
12
|
+
|
13
|
+
spec.summary = 'CI flows in EH'
|
14
|
+
spec.description = 'No desc'
|
15
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
|
20
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
22
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0.2'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rest-client', '~> 2.1'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_dependency 'graphlient', '0.3.6'
|
38
|
+
spec.add_development_dependency 'byebug'
|
39
|
+
spec.add_dependency 'git'
|
40
|
+
spec.add_dependency 'graphql-client', '0.14'
|
41
|
+
spec.add_dependency 'graphql', '~> 1.8.11'
|
42
|
+
spec.add_dependency 'thor'
|
43
|
+
spec.add_development_dependency 'awesome_print'
|
44
|
+
spec.add_dependency 'launchy'
|
45
|
+
end
|
data/exe/flow
ADDED
data/lib/ciflows.rb
ADDED
data/lib/ciflows/cli.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'ciflows'
|
5
|
+
require 'ciflows/project'
|
6
|
+
require 'launchy'
|
7
|
+
require 'git'
|
8
|
+
require 'byebug'
|
9
|
+
|
10
|
+
module Ciflows
|
11
|
+
class CLI < Thor
|
12
|
+
include Thor::Actions
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def git_repo
|
16
|
+
@git_repo ||= File.basename(git.config['remote.origin.url'].to_s).gsub('.git', '')
|
17
|
+
|
18
|
+
raise ArgumentError, 'Remote git repository not found' unless @git_repo
|
19
|
+
|
20
|
+
@git_repo
|
21
|
+
end
|
22
|
+
|
23
|
+
def git_branch
|
24
|
+
git.current_branch
|
25
|
+
end
|
26
|
+
|
27
|
+
def git
|
28
|
+
@git ||= Git.open(Dir.pwd)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'process', 'Process workflow'
|
33
|
+
method_option :repo, aliases: '-r', default: git_repo
|
34
|
+
method_option :branch, aliases: '-b', default: git_branch
|
35
|
+
method_option :build, aliases: '-bu'
|
36
|
+
method_option :job, aliases: '-j'
|
37
|
+
method_option :run, aliases: '-r', default: true
|
38
|
+
|
39
|
+
def process
|
40
|
+
flow = Ciflows::Project.new(options[:repo], options[:branch], options[:build], options[:job])
|
41
|
+
|
42
|
+
begin
|
43
|
+
flow.process
|
44
|
+
|
45
|
+
build_icon = flow.build['status'] == 'success' ? "✅": "❌"
|
46
|
+
|
47
|
+
say("Workflow INFO: #{build_icon}", :blue)
|
48
|
+
print_table(flow.build)
|
49
|
+
|
50
|
+
case flow.build['status']
|
51
|
+
when 'failed', 'failing'
|
52
|
+
say("\n")
|
53
|
+
say("Workflow #{flow.build['id']} failed/failing", :red)
|
54
|
+
say('Failed Jobs', :blue)
|
55
|
+
print_table(flow.failed_jobs.map(&:to_h).map(&:values))
|
56
|
+
|
57
|
+
say("\n Actions: " \
|
58
|
+
"\n 1. Rerun from failed" \
|
59
|
+
"\n 2. Rerun from begining" \
|
60
|
+
"\n 3. Go to workflow (only support Google Chrome)")
|
61
|
+
|
62
|
+
answer = ask('What do you want to go next?', :yellow, limited_to: %w[1 2 3])
|
63
|
+
case answer.to_i
|
64
|
+
when 1
|
65
|
+
flow.rerun_workflow_from('failed')
|
66
|
+
when 2
|
67
|
+
flow.rerun_workflow_from('beginning')
|
68
|
+
when 3
|
69
|
+
Launchy.open("https://circleci.com/workflow-run/#{flow.build['id']}")
|
70
|
+
else
|
71
|
+
say_status('failed', "failed #{self}")
|
72
|
+
end
|
73
|
+
|
74
|
+
when 'on_hold', 'running'
|
75
|
+
say("Workflow #{flow.build['id']} is on_hold/running", :yellow)
|
76
|
+
|
77
|
+
if options[:run] == 'true' || yes?('Do you want to approve it? (y/n)', :yellow)
|
78
|
+
flow.approve_workflow
|
79
|
+
end
|
80
|
+
when 'success'
|
81
|
+
say('success', "Workflow #{flow.build['id']} succeeded", :green)
|
82
|
+
end
|
83
|
+
rescue Graphlient::Errors::ExecutionError => e
|
84
|
+
say_status('fail', e.message, :red)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphlient'
|
4
|
+
require 'ciflows/constants'
|
5
|
+
require 'byebug'
|
6
|
+
|
7
|
+
module Ciflows
|
8
|
+
class Graphql
|
9
|
+
attr_reader :workflow_id, :client, :schema, :job_name
|
10
|
+
attr_accessor :workflow, :job, :failed_jobs
|
11
|
+
|
12
|
+
def initialize(workflow_id, job_name)
|
13
|
+
@workflow_id = workflow_id
|
14
|
+
@job_name = job_name
|
15
|
+
@client = Graphlient::Client.new(BASE_URL,
|
16
|
+
headers: {
|
17
|
+
'Authorization' => Ciflows::CI_TOKEN,
|
18
|
+
})
|
19
|
+
@schema = @client.schema
|
20
|
+
end
|
21
|
+
|
22
|
+
def approve_job
|
23
|
+
client.query(id: job.id) do
|
24
|
+
mutation(id: :ID!) do
|
25
|
+
approveJob(id: :id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_workflow
|
31
|
+
@workflow ||= client.query(id: workflow_id) do
|
32
|
+
query(id: :ID!) do
|
33
|
+
workflow(id: :id) do
|
34
|
+
status
|
35
|
+
jobs do
|
36
|
+
id
|
37
|
+
name
|
38
|
+
type
|
39
|
+
status
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rerun_workflow_from(from = 'failed')
|
47
|
+
client.query(id: workflow_id, from: from.upcase) do
|
48
|
+
mutation(id: :ID!, from: :RerunWorkflowFromOption) do
|
49
|
+
rerunWorkflow(id: :id, from: :from)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_jobs(status)
|
55
|
+
@failed_jobs ||= workflow.data.workflow.jobs.select { |job| job.status.eql?(status) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def job
|
59
|
+
@job ||= workflow.data.workflow.jobs.detect { |job| job.type.eql?('APPROVAL') }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql/client'
|
4
|
+
require 'graphql/client/http'
|
5
|
+
require 'ciflows/constants'
|
6
|
+
|
7
|
+
module Ciflows
|
8
|
+
class GraphqlV2
|
9
|
+
HTTP = GraphQL::Client::HTTP.new('https://api.circleci.com/graphql-unstable') do
|
10
|
+
def headers(_context)
|
11
|
+
{ "User-Agent": 'My Client', 'Authorization': Ciflows::CI_TOKEN }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Schema = GraphQL::Client.load_schema(HTTP)
|
16
|
+
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
|
17
|
+
|
18
|
+
attr_reader :workflow_id, :client, :schema, :job_name
|
19
|
+
attr_accessor :workflow, :job, :approve_job
|
20
|
+
|
21
|
+
def initialize(workflow_id, job_name)
|
22
|
+
@workflow_id = workflow_id
|
23
|
+
@job_name = job_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def approve_job
|
27
|
+
@approve_job ||= Client.query(Mutation::ApproveJobMutation, variables: { id: job.id })
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_workflow
|
31
|
+
@workflow ||= Client.query(Query::WorkflowQuery, variables: { id: workflow_id })
|
32
|
+
end
|
33
|
+
|
34
|
+
def job
|
35
|
+
@job ||= workflow.data.workflow.jobs.detect { |job| job.type.eql?("APPROVAL") }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Query
|
40
|
+
WorkflowQuery = GraphqlV2::Client.parse <<~'GRAPHQL'
|
41
|
+
query ($id: ID!) {
|
42
|
+
workflow(id: $id) {
|
43
|
+
status
|
44
|
+
jobs {
|
45
|
+
id
|
46
|
+
name
|
47
|
+
type
|
48
|
+
status
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
GRAPHQL
|
53
|
+
end
|
54
|
+
|
55
|
+
class Mutation
|
56
|
+
ApproveJobMutation = GraphqlV2::Client.parse <<~'GRAPHQL'
|
57
|
+
mutation($id: ID!) {
|
58
|
+
approveJob(id: $id)
|
59
|
+
}
|
60
|
+
GRAPHQL
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
require 'json'
|
5
|
+
require 'ciflows/graphql'
|
6
|
+
require 'ciflows/graphql_v2'
|
7
|
+
require 'ciflows/constants'
|
8
|
+
require 'awesome_print'
|
9
|
+
|
10
|
+
module Ciflows
|
11
|
+
class Project
|
12
|
+
BASE_URL = 'https://circleci.com/api/v1/projects'
|
13
|
+
|
14
|
+
attr_reader :repo_name, :branch_name, :build_name, :job_name
|
15
|
+
attr_accessor :projects, :repo, :branch, :latest_workflows, :build
|
16
|
+
|
17
|
+
def initialize(repo_name, branch_name, build_name, job_name)
|
18
|
+
@branch_name = CGI.escape(branch_name)
|
19
|
+
@repo_name = repo_name
|
20
|
+
@build_name = build_name
|
21
|
+
@job_name = job_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def process
|
25
|
+
find_projects
|
26
|
+
find_repo
|
27
|
+
find_branch
|
28
|
+
find_latest_workflows
|
29
|
+
find_build
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_workflow
|
33
|
+
graphql_client.get_workflow
|
34
|
+
end
|
35
|
+
|
36
|
+
def approve_workflow
|
37
|
+
graphql_client.get_workflow
|
38
|
+
graphql_client.approve_job
|
39
|
+
end
|
40
|
+
|
41
|
+
def rerun_workflow_from(from)
|
42
|
+
graphql_client.get_workflow
|
43
|
+
graphql_client.rerun_workflow_from(from)
|
44
|
+
end
|
45
|
+
|
46
|
+
def failed_jobs
|
47
|
+
graphql_client.get_workflow
|
48
|
+
graphql_client.get_jobs('FAILED')
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def graphql_client
|
54
|
+
@graphql_client ||= Graphql.new(build['id'], job_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_projects
|
58
|
+
res = RestClient.get(BASE_URL,
|
59
|
+
'Circle-Token' => Ciflows::CI_TOKEN,
|
60
|
+
content_type: :json,
|
61
|
+
accept: :json)
|
62
|
+
|
63
|
+
@projects = JSON.parse(res.body)
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_repo
|
67
|
+
@repo ||= projects.detect { |proj| proj['reponame'] == repo_name }
|
68
|
+
end
|
69
|
+
|
70
|
+
def find_branch
|
71
|
+
@branch ||= @repo['branches'][branch_name]
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_latest_workflows
|
75
|
+
@latest_workflows ||= branch['latest_workflows']
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_build
|
79
|
+
@build ||= begin
|
80
|
+
if build_name
|
81
|
+
latest_workflows[build_name]
|
82
|
+
else
|
83
|
+
build_name = latest_workflows.max_by { |_, data| data[:created_at] }[0]
|
84
|
+
latest_workflows[build_name]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ciflows
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cuong.ngo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: graphlient
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: git
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: graphql-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.14'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.14'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: graphql
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.8.11
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.8.11
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: thor
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: awesome_print
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: launchy
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: No desc
|
182
|
+
email:
|
183
|
+
- cuong.ngo@employmenthero.com
|
184
|
+
executables:
|
185
|
+
- flow
|
186
|
+
extensions: []
|
187
|
+
extra_rdoc_files: []
|
188
|
+
files:
|
189
|
+
- ".gitignore"
|
190
|
+
- ".rspec"
|
191
|
+
- ".ruby-version"
|
192
|
+
- ".travis.yml"
|
193
|
+
- Gemfile
|
194
|
+
- Gemfile.lock
|
195
|
+
- LICENSE.txt
|
196
|
+
- README.md
|
197
|
+
- Rakefile
|
198
|
+
- bin/console
|
199
|
+
- bin/setup
|
200
|
+
- ciflows.gemspec
|
201
|
+
- exe/flow
|
202
|
+
- lib/ciflows.rb
|
203
|
+
- lib/ciflows/cli.rb
|
204
|
+
- lib/ciflows/constants.rb
|
205
|
+
- lib/ciflows/graphql.rb
|
206
|
+
- lib/ciflows/graphql_v2.rb
|
207
|
+
- lib/ciflows/project.rb
|
208
|
+
- lib/ciflows/version.rb
|
209
|
+
homepage:
|
210
|
+
licenses:
|
211
|
+
- MIT
|
212
|
+
metadata: {}
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
require_paths:
|
216
|
+
- lib
|
217
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: '0'
|
227
|
+
requirements: []
|
228
|
+
rubygems_version: 3.0.8
|
229
|
+
signing_key:
|
230
|
+
specification_version: 4
|
231
|
+
summary: CI flows in EH
|
232
|
+
test_files: []
|