github-api-client 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/api-browser.rb +3 -0
- data/db/migrate/003_create_repos.rb +4 -2
- data/features/step_definitions/fetching_steps.rb +1 -1
- data/lib/github-api-client/base.rb +2 -1
- data/lib/github-api-client/organization.rb +1 -1
- data/lib/github-api-client/repo.rb +22 -12
- data/lib/github-api-client/user.rb +1 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/bin/api-browser.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
4
|
+
|
3
5
|
require 'github-api-client'
|
4
6
|
|
5
7
|
puts GitHub::Config::Version
|
@@ -14,6 +16,7 @@ else # launches all-features code
|
|
14
16
|
# Performance tests
|
15
17
|
GitHub::Organization.get('rails').fetch(:repositories).repositories
|
16
18
|
GitHub::Repo.get('parndt/hub').parent.fetch(:self, :watchers).watchers
|
19
|
+
GitHub::Repo.get('rails/rails', :organization).fetch(:self)
|
17
20
|
GitHub::User.get('kneath').fetch(:followers, :followings)
|
18
21
|
GitHub::User.get('schacon').fetch(:organizations).organizations
|
19
22
|
GitHub::Organization.get('github').fetch(:members, :repositories).members
|
@@ -5,16 +5,18 @@ class CreateRepos < ActiveRecord::Migration
|
|
5
5
|
t.string attr
|
6
6
|
end
|
7
7
|
|
8
|
-
%w(
|
8
|
+
%w(parent).each do |attr|
|
9
9
|
t.references attr
|
10
10
|
end
|
11
11
|
|
12
|
+
t.references :owner, :polymorphic => true
|
13
|
+
|
12
14
|
# TODO: organization temporarily a string, only when there's no organization model
|
13
15
|
%w(size score).each do |attr|
|
14
16
|
t.integer attr
|
15
17
|
end
|
16
18
|
|
17
|
-
%w(has_downloads b_fork
|
19
|
+
%w(has_downloads b_fork deleted locked has_wiki private open_issues has_issues).each do |attr|
|
18
20
|
t.boolean attr
|
19
21
|
end
|
20
22
|
|
@@ -45,9 +45,10 @@ module GitHub
|
|
45
45
|
hash = case resource
|
46
46
|
when :user_get then {:public_repo_count => :nil, :public_gist_count => :nil, :created => :nil, :permission => :nil, :followers_count => :nil, :following_count => :nil}
|
47
47
|
when :user_search then {:name => :login, :username => :login, :fullname => :name, :followers => :nil, :repos => :nil, :created => :nil, :permission => :nil}
|
48
|
-
when :repo_get then {:fork => :b_fork, :watchers => nil, :owner => :owner_login, :
|
48
|
+
when :repo_get then {:fork => :b_fork, :watchers => nil, :owner => :owner_login, :forks => nil, :followers_count => nil, :forks_count => nil}
|
49
49
|
when :org_get then {:public_gist_count => nil, :public_repo_count => nil, :following_count => :nil, :followers_count => :nil}
|
50
50
|
when :org_repo_index then {:owner => nil, :open_issues => nil, :has_issues => nil, :watchers => nil, :forks => nil, :fork => :b_fork, :gravatar_id => nil, :organization => :organization_login}
|
51
|
+
when :org_repo_get then {:owner => nil, :open_issues => nil, :has_issues => nil, :watchers => nil, :forks => nil, :fork => :b_fork, :gravatar_id => nil, :organization => :organization_login}
|
51
52
|
end
|
52
53
|
# Provides abstraction layer between YAML :keys and 'keys' returned by Hub
|
53
54
|
symbolized_resources = [:repo_get, :org_repo_index, :org_repo_get]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GitHub
|
2
2
|
class Organization < ActiveRecord::Base
|
3
3
|
has_and_belongs_to_many :members, :class_name => 'GitHub::User', :join_table => 'organizations_members'
|
4
|
-
has_many :repositories, :class_name => 'GitHub::Repo'
|
4
|
+
has_many :repositories, :class_name => 'GitHub::Repo', :as => :owner
|
5
5
|
|
6
6
|
def get
|
7
7
|
self.update_attributes(
|
@@ -1,24 +1,36 @@
|
|
1
1
|
module GitHub
|
2
2
|
class Repo < ActiveRecord::Base
|
3
|
-
belongs_to :owner, :
|
4
|
-
belongs_to :organization, :class_name => 'GitHub::Organization'
|
3
|
+
belongs_to :owner, :polymorphic => true
|
5
4
|
belongs_to :parent, :class_name => 'GitHub::Repo'
|
6
5
|
has_and_belongs_to_many :watchers, :class_name => 'GitHub::User', :join_table => 'repo_watchings', :foreign_key => 'repo_id', :association_foreign_key => 'watcher_id'
|
7
6
|
|
8
7
|
def get
|
9
|
-
self.
|
8
|
+
parser = case self.owner_type
|
9
|
+
when 'GitHub::User'
|
10
|
+
:repo_get
|
11
|
+
when 'GitHub::Organization'
|
12
|
+
:org_repo_get
|
13
|
+
end
|
14
|
+
self.update_attributes GitHub::Base.parse_attributes(parser,
|
10
15
|
YAML::load(
|
11
16
|
GitHub::Browser.get("/repos/show/#{self.permalink}"))['repository'])
|
12
17
|
self
|
13
18
|
end
|
14
19
|
|
15
|
-
def self.get(information)
|
20
|
+
def self.get(information, o_type = :user)
|
16
21
|
#FIXME: permalink column must be present, comparing url's is surely not the most efficient way for the db
|
17
|
-
conditions = {:name => information.split('/').last
|
22
|
+
conditions = {:name => information.split('/').last}
|
23
|
+
if o_type == :user
|
24
|
+
conditions.merge! :owner_id => GitHub::User.find_or_create_by_login(information.split('/').first).id, :owner_type => 'GitHub::User'
|
25
|
+
else
|
26
|
+
conditions.merge! :owner_id => GitHub::Organization.find_or_create_by_login(information.split('/').first).id, :owner_type => 'GitHub::Organization'
|
27
|
+
end
|
18
28
|
if r = GitHub::Repo.where(conditions).first
|
19
29
|
r.get
|
20
30
|
else
|
21
31
|
r = GitHub::Repo.new(conditions).get
|
32
|
+
p r.parent
|
33
|
+
r
|
22
34
|
end
|
23
35
|
end
|
24
36
|
|
@@ -52,29 +64,27 @@ module GitHub
|
|
52
64
|
public
|
53
65
|
def owner_login=(user)
|
54
66
|
if user
|
55
|
-
self.b_org = false
|
56
67
|
self.owner = GitHub::User.find_or_create_by_login(user)
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
60
71
|
def organization_login=(organization)
|
61
72
|
if organization
|
62
|
-
self.
|
63
|
-
self.organization = Organization.find_or_create_by_login(organization)
|
73
|
+
self.owner = Organization.find_or_create_by_login(organization)
|
64
74
|
end
|
65
75
|
end
|
66
76
|
|
67
77
|
def parent=(permalink)
|
78
|
+
#FIXME: parent repo does not allow organization to be owner ATM
|
68
79
|
owner = GitHub::User.find_or_create_by_login permalink.split('/').first
|
69
80
|
name = permalink.split('/').last
|
70
|
-
repo = GitHub::Repo.where(:owner_id => owner.id, :name => name).first
|
71
|
-
repo ||= GitHub::Repo.create(:
|
81
|
+
repo = GitHub::Repo.where(:owner_id => owner.id, :owner_type => 'GitHub::Repo', :name => name).first
|
82
|
+
repo ||= GitHub::Repo.create(:owner => owner, :name => name)
|
72
83
|
self.parent_id = repo.id
|
73
84
|
end
|
74
85
|
|
75
86
|
def permalink
|
76
|
-
|
77
|
-
"#{o.login}/#{name}"
|
87
|
+
"#{owner.login}/#{name}"
|
78
88
|
end
|
79
89
|
|
80
90
|
# For future, when sql will be find_or_create_by_permalink
|
@@ -3,7 +3,7 @@ module GitHub
|
|
3
3
|
class User < ActiveRecord::Base
|
4
4
|
has_and_belongs_to_many :followers, :foreign_key => 'follower_id', :association_foreign_key => 'following_id', :join_table => 'user_followings', :class_name => 'User'
|
5
5
|
has_and_belongs_to_many :followings, :foreign_key => 'following_id', :association_foreign_key => 'follower_id', :join_table => 'user_followings', :class_name => 'User'
|
6
|
-
has_many :repos, :class_name => 'GitHub::Repo', :
|
6
|
+
has_many :repos, :class_name => 'GitHub::Repo', :as => :owner
|
7
7
|
|
8
8
|
# FIXME: Does GitHub allow a user to have multiple organizations?
|
9
9
|
has_and_belongs_to_many :organizations, :join_table => 'organizations_members'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 6
|
9
|
+
version: 0.2.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jakub Oko\xC5\x84ski"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-07 00:00:00 +01:00
|
18
18
|
default_executable: api-browser.rb
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -219,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
219
|
requirements:
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
hash:
|
222
|
+
hash: 4308347029260914289
|
223
223
|
segments:
|
224
224
|
- 0
|
225
225
|
version: "0"
|