Class: GITPOINT::App

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

Instance Method Summary collapse

Instance Method Details

#langstatsObject

Raises:

  • (Error)


6
7
8
9
10
11
12
13
14
15
16
17
18
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
45
46
47
# File 'lib/gitpoint/app.rb', line 6

def langstats

  # Fetch Repositories of Organization
  say Rainbow("Connecting to github & fetching organization\'s repos...").bright
  repos = Git.new.fetch(:all, {org: options[:organization], visibility: 'public'})
  if repos[:status] == 200
    say Rainbow("Organization\'s repos fetched successfully!").green
  else
    say Rainbow("Something went wrong!").red
    raise Error, Rainbow(repos[:error_message]).red
  end

  @repositories = repos[:response]
  raise Error, Rainbow("Github API response is empty! Process cannot continue").red if @repositories.nil?

  fetch_repository_names

  # Fetch Languages used per repository
  @languages = []

  say Rainbow("Fetching repos\'s languages...").bright
  @repository_names.each do |repo|
    repo_languages = Git.new.fetch(:list_languages, {user: options[:organization], repo: repo})
    if repo_languages[:status] == 200
      @languages << repo_languages[:response].keys unless repo_languages[:response].nil?
    else
      say Rainbow("Something went wrong!").red
      raise Error, Rainbow(repos[:error_message]).red
    end
  end

  say Rainbow("Computng results...").bright
  calculate_language_appearance

  # Print Results to User
  results = {
    "organization" => options[:organization],
    "languages" => Hash[@language_hash.sort_by {|k, v| -v}]
  }

  say Rainbow(JSON.pretty_generate(results)).green
end