Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code climate #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Metrics/MethodLength:
Max: 50
Metrics/AbcSize:
Max: 20
Exclude:
# mixin_config tends to overshoot, but is
# still easily readable
- lib/miq_flow/mixin_config.rb

Layout/SpaceBeforeBlockBraces:
EnforcedStyle: no_space
Expand Down
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ matrix:
env: TAG=latest
- name: "Hammer + Integration"
rvm: 2.4
env: TAG=latest-hammer SUITE=integration

before_install:
- script/prepare_manageiq.sh
- ruby -ryaml -e "c={'log_level'=>'debug', 'git'=>{'url'=>'https://github.com/ThomasBuchinger/automate-example'}}; puts c.to_yaml" > config.yaml
env: TAG=latest-hammer GIT_URL=https://github.com/ThomasBuchinger/automate-example
stage: integration
script:
- script/prepare_manageiq.sh
- rake install:local
- miq-flow deploy feature-1-f1 --provider docker --git-index 2
- ./script/verify_import.sh
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- bundle check # ManageIQ Container/Appliance needs to satisfy all dependencies
- rake install:local
- miq-flow deploy feature-1-f1 --provider docker
- ./script/verify_import.sh
- bundle install --with development
- bundle exec rake travis
after_script:
- bundle exec rake coveralls:push
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Changelog

## [Unreleased] ????-??-??
## [1.0.0-rc1] 2019-01-28
### Added
- Initial commit
- Added APACHE-2 LICENSE
- Features:
- YAML based configuration
- Configuration sources:
- YAML files
- CLI parameter
- Environment variables
- Returns exit codes
- Query ManageIQ API
- Repository is cloned in the background and cleaned before the
program exists
- Supports multiple Automate Domains
- Availalbe Commands:
- miq-flow deploy
- miq-flow inspect
- miq-flow list branches
- miq-flow list domains
- miq-flow branch inspect
- miq-flow branch list
- miq-flow domain list
- Availalbe Providers:
- provider_local (to be used on MIQ appliances)
- provider_noop (does nothing)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ManageIQ Workflow Automate Importer
[![Build Status](https://travis-ci.org/ThomasBuchinger/automate-gitflow.svg?branch=master)](https://travis-ci.org/ThomasBuchinger/automate-gitflow)
[![Build Status](https://travis-ci.org/ThomasBuchinger/miq-flow.svg?branch=master)](https://travis-ci.org/ThomasBuchinger/miq-flow)
[![Maintainability](https://api.codeclimate.com/v1/badges/7c4a493f5d03a662bc27/maintainability)](https://codeclimate.com/github/ThomasBuchinger/miq-flow/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/7c4a493f5d03a662bc27/test_coverage)](https://codeclimate.com/github/ThomasBuchinger/miq-flow/test_coverage)

This command line utility implements a git-based branching workflow on top of the default ManageIQ Automate Import scripts.

Expand Down
15 changes: 13 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
# Set logging level
# If set to no_log, no log output will be generated
# Default: info
# Possible values: debug, info, warn, error, fatal
# Possible values: debug, info, warn, error, fatal, no_log
# log_level: info

# git:
Expand All @@ -19,7 +20,17 @@
# Specify credentials for the repository.
# NOTE: only HTTP Authenication is supported
# user: someone
# password: <TOKEN>
# pashsword: <TOKEN>

# Branch naming scheme
# This configures the naming scheme for your git branches (if you use one)
# and how MiqFlow derives a name for the domains imported from that branch.
# The default configuration matches: TYPE-NAME-optional-description
#
# characters used to separate part of yu naming convention
# separators: [ '-', '/' ]
# index of the NAME part in your naming convention (starts with 0)
# index: 1

# miq:
# url: https://localhost/api
Expand Down
5 changes: 3 additions & 2 deletions lib/miq_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
require 'miq_flow/mixin_git'
require 'miq_flow/mixin_api'
require 'miq_flow/mixin_settings'
require 'miq_flow/mixin_config'
require 'miq_flow/manageiq'
require 'miq_flow/domain'
require 'miq_flow/feature'
require 'miq_flow/miqflow'
require 'miq_flow/cli/cli'
require 'miq_flow/cli'
require 'miq_flow/version'

$settings = {}
$settings[:miq] = {}
$settings[:git] = {}
MiqFlow::Settings.set_defaults()
MiqFlow::Config.set_defaults()
2 changes: 1 addition & 1 deletion lib/miq_flow/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require_relative 'cli/cli.rb'
require_relative 'cli/main.rb'
31 changes: 31 additions & 0 deletions lib/miq_flow/cli/branch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'thor'

module MiqFlow
module Cli
# Implements list subcommand
class BranchCli < Thor
include MiqFlow::Cli

desc 'list', 'List avaliable Feature Branches'
def list
cli_setup(options, %i[git])
branches = MiqFlow::GitMethods.get_remote_branches()
text = branches.map{ |b| MiqFlow::Feature.new(b.name, {}).show_summary() }
puts text
MiqFlow.tear_down()
end

desc 'inspect BRANCH', 'Show detailed information about this Feature-Branch'
option :short, type: :boolean, default: false, desc: 'Same as list'
def inspect(name)
cli_setup(options, %i[git])
feature = MiqFlow::Feature.new(name, {})
text = options[:short] ? feature.show_summary() : feature.show_details()
puts text
MiqFlow.tear_down()
end
end
end
end
68 changes: 0 additions & 68 deletions lib/miq_flow/cli/cli.rb

This file was deleted.

19 changes: 19 additions & 0 deletions lib/miq_flow/cli/domain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'thor'

module MiqFlow
module Cli
# Implements list subcommand
class DomainCli < Thor
include MiqFlow::Cli

desc 'list', 'List existing Automate Domains in ManageIQ'
def list
cli_setup(options, %i[api])
api = MiqFlow::ManageIQ.new
puts api.list_domains
end
end
end
end
28 changes: 0 additions & 28 deletions lib/miq_flow/cli/list.rb

This file was deleted.

73 changes: 73 additions & 0 deletions lib/miq_flow/cli/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true

require 'thor'
require_relative 'branch.rb'
require_relative 'domain.rb'

module MiqFlow
# Implements common CLI methods
module Cli
def cli_setup(options={}, mode=[])
MiqFlow::Config.process_cli_flags(options) # Set log level first
MiqFlow::Config.search_config_files()
MiqFlow::Config.process_environment_variables()
MiqFlow::Config.process_config_file(options['config'])
MiqFlow::Config.process_cli_flags(options) # And again for precedence

MiqFlow.validate(mode)
MiqFlow.init()
MiqFlow.prepare_repo()
end

# Implements CLI
class MainCli < Thor
include MiqFlow::Cli

def self.exit_on_failure?
true
end

class_option :verbose, type: :boolean, default: false, desc: 'Turn on verbose logging'
class_option :quiet, type: :boolean, default: false, desc: 'Only show errors and warnings'
class_option :silent, type: :boolean, default: false, desc: 'Do not output anything'
class_option :cleanup, type: :boolean, desc: 'Clean up the working dir before exiting'
class_option :workdir, type: :string, desc: 'Override the working directory'
class_option :config, type: :string, alias: '-c', desc: 'Specify config file to load'

class_option :git_url, type: :string, desc: 'Git clone URL for remote repositories'
class_option :git_path, type: :string, desc: 'path to a local git repositories'
class_option :git_user, type: :string, desc: 'Username for remote repositories'
class_option :git_password, type: :string, desc: 'Password/token for remote repositories'
class_option :git_separator, type: :string, desc: 'List of characters separating part of your ' \
'branch naming convention'
class_option :git_index, type: :numeric, desc: 'Index the NAME par of your branch naming convenion'

class_option :miq_url, type: :string, desc: 'ManageIQ API URL. (e.g. https://localhost/api)'
class_option :miq_user, type: :string, desc: 'ManageIQ API User. (default: admin)'
class_option :miq_password, type: :string, desc: 'Passwork/login-token for the ManageIQ API User'

desc 'branch', 'Branch commands'
subcommand 'branch', MiqFlow::Cli::BranchCli

desc 'domain', 'Domain commands'
subcommand 'domain', MiqFlow::Cli::DomainCli

desc 'deploy BRANCH', 'Deploy a Feature Branch'
option :name, desc: 'specify domain identifier (default: 3rd segment of NAME, separated by \'-\')'
option :priority, type: :numeric, desc: 'Not-yet-implemented'
option :provider, desc: 'How to talk to ManageIQ (default: noop)'
def deploy(branch)
cli_setup(options, %i[git miq])
miq_domain = options[:name]
provider = options.fetch(:provider, 'default')
prio = options[:miq_priority]

opts = { feature_name: miq_domain, provider: provider }
opts[:miq_priotiry] = prio
feature = MiqFlow::Feature.new(branch, opts)
feature.deploy()
MiqFlow.tear_down()
end
end
end
end
2 changes: 1 addition & 1 deletion lib/miq_flow/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.create_from_file(dom)
opts[:provider_name] = dom[:provider]
opts[:branch_name] = dom[:branch_name]

new_name = "feature_#{dom[:feature_name]}_#{opts[:export_name]}"
new_name = "feat_#{dom[:feature_name]}_#{opts[:export_name]}"
opts.reject!{ |_, value| value.nil? }
self.new(new_name, opts)
end
Expand Down
9 changes: 5 additions & 4 deletions lib/miq_flow/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Feature
# @option opts [String] :base('master')
# @option opts [Array<String>] :prefix(feature, fix)
def _set_defaults(opts={})
@remote_name = opts.fetch(:remote_name, 'origin')
@base = opts.fetch(:base, 'master')
@prefixes = opts.fetch(:prefix, %w[feature fix])
@remote_name = opts.fetch(:remote_name, 'origin')
@base = opts.fetch(:base, 'master')
# unused
@prefixes = opts.fetch(:prefix, [''])
end

# Represents a feature-branch
Expand All @@ -32,7 +33,7 @@ def _set_defaults(opts={})
# @option opts @see _set_defaults
def initialize(branch_name, opts={})
_set_defaults(opts)
@name = opts.fetch(:feature_name, branch_name.split(/-/)[2]) || File.basename(branch_name)
@name = opts.fetch(:feature_name, nil) || name_from_branch(branch_name)
$logger.debug("Creating Feature: branch=#{branch_name} domain=#{@name}")

@git_repo = opts.fetch(:git_repo, nil) || $git_repo
Expand Down
Loading