lib/herodot/commands.rb in herodot-0.1.8 vs lib/herodot/commands.rb in herodot-0.1.9

- old
+ new

@@ -12,11 +12,12 @@ def self.show(args, config, opts = {}) subject = args.empty? ? DEFAULT_RANGE : args.join(' ') range = Chronic.parse(subject, guess: false, context: :past) abort "Date not parsable: #{args.join(' ')}" unless range worklog = Herodot::Parser.parse(range, config) - output = Herodot::Output.print(worklog.totals, opts) + decorated_worklog = Herodot::ProjectLink.new(worklog) + output = Herodot::Output.print(decorated_worklog.totals, opts) puts output end def self.track(path, config) path = '.' if path.nil? @@ -26,7 +27,35 @@ %w(post-checkout post-commit).each do |name| File.open("#{hooks}/#{name}", 'w') { |file| file.write(SCRIPT) } File.chmod(0o755, "#{hooks}/#{name}") FileUtils.touch(config.worklog_file) end + end + + def self.link(path) + path = '.' if path.nil? + choose do |menu| + menu.prompt = 'What tracker do you want to link to?' + menu.choice(:jira) { link_jira(path) } + menu.choice(:github) { link_github(path) } + menu.choices(:other) { link_other(path) } + menu.default = :other + end + end + + def self.link_jira(path) + prefix = ask('Jira URL prefix (something for https://something.atlassian.net)?') + pattern = ask('Ticket prefix (ABCD for tickets like ABCD-123)') + Herodot::ProjectLink.link(path, "http://#{prefix}.atlassian.net/browse/", "#{pattern}-\\d+") + end + + def self.link_github(path) + handle = ask('Github handle (something/something for https://github.com/something/something)?') + Herodot::ProjectLink.link(path, "https://github.com/#{handle}/issues/", '\\d+') + end + + def self.link_other(path) + url = ask('URL to issue tracker:') + pattern = ask('Ticket regex pattern (ruby):') + Herodot::ProjectLink.link(path, url, pattern) end end