Skip to content

Commit

Permalink
rubocop configuration added, jobs tracking run with follow, helper cl…
Browse files Browse the repository at this point in the history
…ass added
  • Loading branch information
wdhif committed May 16, 2017
1 parent 7baf3d9 commit 4d684c1
Show file tree
Hide file tree
Showing 15 changed files with 416 additions and 353 deletions.
40 changes: 40 additions & 0 deletions .rubocop.yml
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
2 changes: 1 addition & 1 deletion Gemfile
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
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
specs:
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
ast (2.3.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
Expand All @@ -27,7 +28,12 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
netrc (0.11.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
public_suffix (2.0.5)
rainbow (2.2.2)
rake
rake (10.5.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -46,6 +52,13 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rubocop (0.48.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
safe_yaml (1.0.4)
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
Expand All @@ -68,4 +81,5 @@ DEPENDENCIES
rake (~> 10.0)
rspec (~> 3.0)
rspec-mocks
rubocop
webmock
6 changes: 3 additions & 3 deletions Rakefile
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
4 changes: 2 additions & 2 deletions bin/gitlabci-cli
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
43 changes: 22 additions & 21 deletions gitlabci-cli.gemspec
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
5 changes: 3 additions & 2 deletions lib/gitlabci/controller.rb
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
19 changes: 12 additions & 7 deletions lib/gitlabci/controller/cli.rb
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
74 changes: 74 additions & 0 deletions lib/gitlabci/controller/helper.rb
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
Loading

0 comments on commit 4d684c1

Please sign in to comment.