veye 0.0.9 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +80 -29
  3. data/Makefile +6 -0
  4. data/README.md +12 -224
  5. data/bin/veye +13 -22
  6. data/changelogs.md +95 -0
  7. data/lib/veye/api/base_resource.rb +8 -9
  8. data/lib/veye/api/github.rb +77 -0
  9. data/lib/veye/api/json_response.rb +21 -25
  10. data/lib/veye/api/package.rb +98 -0
  11. data/lib/veye/api/project.rb +107 -0
  12. data/lib/veye/api/resource.rb +9 -8
  13. data/lib/veye/api/service.rb +15 -0
  14. data/lib/veye/api/user.rb +32 -0
  15. data/lib/veye/api.rb +22 -2
  16. data/lib/veye/base_executor.rb +13 -9
  17. data/lib/veye/github/delete.rb +10 -20
  18. data/lib/veye/github/import.rb +7 -14
  19. data/lib/veye/github/info.rb +6 -12
  20. data/lib/veye/github/list.rb +9 -19
  21. data/lib/veye/github/search.rb +9 -17
  22. data/lib/veye/github/sync.rb +9 -18
  23. data/lib/veye/github.rb +1 -1
  24. data/lib/veye/helpers/format_helpers.rb +15 -5
  25. data/lib/veye/package/follow.rb +24 -47
  26. data/lib/veye/package/info.rb +8 -25
  27. data/lib/veye/package/references.rb +9 -36
  28. data/lib/veye/package/search.rb +14 -24
  29. data/lib/veye/package.rb +14 -6
  30. data/lib/veye/pagination.rb +2 -0
  31. data/lib/veye/project/check.rb +39 -117
  32. data/lib/veye/project/license.rb +23 -0
  33. data/lib/veye/project.rb +4 -3
  34. data/lib/veye/service.rb +13 -17
  35. data/lib/veye/user/me.rb +11 -30
  36. data/lib/veye/user.rb +2 -1
  37. data/lib/veye/version.rb +1 -1
  38. data/lib/veye/views/github/info_csv.rb +3 -3
  39. data/lib/veye/views/github/info_json.rb +4 -0
  40. data/lib/veye/views/github/list_csv.rb +5 -3
  41. data/lib/veye/views/github/list_pretty.rb +2 -2
  42. data/lib/veye/views/github/list_table.rb +3 -2
  43. data/lib/veye/views/package/info_pretty.rb +1 -1
  44. data/lib/veye/views/package/search_csv.rb +2 -3
  45. data/lib/veye/views/package/search_table.rb +1 -3
  46. data/lib/veye/views/package.rb +1 -1
  47. data/lib/veye/views/project/licence_csv.rb +3 -3
  48. data/lib/veye/views/project/licence_json.rb +1 -1
  49. data/lib/veye/views/project/licence_pretty.rb +1 -1
  50. data/lib/veye/views/project/licence_table.rb +3 -3
  51. data/lib/veye/views/user/profile_table.rb +4 -1
  52. data/lib/veye/views/user.rb +3 -1
  53. data/lib/veye.rb +29 -61
  54. data/test/api/github_test.rb +84 -0
  55. data/test/api/package_test.rb +80 -0
  56. data/test/api/project_test.rb +118 -0
  57. data/test/api/service_test.rb +15 -0
  58. data/test/api/user_test.rb +30 -0
  59. data/test/fixtures/vcr_cassettes/github_delete.yml +48 -0
  60. data/test/fixtures/vcr_cassettes/github_import.yml +53 -0
  61. data/test/fixtures/vcr_cassettes/github_info.yml +49 -0
  62. data/test/fixtures/vcr_cassettes/github_list.yml +80 -0
  63. data/test/fixtures/vcr_cassettes/github_sync.yml +48 -0
  64. data/test/fixtures/vcr_cassettes/package_follow.yml +52 -0
  65. data/test/fixtures/vcr_cassettes/package_follow_status.yml +48 -0
  66. data/test/fixtures/vcr_cassettes/package_info.yml +56 -0
  67. data/test/fixtures/vcr_cassettes/package_reference.yml +46 -0
  68. data/test/fixtures/vcr_cassettes/package_search.yml +46 -0
  69. data/test/fixtures/vcr_cassettes/package_unfollow.yml +48 -0
  70. data/test/fixtures/vcr_cassettes/project_delete.yml +48 -0
  71. data/test/fixtures/vcr_cassettes/project_get.yml +49 -0
  72. data/test/fixtures/vcr_cassettes/project_license.yml +49 -0
  73. data/test/fixtures/vcr_cassettes/project_list.yml +48 -0
  74. data/test/fixtures/vcr_cassettes/project_update.yml +105 -0
  75. data/test/fixtures/vcr_cassettes/project_upload.yml +104 -0
  76. data/test/fixtures/vcr_cassettes/services_ping.yml +46 -0
  77. data/test/fixtures/vcr_cassettes/user_get_favorites.yml +48 -0
  78. data/test/fixtures/vcr_cassettes/user_get_profile.yml +48 -0
  79. data/test/github_delete_test.rb +31 -0
  80. data/test/github_import_test.rb +94 -0
  81. data/test/github_info_test.rb +73 -0
  82. data/test/github_list_test.rb +84 -0
  83. data/test/github_sync_test.rb +20 -0
  84. data/test/package_follow_test.rb +38 -0
  85. data/test/package_info_test.rb +73 -0
  86. data/test/package_reference_test.rb +67 -0
  87. data/test/package_search_test.rb +66 -0
  88. data/test/project_check_test.rb +326 -0
  89. data/test/project_license_test.rb +72 -0
  90. data/test/service_test.rb +29 -0
  91. data/test/test_helper.rb +29 -4
  92. data/test/user_me_test.rb +126 -0
  93. data/veye.gemspec +45 -0
  94. metadata +163 -37
  95. data/DEPENDENCIES.md +0 -25
  96. data/lib/veye/helpers/repo_helpers.rb +0 -5
  97. data/lib/veye/project/licence.rb +0 -38
  98. data/test/default_test.rb +0 -14
data/lib/veye/service.rb CHANGED
@@ -1,26 +1,22 @@
1
1
  module Veye
2
+ # CLI wrappers for API
2
3
  class Service
3
- RESOURCE_PATH = "/services"
4
- def self.ping(n = 1)
5
- public_api = API::Resource.new RESOURCE_PATH
6
- api_response = "no idea"
7
- public_api.resource['/ping'].get do |response, request, result, &block|
8
- api_response = API::JSONResponse.new(request, result, response)
9
- end
10
- show_result(api_response)
11
- return api_response
4
+ def self.ping
5
+ show_result(Veye::API::Service.ping)
12
6
  end
13
7
 
14
8
  def self.show_result(result)
15
- if result.success
9
+ if result.nil?
10
+ puts 'Request failure'.color(:red)
11
+ elsif result.success
16
12
  puts "#{result.data['message']}".color(:green)
17
- else
18
- printf(
19
- "VersionEye didnt recognized secret word.Answered %s, %s\n",
20
- result.code.to_s.color(:red),
21
- "#{result.message}".color(:yellow)
22
- )
23
- end
13
+ else
14
+ printf(
15
+ "VersionEye didnt recognized secret word.Answered %s, %s\n",
16
+ result.code.to_s.color(:red),
17
+ result.message.to_s.color(:yellow)
18
+ )
19
+ end
24
20
  end
25
21
  end
26
22
  end
data/lib/veye/user/me.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  require_relative '../views/user.rb'
2
2
  require_relative '../base_executor.rb'
3
3
 
4
-
5
4
  module Veye
6
5
  module User
6
+ # Me class includes commands to manage and view authorized user profile
7
+ # and favorites.
7
8
  class Me < BaseExecutor
8
-
9
- @@profile_formats = {
9
+ @profile_formats = {
10
10
  'csv' => User::ProfileCSV.new,
11
11
  'json' => User::ProfileJSON.new,
12
12
  'pretty' => User::ProfilePretty.new,
13
13
  'table' => User::ProfileTable.new
14
14
  }
15
15
 
16
- @@favorite_formats = {
16
+ @favorite_formats = {
17
17
  'csv' => User::FavoriteCSV.new,
18
18
  'json' => User::FavoriteJSON.new,
19
19
  'pretty' => User::FavoritePretty.new,
@@ -21,39 +21,20 @@ module Veye
21
21
  }
22
22
 
23
23
  def self.get_profile(api_key, options)
24
- user_api = API::Resource.new(RESOURCE_PATH)
25
- results = nil
26
- qparams = {:params => {:api_key => api_key}}
27
-
28
- user_api.resource.get(qparams) do |response, request, result|
29
- results = API::JSONResponse.new(request, result, response)
24
+ results = Veye::API::User.get_profile(api_key)
25
+ if valid_response?(results, 'Failed to read profile.')
26
+ show_results(@profile_formats, results.data, options)
30
27
  end
31
-
32
- catch_request_error(results, "Failed to read profile.")
33
- show_results(@@profile_formats, results.data, options)
34
- results
35
28
  end
36
29
 
37
30
  def self.get_favorites(api_key, options)
38
- user_api = API::Resource.new(RESOURCE_PATH)
39
- results = nil
40
- page = options[:page] || 1
41
- qparams = {
42
- :params => {
43
- :api_key => api_key,
44
- :page => page
45
- }
46
- }
31
+ results = Veye::API::User.get_favorites(api_key, options[:page])
47
32
 
48
- user_api.resource['/favorites'].get(qparams) do |response, request, result|
49
- results = API::JSONResponse.new(request, result, response)
33
+ if valid_response?(results, 'Failed to read favorites.')
34
+ paging = results.data['paging']
35
+ show_results(@favorite_formats, results.data, options, paging)
50
36
  end
51
-
52
- catch_request_error(results, "Failed to read favorites.")
53
- show_results(@@favorite_formats, results.data, options, results.data['paging'])
54
- results
55
37
  end
56
38
  end
57
39
  end
58
40
  end
59
-
data/lib/veye/user.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require_relative 'user/me.rb'
2
2
 
3
3
  module Veye
4
+ # User namespace includes user related commands
5
+ # and classes required to render results on commandline.
4
6
  module User
5
- RESOURCE_PATH = "/me"
6
7
  end
7
8
  end
data/lib/veye/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Veye
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1'
3
3
  BIGEYE = %q{
4
4
 
5
5
  _ __ _ ______
@@ -4,7 +4,7 @@ module Veye
4
4
  module Github
5
5
  class InfoCSV < BaseCSV
6
6
  def initialize
7
- headers = "name,language,owner_login,owner_type,private,fork,branches,imported_projects, description"
7
+ headers = "name,language,owner_login,owner_type,private,fork,branches,imported_projects,description"
8
8
  super(headers)
9
9
  end
10
10
  def format(results)
@@ -20,8 +20,8 @@ module Veye
20
20
  repo['owner_type'],
21
21
  repo['private'],
22
22
  repo['fork'],
23
- repo['branches'].join('|'),
24
- imported_project_names.join('|'),
23
+ repo['branches'].to_a.join('|'),
24
+ imported_project_names.to_a.join('|'),
25
25
  repo['description']
26
26
  )
27
27
  end
@@ -5,6 +5,10 @@ module Veye
5
5
  class InfoJSON < BaseJSON
6
6
  def format(results)
7
7
  @results[:repo] = results['repo']
8
+
9
+ if results.has_key?('imported_projects')
10
+ @results[:projects] = results['imported_projects']
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -4,13 +4,14 @@ module Veye
4
4
  module Github
5
5
  class ListCSV < BaseCSV
6
6
  def initialize
7
- headers = "nr,fullname,language,owner_login,owner_type,private,fork,branches,description"
7
+ headers = "nr,fullname,language,owner_login,owner_type,private,fork,\
8
+ branches,imported,description"
8
9
  super(headers)
9
10
  end
10
11
 
11
12
  def format(results)
12
13
  results['repos'].each_with_index do |result, index|
13
- printf("%d,%s,%s,%s,%s,%s,%s,%s,%s\n",
14
+ printf("%d,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
14
15
  index + 1,
15
16
  result['fullname'],
16
17
  result['language'],
@@ -18,7 +19,8 @@ module Veye
18
19
  result['owner_type'],
19
20
  result['private'],
20
21
  result['fork'],
21
- result['branches'].join('|'),
22
+ result['branches'].to_a.join('|'),
23
+ result['imported'].to_a.join('|'),
22
24
  result['description']
23
25
  )
24
26
  end
@@ -18,9 +18,9 @@ module Veye
18
18
  printf("\t%-15s: %s\n", "Owner type", result['owner_type'])
19
19
  printf("\t%-15s: %s\n", "Private", result['private'])
20
20
  printf("\t%-15s: %s\n", "Fork", result['fork'])
21
- printf("\t%-15s: %s\n", "Branches", result['branches'].join(','))
21
+ printf("\t%-15s: %s\n", "Branches", result['branches'].to_a.join(','))
22
22
  printf("\t%-15s: %s\n", "Description", result['description'])
23
- printf("\t%-15s: %s\n", "Imported", result['imported_projects'].join(','))
23
+ printf("\t%-15s: %s\n", "Imported", result['imported_projects'].to_a.join(','))
24
24
  end
25
25
  end
26
26
  end
@@ -4,7 +4,8 @@ module Veye
4
4
  module Github
5
5
  class ListTable < BaseTable
6
6
  def initialize
7
- headings = %w(index fullname language owner_login owner_type private fork branches imported)
7
+ headings = %w(index fullname language owner_login owner_type private
8
+ fork branches imported)
8
9
  super("Github repositories", headings)
9
10
  end
10
11
 
@@ -17,7 +18,7 @@ module Veye
17
18
  row << result['owner_type']
18
19
  row << result['private']
19
20
  row << result['fork']
20
- row << result['branches'].join("\n")
21
+ row << result['branches'].to_a.join("\n")
21
22
  row << result['imported_projects'].to_a.join("\n")
22
23
  #row << result['description']
23
24
  @table << row
@@ -16,7 +16,7 @@ module Veye
16
16
  "#{result["prod_key"]}".bright)
17
17
  printf("\t%-15s:\n\t %s\n", "Description", result["description"])
18
18
  printf("\t%-15s: %s\n", "Group id", result["group_id"])
19
- printf("\t%-15s: %s\n", "Link", result["link"])
19
+ printf("\t%-15s: %s\n", "Link", result["links"].first.fetch('link'))
20
20
 
21
21
  end
22
22
  end
@@ -4,7 +4,7 @@ module Veye
4
4
  module Package
5
5
  class SearchCSV < BaseCSV
6
6
  def initialize
7
- headers = "nr,name,version,prod_key,version,language,group_id"
7
+ headers = "nr,name,version,prod_key,language,group_id"
8
8
  super(headers)
9
9
  end
10
10
 
@@ -13,12 +13,11 @@ module Veye
13
13
  return if items.nil?
14
14
 
15
15
  items.each_with_index do |result, index|
16
- printf("%d,%s,%s,%s,%s,%s,%s\n",
16
+ printf("%d,%s,%s,%s,%s,%s\n",
17
17
  index + 1,
18
18
  result["name"],
19
19
  result["version"],
20
20
  result["prod_key"],
21
- result["version"],
22
21
  result["language"],
23
22
  result["group_id"])
24
23
  end
@@ -4,7 +4,7 @@ module Veye
4
4
  module Package
5
5
  class SearchTable < BaseTable
6
6
  def initialize
7
- headings = %w(index name version product_key language group_id)
7
+ headings = %w(index name version product_key language)
8
8
  super("Package search", headings)
9
9
  end
10
10
 
@@ -14,8 +14,6 @@ module Veye
14
14
  items.each_with_index do |result, index|
15
15
  row = [index+1, result["name"], result["version"], result["prod_key"]]
16
16
  row << result["language"]
17
- row << result["group_id"]
18
-
19
17
  @table << row
20
18
  end
21
19
  end
@@ -15,6 +15,6 @@ require_relative 'package/references_table.rb'
15
15
 
16
16
 
17
17
  module Veye
18
- module Github
18
+ module Package
19
19
  end
20
20
  end
@@ -4,15 +4,15 @@ module Veye
4
4
  module Project
5
5
  class LicenceCSV < BaseCSV
6
6
  def initialize
7
- headers = "nr,licence,product_keys"
7
+ headers = "nr,license,product_keys"
8
8
  super(headers)
9
9
  end
10
10
  def format(results)
11
11
  return nil if results.nil?
12
12
  n = 1
13
- results["licenses"].each_pair do |licence, prods|
13
+ results["licenses"].each_pair do |license, prods|
14
14
  prod_keys = prods.map {|p| p["prod_key"]}
15
- printf("%d,%s,%s\n", n, licence, prod_keys.join(','))
15
+ printf("%d,%s,%s\n", n, license, prod_keys.join(','))
16
16
  n += 1
17
17
  end
18
18
  end
@@ -4,7 +4,7 @@ module Veye
4
4
  module Project
5
5
  class LicenceJSON < BaseJSON
6
6
  def format(results)
7
- @results[:licences] = results["licenses"]
7
+ @results[:licenses] = results["licenses"]
8
8
  end
9
9
  end
10
10
  end
@@ -5,7 +5,7 @@ module Veye
5
5
  module Project
6
6
  class LicencePretty < BasePretty
7
7
  def format(results)
8
- return if result.nil?
8
+ return if results.nil?
9
9
  n = 1
10
10
  results["licenses"].each_pair do |licence, products|
11
11
  product_keys = products.map {|prod| prod["prod_key"]}
@@ -4,16 +4,16 @@ module Veye
4
4
  module Project
5
5
  class LicenceTable < BaseTable
6
6
  def initialize
7
- headings = %w(index licence product_keys)
7
+ headings = %w(index license product_keys)
8
8
  super("Licences", headings)
9
9
  end
10
10
  def format(results)
11
11
  items = results['licenses']
12
12
  return if items.nil?
13
13
  n = 1
14
- items.each_pair do |licence, products|
14
+ items.each_pair do |license, products|
15
15
  products.each do |prod|
16
- row = [n, licence, prod["prod_key"]]
16
+ row = [n, license, prod["prod_key"]]
17
17
  @table << row
18
18
  end
19
19
  n += 1
@@ -4,7 +4,10 @@ module Veye
4
4
  module User
5
5
  class ProfileTable < BaseTable
6
6
  def initialize
7
- headings = %w(username fullname email plan_name, admin, deleted, new_notifications, total_notifications)
7
+ headings = %w(
8
+ username fullname email plan_name admin deleted
9
+ new_notifications total_notifications
10
+ )
8
11
  super("User's profile", headings)
9
12
  end
10
13
 
@@ -9,6 +9,8 @@ require_relative 'user/favorite_pretty.rb'
9
9
  require_relative 'user/favorite_table.rb'
10
10
 
11
11
  module Veye
12
+ # User namespace includes user related commands
13
+ # and classes required to render results on commandline.
12
14
  module User
13
15
  end
14
- end
16
+ end
data/lib/veye.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # Add requires for other files you add to your project here, so
2
2
  # you just need to require this one file in your bin file
3
- require 'openssl'
3
+ require 'rest-client'
4
+ require 'yaml'
4
5
 
5
6
  require 'veye/helpers/format_helpers.rb'
6
- require 'veye/helpers/repo_helpers.rb'
7
7
 
8
8
  require 'veye/version.rb'
9
9
  require 'veye/service.rb'
@@ -14,9 +14,9 @@ require 'veye/user.rb'
14
14
  require 'veye/github.rb'
15
15
  require 'veye/pagination.rb'
16
16
 
17
- $global_options ||= nil
18
- DEFAULT_CONFIG_FILE = ".veye.rc"
19
- DEFAULT_CONFIG_PATH = "~"
17
+ $global_options ||= {}
18
+ DEFAULT_CONFIG_FILE = '.veye.rc'
19
+ DEFAULT_CONFIG_PATH = '~'
20
20
 
21
21
  def get_config_fullpath
22
22
  File.expand_path("#{DEFAULT_CONFIG_PATH}/#{DEFAULT_CONFIG_FILE}")
@@ -24,44 +24,43 @@ end
24
24
 
25
25
  def config_exists?
26
26
  filepath = get_config_fullpath
27
- File.exists?(filepath)
27
+ File.exist?(filepath)
28
28
  end
29
29
 
30
30
  def check_config_file
31
31
  unless config_exists?
32
- msg = sprintf("%s: %s\n",
33
- "config file doesnt exist. ".color(:red),
34
- "Use `veye initconfig` to initialize settings file.")
35
- exit_now!(msg)
32
+ p format(
33
+ "%s: %s\n",
34
+ 'config file doesnt exist.'.color(:red),
35
+ 'Use `veye initconfig` to initialize settings file.'
36
+ )
37
+ exit
36
38
  end
37
39
  end
38
40
 
39
41
  def self.check_configs(global_opts, needs_api_key)
40
42
  check_config_file
41
43
  check_api_key(global_opts) if needs_api_key
42
-
43
- unless ssl_key_exists?(global_opts)
44
- generate_ssl_keys(global_opts)
45
- end
46
44
  true
47
45
  end
48
46
 
49
47
  def init_environment
50
- #sets up required variables and modules to work on IRB or unittest
51
- config_file = get_config_fullpath
52
- $global_options = YAML.load_file(config_file)
53
- $global_options[:config_file] = config_file
54
- $global_options[:url] = Veye::API::Resource.build_url($global_options)
55
- $global_options
48
+ # sets up required variables and modules to work on IRB or unittest
49
+ config_file = get_config_fullpath
50
+ $global_options = YAML.load_file(config_file)
51
+ $global_options[:config_file] = config_file
52
+ $global_options[:url] = Veye::API::Resource.build_url($global_options)
53
+ $global_options
56
54
  end
57
55
 
58
56
  def check_api_key(global_opts)
59
57
  result = false
60
- if global_opts[:api_key].nil? or global_opts[:api_key].match("add your api key")
61
- msg = sprintf("%s: %s\n",
62
- "Warning: API key is missing.".color(:yellow),
63
- "You cant access private data.")
64
- print msg
58
+ if global_opts[:api_key].nil? || global_opts[:api_key].match("add your api key")
59
+ print format(
60
+ "%s: %s\n",
61
+ 'Warning: API key is missing.'.color(:yellow),
62
+ 'You cant access private data.'
63
+ )
65
64
  else
66
65
  result = true
67
66
  end
@@ -69,45 +68,14 @@ def check_api_key(global_opts)
69
68
  result
70
69
  end
71
70
 
72
- def ssl_key_exists?(global_opts)
73
- fullpath = File.expand_path(global_opts[:ssl_path])
74
- return File.exists?("#{fullpath}/veye_cert.pem")
75
- end
76
-
77
- def generate_ssl_keys(global_opts)
78
- result = false
79
-
80
- Dir.chdir(Dir.home)
81
- ssl_path = File.expand_path(global_opts[:ssl_path])
82
- unless Dir.exists?(ssl_path)
83
- print "Info: Creating folder for ssl keys: `#{ssl_path}`\n"
84
- Dir.mkdir(ssl_path)
85
- end
86
-
87
- Dir.chdir(ssl_path)
88
-
89
- key = OpenSSL::PKey::RSA.new 2048
90
- open 'veye_key.pem', 'w' do |io| io.write(key.to_pem) end
91
- open 'veye_cert.pem', 'w' do |io| io.write(key.public_key.to_pem) end
92
-
93
- if ssl_key_exists?(global_opts)
94
- print "Success: SSL keys are generated.\n"
95
- result = true
96
- else
97
- print "Error: Cant generate SSL keys. Do you have openssl installed?\n"
98
- end
99
-
100
- Dir.chdir(Dir.home)
101
- result
102
- end
103
-
104
71
  def save_configs
105
72
  filepath = get_config_fullpath
106
73
  File.open(filepath, 'w') do |f|
107
74
  f.puts $global_options.to_yaml
108
75
  end
109
- msg = sprintf("%s: %s",
110
- "Success".color(:green),
111
- "new settings are saved into file: `#{filepath}`\n")
112
- print msg
76
+ print format(
77
+ "%s: %s",
78
+ 'Success'.color(:green),
79
+ "new settings are saved into file: `#{filepath}`"
80
+ )
113
81
  end
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+
3
+ class GithubTest < Minitest::Test
4
+ def setup
5
+ init_environment
6
+ @api_key = 'ba7d93beb5de7820764e'
7
+ @repo_name = 'versioneye/veye'
8
+ @branch = "master"
9
+ @file = "Gemfile.lock"
10
+ end
11
+
12
+ def test_list_api
13
+ VCR.use_cassette('github_list') do
14
+ res = Veye::API::Github.get_list(@api_key)
15
+ refute_nil res
16
+ assert_equal 200, res.code
17
+ repo = res.data["repos"][0]
18
+ assert_equal "versioneye_update", repo["name"]
19
+ assert_equal "shell", repo["language"]
20
+ assert_equal "versioneye", repo["owner_login"]
21
+ assert_equal "organization", repo["owner_type"]
22
+ assert_equal false, repo["private"]
23
+ end
24
+ end
25
+
26
+ def test_sync_api
27
+ VCR.use_cassette('github_sync') do
28
+ resp = Veye::API::Github.import_all(@api_key)
29
+ refute_nil resp
30
+ assert_equal 200, resp.code
31
+ assert_equal( {"status"=>"running"}, resp.data )
32
+ end
33
+ end
34
+
35
+ def test_info_api
36
+ VCR.use_cassette('github_info') do
37
+ res = Veye::API::Github.get_repo(@api_key, @repo_name)
38
+ refute_nil res
39
+ assert_equal 200, res.code
40
+ repo = res.data["repo"]
41
+ assert_equal "versioneye/veye", repo["fullname"]
42
+ assert_equal "ruby", repo["language"]
43
+ assert_equal "versioneye", repo["owner_login"]
44
+ assert_equal false, repo["private"]
45
+ assert_equal false, repo["fork"]
46
+ assert_equal [], res.data["imported_projects"]
47
+ end
48
+ end
49
+
50
+ def test_import_api
51
+ VCR.use_cassette('github_import') do
52
+ res = Veye::API::Github.import_repo(@api_key, @repo_name, @branch, @file)
53
+ refute_nil res
54
+ assert_equal 201, res.code
55
+ repo = res.data["repo"]
56
+
57
+ assert_equal "veye", repo["name"]
58
+ assert_equal "versioneye/veye", repo["fullname"]
59
+ assert_equal "ruby", repo["language"]
60
+ assert_equal "versioneye", repo["owner_login"]
61
+ assert_equal "organization", repo["owner_type"]
62
+ assert_equal false, repo["private"]
63
+ assert_equal false, repo["fork"]
64
+
65
+ project = res.data["imported_projects"].first
66
+ refute_nil project, "imported_projects fields is missing"
67
+ assert_equal "rubygem_versioneye_veye_1", project["project_key"]
68
+ assert_equal "versioneye/veye", project["name"]
69
+ assert_equal "RubyGem", project["project_type"]
70
+ assert_equal true, project["public"]
71
+ assert_equal "github", project["source"]
72
+ end
73
+ end
74
+
75
+ def test_delete_api
76
+ VCR.use_cassette('github_delete') do
77
+ res = Veye::API::Github.delete_repo(@api_key, @repo_name, @branch)
78
+
79
+ refute_nil res, "No API response"
80
+ assert_equal 200, res.code
81
+ assert_equal true, res.data["success"]
82
+ end
83
+ end
84
+ end