Class: Veye::Project::Check
- Inherits:
-
BaseExecutor
- Object
- BaseExecutor
- Veye::Project::Check
- 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
-
.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.
- .delete_project(api_key, project_key) ⇒ Object
- .get_list(api_key, org_name = 'private', team_name = nil, options) ⇒ Object
- .get_project(api_key, project_key, options) ⇒ Object
- .update(api_key, project_key, filename, options) ⇒ Object
- .upload(api_key, filename, org_name = 'private', team_name = nil, options) ⇒ Object
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, ) 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, [:org], [:team], [:temporary], [:public], [: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) ) [:all] = true #hack show_bulk_dependencies(@dependency_output_formats, deps, ) 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) (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, ) 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, ) 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, ) 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, ) if [:format] != 'json' show_dependencies(@dependency_output_formats, proj_dt['dependencies'], ) 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, ) results = Veye::API::Project.update(api_key, project_key, filename) valid_response?(results, 'Re-upload failed.') show_results(@output_formats, results.data, ) if [:format] != 'json' show_dependencies(@dependency_output_formats, results.data['dependencies'], ) 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, ) results = Veye::API::Project.upload( api_key, filename, org_name, team_name, [:temporary], [:public], [:name] ) valid_response?(results, 'Upload failed.') show_results(@output_formats, results.data, ) if [:format] != 'json' show_dependencies(@dependency_output_formats, results.data['dependencies'], ) end end |