This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commands moved to classes Changed localization class
- Loading branch information
Strech (Sergey Fedorov)
committed
Aug 12, 2014
1 parent
24f7830
commit 62ec01c
Showing
21 changed files
with
737 additions
and
416 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
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,23 +1,27 @@ | ||
# coding: utf-8 | ||
|
||
require "ansi/code" | ||
require "commander/blank" | ||
require "commander/command" | ||
|
||
module Abak | ||
module Flow | ||
end | ||
end | ||
|
||
require "abak-flow/version" | ||
require "abak-flow/locale" | ||
require "abak-flow/manager" | ||
require "abak-flow/configuration" | ||
require "abak-flow/repository" | ||
require "abak-flow/branch" | ||
require "abak-flow/pull_request" | ||
require "abak-flow/visitor" | ||
require "abak-flow/inspector" | ||
require "abak-flow/errors_presenter" | ||
require "abak-flow/commands/checkup" | ||
require "abak-flow/commands/compare" | ||
require "abak-flow/commands/configure" | ||
require "abak-flow/commands/publish" | ||
require "abak-flow/commands/done" | ||
|
||
|
||
# Может пригодится | ||
# module ::Faraday | ||
# class Response::RaiseOctokitError < Response::Middleware | ||
# def error_message_with_trace(response) | ||
# message = (response[:body].errors || []).map {|error| "=> #{error.code}: #{error.message}" }.join("\n") | ||
|
||
# [error_message_without_trace(response), message].reject { |m| m.empty? }.join("\n\nДополнительные сообщения:\n") | ||
# end | ||
# alias_method :error_message_without_trace, :error_message | ||
# alias_method :error_message, :error_message_with_trace | ||
# end | ||
# end | ||
Abak::Flow::Manager.locale |
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,27 +1,24 @@ | ||
# coding: utf-8 | ||
require "ansi/code" | ||
|
||
module Abak::Flow | ||
module Commands | ||
class Checkup | ||
|
||
def initialize | ||
manager = Manager.instance | ||
|
||
@configuration = manager.configuration | ||
@repository = manager.repository | ||
end | ||
include ANSI::Code | ||
|
||
def run(args, options) | ||
process(args, options) | ||
say ANSI.green { I18n.t("commands.checkup.success") } | ||
|
||
say green { Manager.locale.success(self) } | ||
end | ||
|
||
def process(args, options) | ||
Visitor.new(@configuration, @repository, | ||
command: "checkup", call: :ready?, inspect: :errors) | ||
.on_fail(exit: 1) | ||
inspector = Inspector.new(call_method: :valid?, collect_attribute: :errors) | ||
inspector.examine(Manager.configuration, Manager.repository).on_fail do |insp| | ||
say red { Manager.locale.error(self) } | ||
say yellow { insp.output } | ||
|
||
exit 100 | ||
end | ||
end | ||
end # class Checkup | ||
end # module Commands | ||
end # module Abak::Flow | ||
end # module Abak::Flow |
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,45 +1,35 @@ | ||
# coding: utf-8 | ||
require "commander/blank" | ||
require "commander/command" | ||
require "ansi/code" | ||
# 101 exit code available | ||
|
||
module Abak::Flow | ||
module Commands | ||
class Compare | ||
# TODO : Быть может стоит сделать include ANSI | ||
|
||
def initialize | ||
manager = Manager.instance | ||
|
||
@configuration = manager.configuration | ||
@repository = manager.repository | ||
@git = manager.git | ||
end | ||
include ANSI::Code | ||
|
||
def run(args, options) | ||
Checkup.new.process( | ||
Array.new, ::Commander::Command::Options.new) | ||
Checkup.new.process(Array.new, ::Commander::Command::Options.new) | ||
|
||
current = @git.current_branch | ||
current = Manager.git.current_branch | ||
head = Branch.new(options.head || current) | ||
base = Branch.new(options.base || head.extract_base_name) | ||
|
||
if head.current? | ||
say ANSI.white { | ||
I18n.t("commands.compare.updating", | ||
branch: ANSI.bold { head }, | ||
upstream: ANSI.bold { "#{@repository.origin}" }) } | ||
say white { | ||
Manager.locale.word(self, 'updating', | ||
branch: bold { head }, | ||
upstream: bold { "#{Manager.repository.origin}" }) | ||
} | ||
|
||
head.update | ||
else | ||
say ANSI.yellow { | ||
I18n.t("commands.compare.diverging", | ||
branch: ANSI.bold { head }) } | ||
say yellow { | ||
Manager.locale.word(self, 'diverging', branch: bold { head }) | ||
} | ||
end | ||
|
||
say ANSI.green { head.compare_link(base) } | ||
say green { head.compare_link(base) } | ||
end | ||
|
||
end | ||
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,108 @@ | ||
# coding: utf-8 | ||
require "octokit" | ||
|
||
module Abak::Flow | ||
module Commands | ||
class Configure | ||
include ANSI::Code | ||
|
||
def run(args, options) | ||
process(args, options) | ||
|
||
puts | ||
say green { Manager.locale.success(self) } | ||
end | ||
|
||
def process(args, options) | ||
interview | ||
|
||
password_hash = deffered do | ||
client = Octokit::Client.new(login: @login, password: @password) | ||
response = client.create_authorization( | ||
scopes: ["repo"], note: "abak-flow", | ||
note_url: "https://github.com/Strech/abak-flow", | ||
headers: @headers) | ||
|
||
response[:token] | ||
end | ||
|
||
Manager.configuration.rewrite( | ||
login: @login, password: password_hash, | ||
locale: @locale, http_proxy: @http_proxy) | ||
end | ||
|
||
private | ||
|
||
def interview | ||
@login = ask("#{Manager.locale.word(self, 'email')}: ") | ||
@password = password("#{Manager.locale.word(self, 'password')}: ", nil) | ||
@locale = choose("#{Manager.locale.word(self, 'locale')}:\n", :en, :ru) | ||
@http_proxy = ask("#{Manager.locale.word(self, 'http_proxy')}: ") | ||
@headers = {} | ||
end | ||
|
||
def otp_interview | ||
@headers = {"X-GitHub-OTP" => ask("#{Manager.locale.word(self, 'sms_otp')}: ")} | ||
end | ||
|
||
# TODO : Refactor to object | ||
def deffered(&block) | ||
progressbar.show | ||
thread = Thread.new do | ||
Thread.current[:result] = suppress { block.call } | ||
end | ||
|
||
loop do | ||
progressbar.increment | ||
break if thread.status === false | ||
|
||
if thread.status.nil? | ||
progressbar.erase_line | ||
say red { Manager.locale.error(self, 'execution_failed') } | ||
|
||
exit 102 | ||
end | ||
|
||
sleep 0.3 | ||
end | ||
|
||
case thread[:result] | ||
when Octokit::OneTimePasswordRequired | ||
progressbar.erase_line | ||
otp_interview | ||
|
||
return deffered(&block) | ||
when NilClass | ||
progressbar.erase_line | ||
say red { Manager.locale.error(self, 'empty_response') } | ||
|
||
exit 103 | ||
when Exception | ||
progressbar.erase_line | ||
say red { thread[:result].message } | ||
|
||
exit 104 | ||
else | ||
# no-op | ||
end | ||
|
||
thread[:result] | ||
end | ||
|
||
def progressbar | ||
@progressbar ||= Commander::UI::ProgressBar.new(100, | ||
progress_str: ".", incomplete_str: " ", format: ":title:progress_bar", | ||
complete_message: "", title: Manager.locale.word(self, 'configuring')) | ||
end | ||
|
||
def suppress(&block) | ||
begin | ||
block.call | ||
rescue => error | ||
error | ||
end | ||
end | ||
|
||
end # class Configure | ||
end # module Commands | ||
end # module Abak::Flow |
Oops, something went wrong.