Class: Veye::Project::Check

Inherits:
BaseExecutor show all
Extended by:
FormatHelpers
Defined in:
lib/veye/project/check.rb

Overview

Check class includes methods to check and upload project files

Class Method Summary collapse

Methods included from FormatHelpers

format_exists?, formats_attached?, supported_format?

Methods inherited from BaseExecutor

catch_request_error, filter_dependencies, get_formatter, process_dependencies, show_bulk_dependencies, show_dependencies, show_message, show_results, sort_dependencies_by_upgrade_complexity, valid_response?

Class Method Details

.check(api_key, path, files, options) ⇒ Object

checks project file and initializes veye.json file iff it’s missing files - an array with filenames to check, [‘Gemfile’, ‘bower.json’] path - nil or string, a relative path to the project root directory



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/veye/project/check.rb', line 70

def self.check(api_key, path, files, options)
  project_settings = Veye::Settings.load(path)
  #initialize project settings to keep various project specific data
  if project_settings.nil?
    file_map = files.to_a.inject({}) {|acc, x| acc.store(x, nil); acc}
    opts = {'projects' => file_map}
    project_settings = Veye::Settings.init(path, opts)
  end

  unless project_settings.has_key?('projects')
    printf "veye.json is malformed - missing `project` key".color(:red)
    exit 0
  end

  deps = {}
  project_settings['projects'].each do |filename, project_id|
    filepath = "#{path}/#{filename}"
    results = if project_id.to_s.empty?
                Veye::API::Project.upload(api_key, filepath, options[:org], options[:team],
                                          options[:temporary], options[:public], options[:name])
              else
                Veye::API::Project.update(api_key, project_id, filepath)
              end

    error_msg = "Failed to check dependencies for `#{filename.to_s.color(:red)}`"
    if valid_response?(results, error_msg)
      deps[filename] = results.data
      project_settings['projects'].store(filename, results.data['id'])
    else
      deps[filename] = {error: "Failed to check a file `#{filepath}`"}
    end
  end

  Veye::Settings.dump(path, project_settings)
  printf(
    "Checked files: %s\nproject ids are saved into `%s`\n",
    files.to_a.join(', ').to_s.color(:green),
    "veye.json".color(:yellow)
  )
  options[:all] = true #hack
  show_bulk_dependencies(@dependency_output_formats, deps, options)
end

.delete_project(api_key, project_key) ⇒ Object



113
114
115
116
117
118
# File 'lib/veye/project/check.rb', line 113

def self.delete_project(api_key, project_key)
  results = Veye::API::Project.delete_project(api_key, project_key)
  err_msg = "Failed to delete project: `#{project_key}`"
  valid_response?(results, err_msg)
  show_message(results, 'Deleted', 'Cant delete.')
end

.get_list(api_key, org_name = 'private', team_name = nil, options) ⇒ Object



26
27
28
29
30
31
# File 'lib/veye/project/check.rb', line 26

def self.get_list(api_key, org_name = 'private', team_name = nil, options)
  Veye.logger.info "Fetching a list of project for #{org_name}, team:#{team_name}"
  results = Veye::API::Project.get_list(api_key, org_name, team_name)
  valid_response?(results, 'Can not read list of projects.')
  show_results(@output_formats, results.data, options)
end

.get_project(api_key, project_key, options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/veye/project/check.rb', line 33

def self.get_project(api_key, project_key, options)
  results = Veye::API::Project.get_project(api_key, project_key)
  err_msg = "No data for the project: `#{project_key}`"
  valid_response?(results, err_msg)

  proj_dt = results.data
  show_results(@output_formats, proj_dt, options)
  if options[:format] != 'json'
    show_dependencies(@dependency_output_formats, proj_dt['dependencies'], options)
  end
end

.update(api_key, project_key, filename, options) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/veye/project/check.rb', line 58

def self.update(api_key, project_key, filename, options)
  results = Veye::API::Project.update(api_key, project_key, filename)
  valid_response?(results, 'Re-upload failed.')
  show_results(@output_formats, results.data, options)
  if options[:format] != 'json'
    show_dependencies(@dependency_output_formats, results.data['dependencies'], options)
  end
end

.upload(api_key, filename, org_name = 'private', team_name = nil, options) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/veye/project/check.rb', line 45

def self.upload(api_key, filename, org_name = 'private', team_name = nil, options)

  results = Veye::API::Project.upload(
    api_key, filename, org_name, team_name, options[:temporary], options[:public], options[:name]
  )

  valid_response?(results, 'Upload failed.')
  show_results(@output_formats, results.data, options)
  if options[:format] != 'json'
    show_dependencies(@dependency_output_formats, results.data['dependencies'], options)
  end
end