github-api-client 0.1.2.2 → 0.1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/db/migrate/003_create_repos.rb +1 -1
- data/lib/github_api.rb +8 -33
- data/lib/github_api/base.rb +12 -4
- data/lib/github_api/config.rb +34 -0
- data/lib/github_api/repo.rb +7 -1
- metadata +3 -2
@@ -14,7 +14,7 @@ class CreateRepos < ActiveRecord::Migration
|
|
14
14
|
t.integer attr
|
15
15
|
end
|
16
16
|
|
17
|
-
%w(has_downloads
|
17
|
+
%w(has_downloads b_fork deleted locked has_wiki private open_issues has_issues).each do |attr|
|
18
18
|
t.boolean attr
|
19
19
|
end
|
20
20
|
|
data/lib/github_api.rb
CHANGED
@@ -9,23 +9,8 @@ require 'yaml'
|
|
9
9
|
require 'singleton'
|
10
10
|
require 'active_record'
|
11
11
|
require 'core_ext/habtm'
|
12
|
-
|
13
|
-
|
14
|
-
module GitHub
|
15
|
-
# Keeps all the configuration stuff
|
16
|
-
module Config
|
17
|
-
# Constant with defined all the paths used in the application
|
18
|
-
Path = {:dir => ENV['HOME'] + "/.github", :dbfile => ENV['HOME'] + "/.github/github.db", :migrations => Gem.loaded_specs['github-api-client'].full_gem_path + "/db/migrate", :secrets => ENV['HOME'] + "/.github" + "/secrets.yml"}
|
19
|
-
|
20
|
-
# Sets up the database and migrates it
|
21
|
-
# @return [nil]
|
22
|
-
def self.setup
|
23
|
-
Dir.mkdir GitHub::Config::Path[:dir] rescue nil
|
24
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => GitHub::Config::Path[:dbfile]
|
25
|
-
ActiveRecord::Migrator.migrate(GitHub::Config::Path[:migrations], nil)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
12
|
+
require 'rainbow'
|
13
|
+
require 'github_api/config'
|
29
14
|
|
30
15
|
GitHub::Config.setup
|
31
16
|
|
@@ -33,22 +18,12 @@ require 'github_api/base'
|
|
33
18
|
require 'github_api/user'
|
34
19
|
require 'github_api/repo'
|
35
20
|
require 'github_api/browser'
|
36
|
-
|
21
|
+
|
22
|
+
unless $user = GitHub::User.where(GitHub::Config::Secrets).first
|
23
|
+
$user = GitHub::User.create(GitHub::Config::Secrets)
|
24
|
+
end if GitHub::Config::Secrets
|
37
25
|
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
$user = GitHub::User.create(YAML::load_file(GitHub::Config::Path[:secrets])['user'])
|
42
|
-
end
|
43
|
-
|
44
|
-
rescue Errno::ENOENT
|
45
|
-
puts "Could not load config/secrets.yml, have you defined it?"
|
46
|
-
puts "Putting example secrets file in your #{GitHub::Config::Path[:secrets]}"
|
47
|
-
File.open(GitHub::Config::Path[:secrets], 'w') do |f|
|
48
|
-
f.write <<-config
|
49
|
-
user:
|
50
|
-
login: login
|
51
|
-
token: private_token
|
52
|
-
config
|
53
|
-
end
|
27
|
+
# General placeholder for all of the GitHub API sweets
|
28
|
+
module GitHub
|
54
29
|
end
|
data/lib/github_api/base.rb
CHANGED
@@ -37,15 +37,23 @@ module GitHub
|
|
37
37
|
# @return [Hash] parsed attributes, fully compatibile with local db
|
38
38
|
def self.parse_attributes(resource, attributes)
|
39
39
|
hash = case resource
|
40
|
-
|
40
|
+
when :user_get then {:public_repo_count => :nil, :public_gist_count => :nil, :created => :nil, :permission => :nil, :followers_count => :nil, :following_count => :nil}
|
41
41
|
when :user_search then {:name => :login, :username => :login, :fullname => :name, :followers => :nil, :repos => :public_repo_count, :created => :nil, :permission => :nil}
|
42
|
-
|
42
|
+
when :repo_get then {:fork => :b_fork}
|
43
43
|
end
|
44
44
|
hash.each do |k, v|
|
45
45
|
unless v == :nil
|
46
|
-
|
46
|
+
if [:repo_get].include? resource
|
47
|
+
attributes[v.to_s] = attributes[k.to_sym]
|
48
|
+
else
|
49
|
+
attributes[v.to_s] = attributes[k.to_s]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if [:repo_get].include? resource
|
53
|
+
attributes.delete k.to_sym
|
54
|
+
else
|
55
|
+
attributes.delete k.to_s
|
47
56
|
end
|
48
|
-
attributes.delete k.to_s
|
49
57
|
end
|
50
58
|
attributes
|
51
59
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module GitHub
|
2
|
+
# Keeps all the configuration stuff
|
3
|
+
module Config
|
4
|
+
# Constant with defined all the paths used in the application
|
5
|
+
Path = {:dir => ENV['HOME'] + "/.github", :dbfile => ENV['HOME'] + "/.github/github.db", :migrations => Gem.loaded_specs['github-api-client'].full_gem_path + "/db/migrate", :secrets => ENV['HOME'] + "/.github" + "/secrets.yml"}
|
6
|
+
|
7
|
+
# Secrets array, uses env vars if defined
|
8
|
+
Secrets = {"login" => ENV['GITHUB_USER'], "token" => ENV['GITHUB_TOKEN']} if ENV['GITHUB_USER'] && ENV['GITHUB_TOKEN']
|
9
|
+
begin
|
10
|
+
Secrets ||= YAML::load_file(GitHub::Config::Path[:secrets])['user']
|
11
|
+
rescue Errno::ENOENT
|
12
|
+
# Eye candy with rainbow
|
13
|
+
puts <<-report
|
14
|
+
You have two ways of defining your user to have authenticated access to your API:
|
15
|
+
#{"1.".color(:cyan)} Put a file in: #{GitHub::Config::Path[:secrets].color(:blue).bright}
|
16
|
+
Define in yaml:
|
17
|
+
#{"user".color(:yellow).bright}:
|
18
|
+
#{"login".color(:green).bright}: #{"your_login".color(:magenta)}
|
19
|
+
#{"token".color(:blue).bright}: #{"your_token".color(:magenta)}
|
20
|
+
#{"2.".color(:cyan)} Put #{"GITHUB_USER".color(:green).bright} and #{"GITHUB_TOKEN".color(:blue).bright} in your environment, so github-api-client can read it.
|
21
|
+
|
22
|
+
report
|
23
|
+
end
|
24
|
+
Secrets ||= nil
|
25
|
+
|
26
|
+
# Sets up the database and migrates it
|
27
|
+
# @return [nil]
|
28
|
+
def self.setup
|
29
|
+
Dir.mkdir GitHub::Config::Path[:dir] rescue nil
|
30
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => GitHub::Config::Path[:dbfile]
|
31
|
+
ActiveRecord::Migrator.migrate(GitHub::Config::Path[:migrations], nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/github_api/repo.rb
CHANGED
@@ -5,7 +5,9 @@ module GitHub
|
|
5
5
|
|
6
6
|
def self.get(information)
|
7
7
|
#FIXME: permalink column must be present, comparing url's is surely not the most efficient way for the db
|
8
|
-
GitHub::Repo.find_or_create_by_url(
|
8
|
+
GitHub::Repo.find_or_create_by_url(
|
9
|
+
GitHub::Base.parse_attributes(:repo_get,
|
10
|
+
YAML::load(GitHub::Browser.get("/repos/show/#{information}"))['repository']))
|
9
11
|
end
|
10
12
|
|
11
13
|
|
@@ -27,5 +29,9 @@ module GitHub
|
|
27
29
|
def permalink
|
28
30
|
"#{owner.login}/#{name}"
|
29
31
|
end
|
32
|
+
|
33
|
+
define_method(:fork?) do
|
34
|
+
b_fork
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.1.2.
|
9
|
+
- 4
|
10
|
+
version: 0.1.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Jakub Oko\xC5\x84ski"
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/github_api/base.rb
|
76
76
|
- lib/github_api/repo.rb
|
77
77
|
- lib/github_api/browser.rb
|
78
|
+
- lib/github_api/config.rb
|
78
79
|
- lib/github_api/user.rb
|
79
80
|
- db/migrate/003_create_repos.rb
|
80
81
|
- db/migrate/002_create_followings.rb
|