Class: TechnicalDebt
- Inherits:
-
Object
- Object
- TechnicalDebt
- Defined in:
- lib/technical_debt.rb
Instance Method Summary collapse
- #check_connection ⇒ Object
-
#committed_lines_only ⇒ Object
DEBT.
- #connection_exists? ⇒ Boolean
- #debt_lines_only ⇒ Object
- #debt_lines_with_logged ⇒ Object
- #debtify ⇒ Object
- #get_git_token ⇒ Object
- #git_token_exists? ⇒ Boolean
- #git_version ⇒ Object
-
#initialize(dir) ⇒ TechnicalDebt
constructor
A new instance of TechnicalDebt.
- #last_commit ⇒ Object
- #last_commit_sha ⇒ Object
- #log_debt ⇒ Object
-
#log_file ⇒ Object
DEBT 1h Just a sanity check maybe a reality check.
- #log_file_exists? ⇒ Boolean
- #minimum_git_version? ⇒ Boolean
- #no_token_message ⇒ Object
- #project ⇒ Object
- #push_to_technical_debt ⇒ Object
- #read_logged_debt ⇒ Object
- #regex_debt_matcher ⇒ Object
- #register_debt ⇒ Object
- #send_to_server(debt) ⇒ Object
- #split_commit ⇒ Object
- #stripped_debt_line(debt_line) ⇒ Object
Constructor Details
#initialize(dir) ⇒ TechnicalDebt
Returns a new instance of TechnicalDebt.
9 10 11 |
# File 'lib/technical_debt.rb', line 9 def initialize(dir) @project = dir end |
Instance Method Details
#check_connection ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/technical_debt.rb', line 74 def check_connection begin status = Timeout::timeout(2){ Net::HTTP.get(URI.parse("http://google.com")) return true } rescue Exception return false end end |
#committed_lines_only ⇒ Object
DEBT
50 51 52 |
# File 'lib/technical_debt.rb', line 50 def committed_lines_only split_commit.reject { |commited_line| !(commited_line =~ /^\+[^\+]/)} end |
#connection_exists? ⇒ Boolean
85 86 87 |
# File 'lib/technical_debt.rb', line 85 def connection_exists? check_connection ? true : false end |
#debt_lines_only ⇒ Object
54 55 56 |
# File 'lib/technical_debt.rb', line 54 def debt_lines_only committed_lines_only.reject{ |committed_line| !(committed_line =~ regex_debt_matcher)} end |
#debt_lines_with_logged ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/technical_debt.rb', line 58 def debt_lines_with_logged if log_file_exists? debt = debt_lines_only + read_logged_debt File.delete(log_file) else debt = debt_lines_only end debt end |
#debtify ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/technical_debt.rb', line 128 def debtify path = File.(project.to_s) command = "#/bin/sh\ncd #{path} && senddebt ." post_commit_file = "#{path}/.git/hooks/post-commit" File.open(post_commit_file,'w'){ |f| f.write(command) } File.chmod(0755, post_commit_file) puts "Your project is now debtified." end |
#get_git_token ⇒ Object
33 34 35 |
# File 'lib/technical_debt.rb', line 33 def get_git_token `git config --global technicaldebt.token`.strip end |
#git_token_exists? ⇒ Boolean
37 38 39 |
# File 'lib/technical_debt.rb', line 37 def git_token_exists? !get_git_token.blank? end |
#git_version ⇒ Object
17 18 19 |
# File 'lib/technical_debt.rb', line 17 def git_version `git --version`.gsub(/git version/, "").strip end |
#last_commit ⇒ Object
29 30 31 |
# File 'lib/technical_debt.rb', line 29 def last_commit `git diff master~1 head` end |
#last_commit_sha ⇒ Object
21 22 23 |
# File 'lib/technical_debt.rb', line 21 def last_commit_sha `git rev-parse head`.strip end |
#log_debt ⇒ Object
98 99 100 101 |
# File 'lib/technical_debt.rb', line 98 def log_debt File.open(log_file, 'a') { |f| f.write(debt_lines_only.join(",") + ",")} unless git_token_exists? end |
#log_file ⇒ Object
DEBT 1h Just a sanity check maybe a reality check
116 117 118 |
# File 'lib/technical_debt.rb', line 116 def log_file "#{project}/.git/technical_debt" end |
#log_file_exists? ⇒ Boolean
107 108 109 |
# File 'lib/technical_debt.rb', line 107 def log_file_exists? File.exists?("#{project}/.git/technical_debt") end |
#minimum_git_version? ⇒ Boolean
25 26 27 |
# File 'lib/technical_debt.rb', line 25 def minimum_git_version? git_version >= "1.6" end |
#no_token_message ⇒ Object
103 104 105 |
# File 'lib/technical_debt.rb', line 103 def puts "You don't have a token for Technical Debt access. To install it get your token from the website and:\ngit config --global technicaldebt.token your_token_here\nVisit http://technicaldebt.r09.railsrumble.com/account to obtain your token\n" end |
#project ⇒ Object
13 14 15 |
# File 'lib/technical_debt.rb', line 13 def project @project end |
#push_to_technical_debt ⇒ Object
68 69 70 71 72 |
# File 'lib/technical_debt.rb', line 68 def push_to_technical_debt debt_lines_with_logged.each do |debt_line| send_to_server(debt_line) end end |
#read_logged_debt ⇒ Object
111 112 113 |
# File 'lib/technical_debt.rb', line 111 def read_logged_debt File.open(log_file,'r') { |f| f.read.split(",")} end |
#regex_debt_matcher ⇒ Object
45 46 47 |
# File 'lib/technical_debt.rb', line 45 def regex_debt_matcher /^\+\s*#\s*[dD][eE][bB][tT]\s+(.*)$*/ end |
#register_debt ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/technical_debt.rb', line 89 def register_debt if git_token_exists? && connection_exists? && !debt_lines_with_logged.blank? push_to_technical_debt else log_debt end end |
#send_to_server(debt) ⇒ Object
120 121 122 |
# File 'lib/technical_debt.rb', line 120 def send_to_server(debt) Net::HTTP.post_form(URI.parse("http://technicaldebt.r09.railsrumble.com/transactions"), { 'transaction[message]' => stripped_debt_line(debt), 'transaction[sha]' => last_commit_sha, 'git_token' => get_git_token, 'kind' => 'debt' }) end |
#split_commit ⇒ Object
41 42 43 |
# File 'lib/technical_debt.rb', line 41 def split_commit last_commit.split("\n") end |
#stripped_debt_line(debt_line) ⇒ Object
124 125 126 |
# File 'lib/technical_debt.rb', line 124 def stripped_debt_line(debt_line) debt_line[/^\+\s*#\s*[dD][eE][bB][tT]\s+(.*)$/, 1] end |