Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
feature(all) total refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech (Sergey Fedorov) committed Aug 27, 2013
1 parent c88eca4 commit 865b814
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 340 deletions.
3 changes: 0 additions & 3 deletions .autotest

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.gem
.ruby-*
.bundle
Gemfile.lock
pkg/*
Expand Down
3 changes: 0 additions & 3 deletions .rspec

This file was deleted.

5 changes: 0 additions & 5 deletions Guardfile

This file was deleted.

47 changes: 19 additions & 28 deletions abak-flow.gemspec
Expand Up @@ -3,35 +3,26 @@ $:.push File.expand_path("../lib", __FILE__)

require "abak-flow/version"

Gem::Specification.new do |s|
s.name = "abak-flow"
s.version = Abak::Flow::VERSION
s.authors = ["Strech (aka Sergey Fedorov)"]
s.email = ["oni.strech@gmail.com"]
s.homepage = "https://github.com/Strech/abak-flow"
s.summary = "Совмещение 2-х подходов разработки Git-flow & Github-flow"
s.description = "Простой набор правил и комманд, заточеных для работы в git-flow с использование в качестве удаленного репозитория github"
Gem::Specification.new do |gem|
gem.name = "abak-flow"
gem.version = Abak::Flow::VERSION
gem.authors = ["Strech (aka Sergey Fedorov)"]
gem.email = ["oni.strech@gmail.com"]
gem.homepage = "https://github.com/Strech/abak-flow"
gem.summary = "Совмещение 2-х подходов разработки Git-flow & Github-flow"
gem.description = "Простой набор правил и комманд, заточеных для работы в git-flow с использование в качестве удаленного репозитория github"

s.rubyforge_project = "abak-flow"
gem.rubyforge_project = "abak-flow"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.require_paths = ["lib"]

s.add_runtime_dependency "octokit", ">= 1.22.0"
s.add_runtime_dependency "git", ">= 1.2.5"
s.add_runtime_dependency "commander", ">= 4.1.3"
s.add_runtime_dependency "ruler", ">= 1.4.2"
s.add_runtime_dependency "i18n", ">= 0.6.1"

s.add_development_dependency "rake"
s.add_development_dependency "rspec"
s.add_development_dependency "simplecov"
s.add_development_dependency "yard"
s.add_development_dependency "yard-tomdoc"
s.add_development_dependency "cane"
s.add_development_dependency "guard"
s.add_development_dependency "guard-rspec"
s.add_development_dependency "rb-fsevent"
gem.add_runtime_dependency "octokit", ">= 1.22.0"
gem.add_runtime_dependency "git", ">= 1.2.5"
gem.add_runtime_dependency "commander", ">= 4.1.3"
gem.add_runtime_dependency "ruler", ">= 1.4.2"
gem.add_runtime_dependency "i18n", ">= 0.6.1"
gem.add_runtime_dependency "ansi", ">= 1.4.3"
end
1 change: 0 additions & 1 deletion bin/request
@@ -1,4 +1,3 @@
#!/usr/bin/env ruby
# coding: utf-8
require 'abak-flow'
require "abak-flow/request"
18 changes: 6 additions & 12 deletions lib/abak-flow.rb
@@ -1,15 +1,9 @@
module Abak
module Flow
autoload :Git, "abak-flow/git"
autoload :Configuration, "abak-flow/configuration"
autoload :Messages, "abak-flow/messages"
autoload :Project, "abak-flow/project"
autoload :System, "abak-flow/system"
autoload :GithubClient, "abak-flow/github_client"
autoload :Branches, "abak-flow/branches"
autoload :Branch, "abak-flow/branch"
autoload :PullRequest, "abak-flow/pull_request"
end
module Flow; end
end

require "abak-flow/version"
require "abak-flow/version" # ✔
require "abak-flow/manager"
require "abak-flow/configuration"
require "abak-flow/repository"
require "abak-flow/request"
83 changes: 46 additions & 37 deletions lib/abak-flow/configuration.rb
@@ -1,59 +1,68 @@
# coding: utf-8
#
# Module for access to global abak-flow gem config
# recieved from .git config and environment
#
# Auto generated methods: oauth_user, oauth_token, proxy_server
#
# TODO : Проверять что атрибут из конфига валиден
# TODO : Переименовать модуль
#
# Example
#
# Abak::Flow::Configuration.oauth_user #=> Strech
#
require "singleton"
require "i18n"
require "ruler"
require "forwardable"
require "ostruct"

module Abak::Flow
class Configuration
include Singleton
include Ruler
extend Forwardable

def_delegator "Abak::Flow::Git.instance", :git
OPTIONS = [:oauth_user, :oauth_token, :locale, :http_proxy].freeze
LOCALE_FILES = File.join(File.dirname(__FILE__), "locales/*.{rb,yml}").freeze

attr_reader :params
def_delegators :@manager, :git

def initialize
load_git_configuration
setup_locale
attr_reader :errors

def initialize(manager)
@manager = manager
@errors = []

configure!
end

private
def load_git_configuration
git_config = git.config.select { |k, _| k.include? "abak-flow." }
.map { |k,v| [convert_param_name_to_method_name(k), v] }
def ready?
@errors = []

@params = Params.new(Hash[git_config]).tap do |p|
p.locale ||= "en"
p.proxy_server ||= environment_http_proxy
multi_ruleset do
fact(:oauth_user_not_setup) { oauth_user.nil? }
fact(:oauth_token_not_setup) { oauth_token.nil? }

rule([:oauth_user_not_setup]) { @errors << I18n.t("configuration.errors.oauth_user_not_setup") }
rule([:oauth_token_not_setup]) { @errors << I18n.t("configuration.errors.oauth_token_not_setup") }
end

@errors.empty? ? true : false
end

def setup_locale
I18n.load_path += Dir.glob(File.join File.dirname(__FILE__), "locales/*.{rb,yml}")
I18n.locale = params.locale
def configure!
load_gitconfig
setup_locale
end

def environment_http_proxy
ENV["http_proxy"] || ENV["HTTP_PROXY"]
private
def setup_locale
I18n.load_path += Dir.glob(LOCALE_FILES)
I18n.locale = locale
end

def convert_param_name_to_method_name(name)
name.sub(/abak-flow./, "").gsub(/\W/, "_")
def load_gitconfig
git_config = git.config.select { |k, _| k.include? "abak-flow." }
.map { |k,v| [to_method_name(k), v] }


config = Hash[git_config]
config[:locale] ||= "en"
config[:http_proxy] ||= ENV["http_proxy"] || ENV["HTTP_PROXY"]

OPTIONS.each do |name|
define_singleton_method(name) { config[name] }
end
end

class Params < OpenStruct; end
def to_method_name(name)
name.sub(/abak-flow./, "").gsub(/\W/, "_").to_sym
end
end
end
end
20 changes: 0 additions & 20 deletions lib/abak-flow/git.rb

This file was deleted.

50 changes: 16 additions & 34 deletions lib/abak-flow/locales/en.yml
@@ -1,37 +1,19 @@
en:
commands:
checkup: &command_checkup
you_are_ready: "Yaw, you are ready!"
you_are_not_prepared: "You are not prepared!"
publish:
<<: *command_checkup
lets_do_it: "Let's do it!"
request_published: "Yaw, your request published!"
something_goes_wrong: "Goddamned, something goes wrong ..."
garbage:
searching_for_garbage: "Searching for garbage ..."
garbage_detected: "Some part of garbage detected"
no_garbage_detected: "Yaw, no garbage detected!"
configuration:
name: Configuration
errors:
oauth_user_not_setup: Options oauth_user not setted
oauth_token_not_setup: Options oauth_token not setted
recommendations: "Check [abak-flow] section in ~/.gitcofig file"

system:
recommendations:
header: "== System recommendations =="
set_up_origin: "Set up your origin"
set_up_upstream: "Set up your upstream"
set_up_oauth_user: "Set up your abak-flow.oauth-user"
set_up_oauth_token: "Set up your abak-flow.oauth-token"
information:
header: "== System information =="
proxy_server_set_up: "You set up the custom proxy server"
repository:
name: Repository
errors:
origin_not_setup: Repository with name 'origin' not found
upstream_not_setup: Repository with name 'upstream' not found
recommendations: "Check .git/cofig file"

pull_request:
publish:
forgot_task: "Sorry, i forgot my task number. Ask me personally if you have any questions"
garbage:
collected_branches: "Branches collected: %{count}"
deletion_allowed: "%{index}. %{branch_name} → deletion allowed"
deletion_possibly: "%{index}. %{branch_name} → deletion possibly\n%{diagnoses}"
deletion_restricted: "%{index}. %{branch_name} → deletion restricted\n%{diagnoses}"
branch_unused: "Branch is unused in upstream"
branch_differ: "Branch is differ than origin"
branch_missing: "Branch is missing in local repo"
commands:
checkup:
fail: "You are not prepared!"
success: "Congratulations, you are ready to ROCK :)"
35 changes: 17 additions & 18 deletions lib/abak-flow/locales/ru.yml
@@ -1,20 +1,19 @@
ru:
configuration:
name: Корфигурация
errors:
oauth_user_not_setup: Не установлена опция oauth_user
oauth_token_not_setup: Не установлена опция oauth_token
recommendations: "Проверьте секцию [abak-flow] в файле ~/.gitcofig"

repository:
name: Репозиторий
errors:
origin_not_setup: Репозиторий с именем 'origin' не найден
upstream_not_setup: Репозиторий с именем 'upstream' не найден
recommendations: Проверьте файл .git/cofig

commands:
checkup: &command_checkup
you_are_ready: "Ура, все готово!"
you_are_not_prepared: "Кажется вы все еще не готовы!"
publish:
<<: *command_checkup
lets_do_it: "Начинаю публиковать пул реквест"
request_published: "Ура, пул реквест опубликован!"
something_goes_wrong: "Так, кажется что-то пошло не так ..."
system:
recommendations:
header: "== Рекомендации по конфигурации =="
set_up_origin: "Укажите origin репозиторий"
set_up_upstream: "Укажите upstream репозиторий"
set_up_oauth_user: "Пропишите git конфигурацию abak-flow.oauth-user"
set_up_oauth_token: "Пропишите git конфигурацию abak-flow.oauth-token"
information:
header: "== Информация по конфигурации =="
proxy_server_set_up: "Вы указали свой proxy server"
checkup:
fail: "Вы не готовы!"
success: "Поздравляем, вы готовы чтобы жечь :)"
28 changes: 28 additions & 0 deletions lib/abak-flow/manager.rb
@@ -0,0 +1,28 @@
# coding: utf-8
require "git"

module Abak::Flow
class Manager

def initialize
# preload dependencies
configuration
repository

yield self if block_given?
end

def configuration
@configuration ||= Configuration.new(self)
end

def repository
@repository ||= Repository.new(self)
end

def git
@git ||= Git.open(".")
end

end
end

0 comments on commit 865b814

Please sign in to comment.