Class: Git2Mite::App

Inherits:
Object
  • Object
show all
Defined in:
lib/git2mite/app.rb

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



24
25
26
27
# File 'lib/git2mite/app.rb', line 24

def initialize
  @gui = Gui.new
  @repo  = GitRepo.new
end

Instance Method Details

#check_if_git_repo!Object



15
16
17
# File 'lib/git2mite/app.rb', line 15

def check_if_git_repo!
  @gui.error "Please change to a directory that is a git repository." unless @repo.is_git_repo?
end

#check_ruby_version!Object



19
20
21
# File 'lib/git2mite/app.rb', line 19

def check_ruby_version!
  @gui.error "Sorry you need Ruby 1.8.7+ for this." if RUBY_VERSION < '1.8.7'
end

#configurationObject



3
4
5
# File 'lib/git2mite/app.rb', line 3

def configuration
  @configuration ||= Git2Mite::Configuration.new
end

#get_api_keyObject



7
8
9
# File 'lib/git2mite/app.rb', line 7

def get_api_key
  configuration.api_key ||= @gui.ask('What is your api key?').strip
end

#get_sub_domainObject



11
12
13
# File 'lib/git2mite/app.rb', line 11

def get_sub_domain
  configuration.sub_domain ||= @gui.ask('What is your account subdomain?').strip
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/git2mite/app.rb', line 29

def run
  @gui.print_welcome
  check_if_git_repo!
  check_ruby_version!
  client = MiteClient.new("http://#{get_sub_domain}.mite.yo.lk", get_api_key)
  project_id = @gui.get_project_id(client.projects)
  user_id = @gui.get_user_id(User.all(client))
  start_date = @gui.get_date('start date')
  end_date = @gui.get_date('end date')
  commits = @repo.commits start_date, end_date
  author = @gui.get_author commits.map{|date, message, _author| _author}.uniq

  puts
  puts 'Writing commits to mite'

  commits.each do |date, message, _author|
    next unless _author == author
    entries = client.time_entries project_id, user_id, date
    if entries.empty?
      STDERR.puts "WARN no time entries for commit #{date.to_s}: #{message}"
    else
      entry = entries[rand(entries.size)]['time_entry']
      client.add_message_to_entry entry, message
      print "."
    end
  end
  puts 'done'
end