Class: Monotes::CLI::Application

Inherits:
Thor
  • Object
show all
Includes:
AppDirectory
Defined in:
lib/monotes/cli/application.rb

Instance Method Summary collapse

Methods included from AppDirectory

#app_path

Instance Method Details

#create(repository_name, title) ⇒ Object



73
74
75
76
77
78
# File 'lib/monotes/cli/application.rb', line 73

def create(repository_name, title)
  text = Monotes::BodyText.new(title)
  issue = text.create_issue
  repository = Monotes::IssueRepository.build(repository: repository_name)
  repository.append(issue)
end

#download(repository) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/monotes/cli/application.rb', line 47

def download(repository)
  STDOUT.puts "Downloading issues for #{repository}..."
  downloader = Monotes::IssueDownload.new(Octokit)
  begin
    issues = downloader.download(repository)
  rescue Exception => exc
    fatal!(exc)
  end
  repository = Monotes::IssueRepository.build(repository: repository)
  repository.save(issues)
end

#loginObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/monotes/cli/application.rb', line 19

def 
  print "Username > "
  username = STDIN.gets.chomp
  validate!("username", username)
  print "Password > "
  password = STDIN.noecho(&:gets).chomp
  validate!("password", password)
  STDOUT.puts "\n"
  authenticator = Monotes::Authenticator.new(Octokit::Client)
  begin
    oauth_token = authenticator.get_oauth_token(username, password) do
      print "Two-Factor token > "
      token = STDIN.gets.chomp
      validate!("Two-Factor token", token)
      token
    end
  rescue Octokit::Unauthorized => unauthorized
    STDERR.puts "Unauthorized: #{unauthorized.message}"
    exit 77
  rescue Exception => e
    fatal!(e)

  else
    write_to_netrc(username, oauth_token.token)
  end
end

#show(repository_name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/monotes/cli/application.rb', line 60

def show(repository_name)
  repository = Monotes::IssueRepository.build(repository: repository_name)
  issues = repository.load
  issues.map do |issue|
    if issue.unsynced?
      STDOUT.puts "(new) - #{issue.title}"
    else
      STDOUT.puts "#{issue.number} - #{issue.title}"
    end
  end
end

#sync(repository_name) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/monotes/cli/application.rb', line 81

def sync(repository_name)
  repository = Monotes::IssueRepository.build(repository: repository_name)
  issues = repository.load
  already_synced = issues.reject { |i| i.unsynced? }
  adapter = Octokit::Client.new(netrc: true)
  begin
    sync_list = Monotes::SyncList.new(list: issues, repo: repository_name, adapter: adapter)
    synced = sync_list.sync do |issue|
      STDOUT.puts "Synced issue #{issue.title}"
    end
  rescue Exception => exc
    fatal!(exc)
  end
  repository.save(already_synced.concat(synced))
end