Module: GitIssue::Helper
- Included in:
- Base
- Defined in:
- lib/git_issue.rb
Constant Summary collapse
- CONFIGURE_MESSAGE =
<<-END please set issue tracker %s. %s END
Class Method Summary collapse
- .configure_error(attr_name, example) ⇒ Object
- .configured_value(name, trim = true) ⇒ Object
- .get_body_from_editor(message = nil) ⇒ Object
- .get_title_and_body_from_editor(message = nil) ⇒ Object
- .global_configured_value(name) ⇒ Object
- .its_klass_of(its_type) ⇒ Object
Instance Method Summary collapse
- #git_editor ⇒ Object
- #open_editor(message = nil, abort_if_not_modified = true) {|text.strip| ... } ⇒ Object
- #read_body(file) ⇒ Object
- #split_head_and_body(text) ⇒ Object
- #work_dir ⇒ Object
Class Method Details
.configure_error(attr_name, example) ⇒ Object
43 44 45 |
# File 'lib/git_issue.rb', line 43 def configure_error(attr_name, example) raise CONFIGURE_MESSAGE % [attr_name, example] end |
.configured_value(name, trim = true) ⇒ Object
48 49 50 51 52 |
# File 'lib/git_issue.rb', line 48 def configured_value(name, trim = true) res = `git config #{name}` res = trim ? res.strip : res res end |
.get_body_from_editor(message = nil) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/git_issue.rb', line 112 def get_body_from_editor(=nil) open_editor() do |text| abort "Aborting due to empty message" if text.empty? text end end |
.get_title_and_body_from_editor(message = nil) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/git_issue.rb', line 104 def get_title_and_body_from_editor(=nil) open_editor() do |text| title, body = split_head_and_body(text) abort "Aborting due to empty issue title" unless title [title, body] end end |
.global_configured_value(name) ⇒ Object
54 55 56 57 |
# File 'lib/git_issue.rb', line 54 def global_configured_value(name) res = `git config --global #{name}` res.strip end |
.its_klass_of(its_type) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/git_issue.rb', line 59 def its_klass_of(its_type) case its_type when /redmine/i then GitIssue::Redmine when /github/i then GitIssue::Github when /bitbucket/i then GitIssue::Bitbucket else raise "unknown issue tracker type : #{its_type}" end end |
Instance Method Details
#git_editor ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/git_issue.rb', line 69 def git_editor # possible: ~/bin/vi, $SOME_ENVIRONMENT_VARIABLE, "C:\Program Files\Vim\gvim.exe" --nofork editor = `git var GIT_EDITOR` editor = ENV[$1] if editor =~ /^\$(\w+)$/ editor = File. editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/ editor.shellsplit end |
#open_editor(message = nil, abort_if_not_modified = true) {|text.strip| ... } ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/git_issue.rb', line 119 def open_editor( = nil, abort_if_not_modified = true , &block) = File.join(work_dir, 'ISSUE_MESSAGE') File.open(, 'w') { |msg| msg.puts } begin edit_cmd = Array(git_editor).dup edit_cmd << '-c' << 'set ft=gitcommit' if edit_cmd[0] =~ /^[mg]?vim$/ edit_cmd << system(*edit_cmd) abort "can't open text editor for issue message" unless $?.success? text = read_body() abort "Aborting cause messages didn't modified." if == text && abort_if_not_modified ensure File.unlink() end yield text.strip end |
#read_body(file) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/git_issue.rb', line 97 def read_body(file) f = open(file) body = f.read f.close body end |
#split_head_and_body(text) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/git_issue.rb', line 84 def split_head_and_body(text) title, body = '', '' text.each_line do |line| next if line.index('#') == 0 ((body.empty? and line =~ /\S/) ? title : body) << line end title.tr!("\n", ' ') title.strip! body.strip! [title =~ /\S/ ? title : nil, body =~ /\S/ ? body : nil] end |
#work_dir ⇒ Object
77 78 79 80 81 82 |
# File 'lib/git_issue.rb', line 77 def work_dir dir = RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin|cygwin/ ? `git rev-parse -q --git-dir 2> NUL`.strip : `git rev-parse -q --git-dir 2> /dev/null`.strip dir.empty? ? Dir.tmpdir : dir end |