-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rubocop configuration added, jobs tracking run with follow, helper cl…
…ass added
- Loading branch information
Showing
15 changed files
with
416 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2017-05-16 13:17:04 +0200 using RuboCop version 0.48.1. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 12 | ||
Metrics/AbcSize: | ||
Max: 50 | ||
|
||
# Offense count: 6 | ||
# Configuration parameters: CountComments, ExcludedMethods. | ||
Metrics/BlockLength: | ||
Max: 200 | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: CountComments. | ||
Metrics/ClassLength: | ||
Max: 200 | ||
|
||
# Offense count: 2 | ||
Metrics/CyclomaticComplexity: | ||
Max: 10 | ||
|
||
# Offense count: 38 | ||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. | ||
# URISchemes: http, https | ||
Metrics/LineLength: | ||
Max: 160 | ||
|
||
# Offense count: 13 | ||
# Configuration parameters: CountComments. | ||
Metrics/MethodLength: | ||
Max: 50 | ||
|
||
# Offense count: 1 | ||
Metrics/PerceivedComplexity: | ||
Max: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
source "https://rubygems.org" | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in gitlabci-controller.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "gitlabci/controller" | ||
require 'gitlabci/controller' | ||
|
||
Gitlabci::Controller::Cli.start ( ARGV ) | ||
Gitlabci::Controller::Cli.start ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path("../lib", __FILE__) | ||
|
||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require "gitlabci/controller/version" | ||
require 'gitlabci/controller/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "gitlabci-cli" | ||
spec.name = 'gitlabci-cli' | ||
spec.version = Gitlabci::Controller::VERSION | ||
spec.authors = ["Wassim DHIF"] | ||
spec.email = ["wassimdhif@gmail.com"] | ||
spec.authors = ['Wassim DHIF'] | ||
spec.email = ['wassimdhif@gmail.com'] | ||
|
||
spec.summary = %q{Control your GitlabCI workflow from your terminal} | ||
spec.description = %q{Control your GitlabCI workflow from your terminal} | ||
spec.homepage = "http://github.com/wdhif/gitlabci-cli" | ||
spec.summary = 'Control your GitlabCI workflow from your terminal' | ||
spec.description = 'Control your GitlabCI workflow from your terminal' | ||
spec.homepage = 'http://github.com/wdhif/gitlabci-cli' | ||
|
||
spec.files = [] | ||
spec.executables = "gitlabci-cli" | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency "thor" | ||
spec.add_dependency "rest-client" | ||
spec.add_dependency "json" | ||
spec.add_dependency "json_pure" | ||
spec.add_dependency "terminal-table" | ||
spec.executables = 'gitlabci-cli' | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_development_dependency "bundler" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_development_dependency "rspec", "~> 3.0" | ||
spec.add_development_dependency "rspec-mocks" | ||
spec.add_development_dependency "webmock" | ||
spec.add_dependency 'thor' | ||
spec.add_dependency 'rest-client' | ||
spec.add_dependency 'json' | ||
spec.add_dependency 'json_pure' | ||
spec.add_dependency 'terminal-table' | ||
|
||
spec.add_development_dependency 'bundler' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
spec.add_development_dependency 'rspec-mocks' | ||
spec.add_development_dependency 'webmock' | ||
spec.add_development_dependency 'rubocop' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
require "gitlabci/controller/version" | ||
require "gitlabci/controller/cli" | ||
require 'gitlabci/controller/cli' | ||
require 'gitlabci/controller/version' | ||
|
||
module Gitlabci | ||
# Main Controller Class | ||
module Controller | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
require "thor" | ||
require "gitlabci/controller/pipeline" | ||
require "gitlabci/controller/trigger" | ||
require 'thor' | ||
|
||
require 'gitlabci/controller/helper' | ||
require 'gitlabci/controller/pipeline' | ||
require 'gitlabci/controller/trigger' | ||
|
||
module Gitlabci | ||
module Controller | ||
# Main CLI Class, with subcommands | ||
class Cli < Thor | ||
desc "pipeline SUBCOMMAND", "Interact the pipeline API" | ||
subcommand "pipeline", Pipeline | ||
# RestClient.log = 'stdout' | ||
|
||
desc 'pipeline SUBCOMMAND', 'Interact the pipeline API' | ||
subcommand 'pipeline', Pipeline | ||
|
||
desc "trigger SUBCOMMAND", "Interact the trigger API" | ||
subcommand "trigger", Trigger | ||
desc 'trigger SUBCOMMAND', 'Interact the trigger API' | ||
subcommand 'trigger', Trigger | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'json' | ||
require 'rest-client' | ||
|
||
module Gitlabci | ||
module Controller | ||
# Helper Module | ||
module Helper | ||
module_function | ||
|
||
def get_job_status(id = nil, url = nil, token = nil, pipeline = nil, test = false) | ||
begin | ||
response = RestClient::Request.execute( | ||
method: :get, | ||
headers: { 'PRIVATE-TOKEN' => token }, | ||
url: "#{url}/api/v4/projects/#{id}/pipelines/#{pipeline}/jobs", | ||
verify_ssl: false, | ||
timeout: 60 | ||
) | ||
jobs = JSON.parse(response) | ||
rescue => e | ||
puts 'API error' | ||
puts e | ||
unless test | ||
sleep 2 | ||
retry | ||
end | ||
end | ||
helper_response = {} | ||
jobs.each do |job| | ||
helper_response[job['name']] = job['status'] | ||
end | ||
helper_response | ||
end | ||
|
||
def follow(options, pipeline) | ||
puts "\e[32mWaiting for pipeline #{pipeline['id']} to finish\e[0m" | ||
jobs = Gitlabci::Controller::Helper.get_job_status(options['id'], options['url'], options['token'], pipeline['id'], false) | ||
puts "\e[32m#{jobs.length} jobs in pipeline\e[0m" | ||
jobs.each_key do |k| | ||
puts "\e[32mJob #{k}\e[0m" | ||
end | ||
time = 0 | ||
loop do | ||
puts 'The api is not responding, wait for next call' if jobs.nil? | ||
|
||
jobs = Gitlabci::Controller::Helper.get_job_status(options['id'], options['url'], options['token'], pipeline['id'], false) | ||
sleep 2 | ||
if (time % 10).zero? | ||
puts "\e[32mStarted since #{time} seconds\e[0m" if time != 0 | ||
jobs.each do |k, v| | ||
puts "#{k} status is #{v}" | ||
end | ||
end | ||
time += 2 | ||
break if !jobs.values.include?('created') && !jobs.values.include?('running') && !jobs.values.include?('pending') && !jobs.nil? | ||
end | ||
|
||
if jobs.values.uniq == ['success'] | ||
puts "\e[32mPipeline passed\e[0m" | ||
jobs.each do |k, v| | ||
puts "\e[32m#{k} status is #{v}\e[0m" | ||
end | ||
exit 0 | ||
else | ||
puts "\e[31mPipeline #{pipeline['id']} failed\e[0m" | ||
jobs.each do |k, v| | ||
puts "\e[31m#{k} status is #{v}\e[0m" | ||
end | ||
end | ||
exit 1 | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.