Class: Herodot::Commands
- Inherits:
-
Object
- Object
- Herodot::Commands
- Defined in:
- lib/herodot/commands.rb
Constant Summary collapse
- SCRIPT =
"#!/bin/bash\n"\ "echo 'Logging into worklog'\n"\ "project=$(pwd)\n"\ "branch=$(git rev-parse --abbrev-ref HEAD)\n"\ 'echo "$(date);$project;$branch" >> ~/worklog'.freeze
- DEFAULT_RANGE =
'this week'.freeze
Class Method Summary collapse
- .link(path) ⇒ Object
- .link_github(path) ⇒ Object
- .link_gitlab(path) ⇒ Object
- .link_jira(path) ⇒ Object
- .link_other(path) ⇒ Object
- .show(args, config, opts = {}) ⇒ Object
- .track(path, config) ⇒ Object
Class Method Details
.link(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/herodot/commands.rb', line 34 def self.link(path) path = '.' if path.nil? choose do || .prompt = 'What tracker do you want to link to?' .choice(:jira) { link_jira(path) } .choice(:github) { link_github(path) } .choice(:gitlab) { link_gitlab(path) } .choices(:other) { link_other(path) } .default = :other end end |
.link_github(path) ⇒ Object
52 53 54 55 |
# File 'lib/herodot/commands.rb', line 52 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 |
.link_gitlab(path) ⇒ Object
57 58 59 60 |
# File 'lib/herodot/commands.rb', line 57 def self.link_gitlab(path) handle = ask('GitLab handle (something/something for https://gitlab.com/something/something)?') Herodot::ProjectLink.link(path, "https://gitlab.com/#{handle}/issues/", '\\d+') end |
.link_jira(path) ⇒ Object
46 47 48 49 50 |
# File 'lib/herodot/commands.rb', line 46 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 |
.link_other(path) ⇒ Object
62 63 64 65 66 |
# File 'lib/herodot/commands.rb', line 62 def self.link_other(path) url = ask('URL to issue tracker:') pattern = ask('Ticket regex pattern (ruby):') Herodot::ProjectLink.link(path, url, pattern) end |
.show(args, config, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/herodot/commands.rb', line 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) decorated_worklog = Herodot::ProjectLink.new(worklog) output = Herodot::Output.print(decorated_worklog.totals, opts) puts output end |
.track(path, config) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/herodot/commands.rb', line 22 def self.track(path, config) path = '.' if path.nil? puts "Start tracking of `#{File.expand_path(path)}` into `#{config.worklog_file}`." hooks = "#{path}/.git/hooks" abort('Path is not a git repository.') unless File.exist?(hooks) %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 |