ghtorrent 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +16 -0
- data/Gemfile.lock +12 -27
- data/README.md +20 -33
- data/Rakefile +1 -9
- data/bin/ght-log-analyzer +11 -6
- data/bin/ght-log-influx +190 -0
- data/bin/ght-queue-grep.rb +55 -0
- data/bin/ght-retrieve-users +6 -0
- data/bin/{ght-rm-dupl → ght-update-repo} +1 -1
- data/lib/ghtorrent.rb +4 -4
- data/lib/ghtorrent/adapters/base_adapter.rb +4 -11
- data/lib/ghtorrent/adapters/mongo_persister.rb +5 -9
- data/lib/ghtorrent/adapters/noop_persister.rb +0 -5
- data/lib/ghtorrent/api_client.rb +45 -119
- data/lib/ghtorrent/command.rb +25 -8
- data/lib/ghtorrent/commands/full_user_retriever.rb +50 -0
- data/lib/ghtorrent/commands/ght_data_retrieval.rb +12 -98
- data/lib/ghtorrent/commands/ght_get_more_commits.rb +13 -17
- data/lib/ghtorrent/commands/ght_load.rb +1 -2
- data/lib/ghtorrent/commands/ght_mirror_events.rb +8 -12
- data/lib/ghtorrent/commands/ght_retrieve_dependents.rb +0 -5
- data/lib/ghtorrent/commands/ght_retrieve_one.rb +1 -6
- data/lib/ghtorrent/commands/ght_retrieve_repo.rb +56 -26
- data/lib/ghtorrent/commands/ght_retrieve_repos.rb +5 -15
- data/lib/ghtorrent/commands/ght_retrieve_user.rb +13 -54
- data/lib/ghtorrent/commands/ght_retrieve_users.rb +49 -0
- data/lib/ghtorrent/commands/ght_update_repo.rb +126 -0
- data/lib/ghtorrent/event_processing.rb +140 -0
- data/lib/ghtorrent/ghtorrent.rb +330 -396
- data/lib/ghtorrent/logging.rb +65 -12
- data/lib/ghtorrent/migrations/014_add_deleted_to_projects.rb +1 -1
- data/lib/ghtorrent/migrations/019_add_fake_to_users.rb +1 -1
- data/lib/ghtorrent/migrations/020_add_deleted_to_users.rb +19 -0
- data/lib/ghtorrent/migrations/021_remove_ext_ref_id.rb +42 -0
- data/lib/ghtorrent/migrations/022_add_project_languages.rb +24 -0
- data/lib/ghtorrent/multiprocess_queue_client.rb +25 -5
- data/lib/ghtorrent/retriever.rb +100 -57
- data/lib/ghtorrent/settings.rb +14 -17
- data/lib/ghtorrent/{transacted_ghtorrent.rb → transacted_gh_torrent.rb} +28 -5
- data/lib/version.rb +1 -1
- metadata +14 -46
- data/bin/ght-process-event +0 -35
- data/lib/ghtorrent/cache.rb +0 -97
- data/lib/ghtorrent/commands/ght_rm_dupl.rb +0 -132
- data/lib/ghtorrent/gh_torrent_exception.rb +0 -6
- data/spec/api_client_spec.rb +0 -42
- data/spec/spec_helper.rb +0 -21
data/lib/ghtorrent/logging.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
|
+
require 'ghtorrent/settings'
|
4
|
+
|
3
5
|
module GHTorrent
|
4
6
|
module Logging
|
5
7
|
|
6
|
-
|
8
|
+
include GHTorrent::Settings
|
9
|
+
|
10
|
+
def error(msg)
|
11
|
+
log(:warn, msg)
|
12
|
+
end
|
7
13
|
|
8
14
|
def warn(msg)
|
9
15
|
log(:warn, msg)
|
@@ -17,30 +23,77 @@ module GHTorrent
|
|
17
23
|
log(:debug, msg)
|
18
24
|
end
|
19
25
|
|
26
|
+
# Default logger
|
27
|
+
def loggerr
|
28
|
+
@logger ||= proc do
|
29
|
+
@logger_uniq ||= config(:logging_uniq)
|
30
|
+
|
31
|
+
logger = if config(:logging_file).casecmp('stdout')
|
32
|
+
Logger.new(STDOUT)
|
33
|
+
elsif config(:logging_file).casecmp('stderr')
|
34
|
+
Logger.new(STDERR)
|
35
|
+
else
|
36
|
+
Logger.new(config(:logging_file))
|
37
|
+
end
|
38
|
+
|
39
|
+
logger.level =
|
40
|
+
case config(:logging_level).downcase
|
41
|
+
when 'debug' then
|
42
|
+
Logger::DEBUG
|
43
|
+
when 'info' then
|
44
|
+
Logger::INFO
|
45
|
+
when 'warn' then
|
46
|
+
Logger::WARN
|
47
|
+
when 'error' then
|
48
|
+
Logger::ERROR
|
49
|
+
else
|
50
|
+
Logger::INFO
|
51
|
+
end
|
52
|
+
|
53
|
+
logger.formatter = proc do |severity, time, progname, msg|
|
54
|
+
if progname.nil? or progname.empty?
|
55
|
+
progname = @logger_uniq
|
56
|
+
end
|
57
|
+
"#{severity}, #{time.iso8601}, #{progname} -- #{msg}\n"
|
58
|
+
end
|
59
|
+
logger
|
60
|
+
end.call
|
61
|
+
|
62
|
+
@logger
|
63
|
+
end
|
64
|
+
|
20
65
|
private
|
21
66
|
|
67
|
+
def retrieve_caller
|
68
|
+
@logprefixes ||= Hash.new
|
69
|
+
|
70
|
+
c = caller[2]
|
71
|
+
unless @logprefixes.key? c
|
72
|
+
file_path = c.split(/:/)[0]
|
73
|
+
@logprefixes[c] = File.basename(file_path) + ': '
|
74
|
+
end
|
75
|
+
|
76
|
+
@logprefixes[c]
|
77
|
+
|
78
|
+
end
|
79
|
+
|
22
80
|
# Log a message at the given level.
|
23
81
|
def log(level, msg)
|
24
82
|
|
25
83
|
case level
|
26
84
|
when :fatal then
|
27
|
-
|
85
|
+
loggerr.fatal (retrieve_caller + msg)
|
28
86
|
when :error then
|
29
|
-
|
87
|
+
loggerr.error (retrieve_caller + msg)
|
30
88
|
when :warn then
|
31
|
-
|
89
|
+
loggerr.warn (retrieve_caller + msg)
|
32
90
|
when :info then
|
33
|
-
|
91
|
+
loggerr.info (retrieve_caller + msg)
|
34
92
|
when :debug then
|
35
|
-
|
93
|
+
loggerr.debug (retrieve_caller + msg)
|
36
94
|
else
|
37
|
-
|
95
|
+
loggerr.debug (retrieve_caller + msg)
|
38
96
|
end
|
39
97
|
end
|
40
|
-
|
41
|
-
# Default logger
|
42
|
-
def logger
|
43
|
-
@logger ||= Logger.new(STDOUT)
|
44
|
-
end
|
45
98
|
end
|
46
99
|
end
|
@@ -10,7 +10,7 @@ Sequel.migration do
|
|
10
10
|
:default => false
|
11
11
|
|
12
12
|
puts 'Field deleted added'
|
13
|
-
puts 'Remember to run the fixes/
|
13
|
+
puts 'Remember to run the fixes/ght_update_project_info.rb script to mark deleted projects'
|
14
14
|
end
|
15
15
|
|
16
16
|
down do
|
@@ -19,7 +19,7 @@ Sequel.migration do
|
|
19
19
|
and not exists (select * from project_members where users.id = user_id)
|
20
20
|
and not exists (select * from issues where reporter_id=users.id )
|
21
21
|
and not exists (select * from issues where assignee_id=users.id )
|
22
|
-
|
22
|
+
and not exists (select * from organization_members where user_id = users.id);"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
require 'ghtorrent/migrations/mysql_defaults'
|
4
|
+
|
5
|
+
|
6
|
+
Sequel.migration do
|
7
|
+
|
8
|
+
up do
|
9
|
+
puts 'Add column deleted to users'
|
10
|
+
add_column :users, :deleted, TrueClass, :null => false, :default => false
|
11
|
+
end
|
12
|
+
|
13
|
+
down do
|
14
|
+
puts 'Drop column deleted from users'
|
15
|
+
alter_table :users do
|
16
|
+
drop_column :deleted
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
require 'ghtorrent/migrations/mysql_defaults'
|
4
|
+
|
5
|
+
|
6
|
+
Sequel.migration do
|
7
|
+
|
8
|
+
up do
|
9
|
+
puts 'Dropping column ext_ref_id from all tables'
|
10
|
+
|
11
|
+
drop_column :users, :ext_ref_id
|
12
|
+
drop_column :projects, :ext_ref_id
|
13
|
+
drop_column :commits, :ext_ref_id
|
14
|
+
drop_column :followers, :ext_ref_id
|
15
|
+
drop_column :commit_comments, :ext_ref_id
|
16
|
+
drop_column :pull_request_history, :ext_ref_id
|
17
|
+
drop_column :pull_request_comments, :ext_ref_id
|
18
|
+
drop_column :issues, :ext_ref_id
|
19
|
+
drop_column :issue_events, :ext_ref_id
|
20
|
+
drop_column :issue_comments, :ext_ref_id
|
21
|
+
drop_column :repo_labels, :ext_ref_id
|
22
|
+
drop_column :repo_milestones, :ext_ref_id
|
23
|
+
drop_column :watchers, :ext_ref_id
|
24
|
+
end
|
25
|
+
|
26
|
+
down do
|
27
|
+
puts 'Add column ext_ref_id to all tables'
|
28
|
+
add_column :users, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
29
|
+
add_column :projects, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
30
|
+
add_column :commits, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
31
|
+
add_column :followers, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
32
|
+
add_column :commit_comments, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
33
|
+
add_column :pull_request_history, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
34
|
+
add_column :pull_request_comments, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
35
|
+
add_column :issues, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
36
|
+
add_column :issue_events, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
37
|
+
add_column :issue_comments, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
38
|
+
add_column :repo_labels, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
39
|
+
add_column :repo_milestones, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
40
|
+
add_column :watchers, :ext_ref_id, String, :null => false, :size => 24, :default => "0"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
require 'ghtorrent/migrations/mysql_defaults'
|
4
|
+
|
5
|
+
|
6
|
+
Sequel.migration do
|
7
|
+
|
8
|
+
up do
|
9
|
+
puts 'Adding table project_languages'
|
10
|
+
|
11
|
+
create_table :project_languages do
|
12
|
+
foreign_key :project_id, :projects, :null => false
|
13
|
+
String :language, :null => false
|
14
|
+
Integer :lines, :null => false, :default => 0
|
15
|
+
DateTime :created_at, :null => false,
|
16
|
+
:default => Sequel::CURRENT_TIMESTAMP
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
down do
|
21
|
+
puts 'Dropping table project_languages'
|
22
|
+
drop_table :project_languages
|
23
|
+
end
|
24
|
+
end
|
@@ -1,3 +1,28 @@
|
|
1
|
+
# A generic class to implement a multiprocess client for clients that listen
|
2
|
+
# to the same queue for incoming messages.
|
3
|
+
#
|
4
|
+
# Client creation is driven by an input file whose format is described
|
5
|
+
# in #options.banner.
|
6
|
+
#
|
7
|
+
# MultiprocessQueueClient expects overriding classes to overload the #clazz method
|
8
|
+
# with the name of a class that respects the following protocol:
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# class ExampleQueueClient
|
12
|
+
# # Constructor accepting a GHTorrent::Settings and a String object
|
13
|
+
# # representing the client configuration and the queue to connect to
|
14
|
+
# def initialize(config, queue); end
|
15
|
+
#
|
16
|
+
# # Start processing using the specified GHTorrent::Command as input
|
17
|
+
# def run(command); end
|
18
|
+
#
|
19
|
+
# # Stop processing of queue messages
|
20
|
+
# def stop; end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# MultiprocessQueueClient does not do any error handling/respawning of
|
24
|
+
# dead children. Client/Sub classes are expected to handle errors by
|
25
|
+
# themselves.
|
1
26
|
class MultiprocessQueueClient < GHTorrent::Command
|
2
27
|
|
3
28
|
include GHTorrent::Settings
|
@@ -33,11 +58,6 @@ Values in the config.yaml file set with the -c command are overridden.
|
|
33
58
|
:type => :string
|
34
59
|
end
|
35
60
|
|
36
|
-
def logger
|
37
|
-
@logger ||= Logger.new(STDOUT)
|
38
|
-
@logger
|
39
|
-
end
|
40
|
-
|
41
61
|
def validate
|
42
62
|
super
|
43
63
|
Trollop::die 'Argument mapping-file is required' unless not args[0].nil?
|
data/lib/ghtorrent/retriever.rb
CHANGED
@@ -4,7 +4,7 @@ require 'cgi'
|
|
4
4
|
require 'ghtorrent/api_client'
|
5
5
|
require 'ghtorrent/settings'
|
6
6
|
require 'ghtorrent/utils'
|
7
|
-
require 'ghtorrent/
|
7
|
+
require 'ghtorrent/logging'
|
8
8
|
|
9
9
|
module GHTorrent
|
10
10
|
module Retriever
|
@@ -12,10 +12,7 @@ module GHTorrent
|
|
12
12
|
include GHTorrent::Settings
|
13
13
|
include GHTorrent::Utils
|
14
14
|
include GHTorrent::APIClient
|
15
|
-
|
16
|
-
def ext_uniq
|
17
|
-
raise Exception.new("Unimplemented")
|
18
|
-
end
|
15
|
+
include GHTorrent::Logging
|
19
16
|
|
20
17
|
def persister
|
21
18
|
raise Exception.new("Unimplemented")
|
@@ -32,13 +29,12 @@ module GHTorrent
|
|
32
29
|
end
|
33
30
|
|
34
31
|
unq = persister.store(:users, u)
|
35
|
-
u[ext_uniq] = unq
|
36
32
|
what = user_type(u['type'])
|
37
|
-
info "
|
33
|
+
info "Added user #{what} #{user}"
|
38
34
|
u
|
39
35
|
else
|
40
36
|
what = user_type(stored_user.first['type'])
|
41
|
-
debug "
|
37
|
+
debug "#{what} #{user} exists"
|
42
38
|
stored_user.first
|
43
39
|
end
|
44
40
|
end
|
@@ -72,22 +68,23 @@ module GHTorrent
|
|
72
68
|
if not email.nil? and user['email'] == email
|
73
69
|
user
|
74
70
|
else
|
71
|
+
warn "Could not find user #{email}"
|
75
72
|
nil
|
76
73
|
end
|
77
74
|
else
|
75
|
+
warn "Could not find user #{email}"
|
78
76
|
nil
|
79
77
|
end
|
80
78
|
end
|
81
79
|
else
|
82
80
|
unless byemail['user']['login'].nil?
|
83
|
-
info "
|
81
|
+
info "Added user #{byemail['user']['login']} retrieved by email #{email}"
|
84
82
|
retrieve_user_byusername(byemail['user']['login'])
|
85
83
|
else
|
86
84
|
u = byemail['user']
|
87
85
|
unq = persister.store(:users, u)
|
88
|
-
u[ext_uniq] = unq
|
89
86
|
what = user_type(u['type'])
|
90
|
-
info "
|
87
|
+
info "Added user #{what} #{user}"
|
91
88
|
u
|
92
89
|
end
|
93
90
|
end
|
@@ -110,19 +107,52 @@ module GHTorrent
|
|
110
107
|
x['follows'] = user
|
111
108
|
|
112
109
|
exists = !persister.find(:followers, {'follows' => user,
|
113
|
-
|
110
|
+
'login' => x['login']}).empty?
|
114
111
|
|
115
112
|
if not exists
|
116
113
|
persister.store(:followers, x)
|
117
|
-
info "
|
114
|
+
info "Added follower #{user} -> #{x['login']}"
|
118
115
|
else
|
119
|
-
debug "
|
116
|
+
debug "Follower #{user} -> #{x['login']} exists"
|
120
117
|
end
|
121
118
|
end
|
122
119
|
|
123
120
|
persister.find(:followers, {'follows' => user})
|
124
121
|
end
|
125
122
|
|
123
|
+
def retrieve_user_following(user)
|
124
|
+
following = paged_api_request(ghurl "users/#{user}/following")
|
125
|
+
user_followers_entry = nil
|
126
|
+
|
127
|
+
following.each do |x|
|
128
|
+
|
129
|
+
if user_followers_entry.nil?
|
130
|
+
reverse_lookup = persister.find(:followers, {'follows' => x['login'],
|
131
|
+
'login' => user})
|
132
|
+
if reverse_lookup.empty?
|
133
|
+
user_followers_entry = retrieve_user_followers(x['login']).\
|
134
|
+
find{|y| y['login'] == user}
|
135
|
+
else
|
136
|
+
user_followers_entry = reverse_lookup[0]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
exists = !persister.find(:followers, {'follows' => x['login'],
|
141
|
+
'login' => user}).empty?
|
142
|
+
if not exists
|
143
|
+
user_followers_entry['follows'] = x['login']
|
144
|
+
user_followers_entry.delete(:_id)
|
145
|
+
user_followers_entry.delete('_id')
|
146
|
+
a = persister.store(:followers, user_followers_entry)
|
147
|
+
info "Added following #{user} -> #{x['login']}"
|
148
|
+
else
|
149
|
+
debug "Following #{user} -> #{x['login']} exists"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
persister.find(:followers, {'login' => user})
|
154
|
+
end
|
155
|
+
|
126
156
|
# Retrieve a single commit from a repo
|
127
157
|
def retrieve_commit(repo, sha, user)
|
128
158
|
commit = persister.find(:commits, {'sha' => "#{sha}"})
|
@@ -136,11 +166,10 @@ module GHTorrent
|
|
136
166
|
end
|
137
167
|
|
138
168
|
unq = persister.store(:commits, c)
|
139
|
-
info "
|
140
|
-
c[ext_uniq] = unq
|
169
|
+
info "Added commit #{user}/#{repo} -> #{sha}"
|
141
170
|
c
|
142
171
|
else
|
143
|
-
debug "
|
172
|
+
debug "Commit #{user}/#{repo} -> #{sha} exists"
|
144
173
|
commit.first
|
145
174
|
end
|
146
175
|
end
|
@@ -173,15 +202,18 @@ module GHTorrent
|
|
173
202
|
end
|
174
203
|
|
175
204
|
unq = persister.store(:repos, r)
|
176
|
-
info "
|
177
|
-
r[ext_uniq] = unq
|
205
|
+
info "Added repo #{user} -> #{repo}"
|
178
206
|
r
|
179
207
|
else
|
180
|
-
debug "
|
208
|
+
debug "Repo #{user} -> #{repo} exists"
|
181
209
|
stored_repo.first
|
182
210
|
end
|
183
211
|
end
|
184
212
|
|
213
|
+
def retrieve_languages(owner, repo)
|
214
|
+
paged_api_request ghurl "repos/#{owner}/#{repo}/languages"
|
215
|
+
end
|
216
|
+
|
185
217
|
# Retrieve organizations the provided user participates into
|
186
218
|
def retrieve_orgs(user)
|
187
219
|
url = ghurl "users/#{user}/orgs"
|
@@ -208,9 +240,9 @@ module GHTorrent
|
|
208
240
|
|
209
241
|
if not exists
|
210
242
|
persister.store(:org_members, x)
|
211
|
-
info "
|
243
|
+
info "Added org_member #{org} -> #{x['login']}"
|
212
244
|
else
|
213
|
-
debug "
|
245
|
+
debug "Org Member #{org} -> #{x['login']} exists"
|
214
246
|
end
|
215
247
|
end
|
216
248
|
|
@@ -239,15 +271,15 @@ module GHTorrent
|
|
239
271
|
r = api_request(ghurl "repos/#{owner}/#{repo}/comments/#{id}")
|
240
272
|
|
241
273
|
if r.empty?
|
242
|
-
|
274
|
+
warn "Could not find commit_comment #{id}. Deleted?"
|
243
275
|
return
|
244
276
|
end
|
245
277
|
|
246
278
|
persister.store(:commit_comments, r)
|
247
|
-
info "
|
279
|
+
info "Added commit_comment #{r['commit_id']} -> #{r['id']}"
|
248
280
|
persister.find(:commit_comments, {'commit_id' => sha, 'id' => id}).first
|
249
281
|
else
|
250
|
-
debug "
|
282
|
+
debug "Commit comment #{comment['commit_id']} -> #{comment['id']} exists"
|
251
283
|
comment
|
252
284
|
end
|
253
285
|
end
|
@@ -334,7 +366,7 @@ module GHTorrent
|
|
334
366
|
url = review_comments_url
|
335
367
|
retrieved_comments = paged_api_request url
|
336
368
|
|
337
|
-
retrieved_comments.each
|
369
|
+
retrieved_comments.each do |x|
|
338
370
|
x['owner'] = owner
|
339
371
|
x['repo'] = repo
|
340
372
|
x['pullreq_id'] = pullreq_id.to_i
|
@@ -345,7 +377,7 @@ module GHTorrent
|
|
345
377
|
'id' => x['id']}).empty?
|
346
378
|
persister.store(:pull_request_comments, x)
|
347
379
|
end
|
348
|
-
|
380
|
+
end
|
349
381
|
|
350
382
|
persister.find(:pull_request_comments, {'owner' => owner, 'repo' => repo,
|
351
383
|
'pullreq_id' => pullreq_id})
|
@@ -354,13 +386,13 @@ module GHTorrent
|
|
354
386
|
def retrieve_pull_req_comment(owner, repo, pullreq_id, comment_id)
|
355
387
|
comment = persister.find(:pull_request_comments, {'repo' => repo,
|
356
388
|
'owner' => owner,
|
357
|
-
'pullreq_id' => pullreq_id,
|
389
|
+
'pullreq_id' => pullreq_id.to_i,
|
358
390
|
'id' => comment_id}).first
|
359
391
|
if comment.nil?
|
360
392
|
r = api_request(ghurl "repos/#{owner}/#{repo}/pulls/comments/#{comment_id}")
|
361
393
|
|
362
394
|
if r.empty?
|
363
|
-
|
395
|
+
warn "Could not find pullreq_comment #{owner}/#{repo} #{pullreq_id}->#{comment_id}. Deleted?"
|
364
396
|
return
|
365
397
|
end
|
366
398
|
|
@@ -368,12 +400,12 @@ module GHTorrent
|
|
368
400
|
r['owner'] = owner
|
369
401
|
r['pullreq_id'] = pullreq_id.to_i
|
370
402
|
persister.store(:pull_request_comments, r)
|
371
|
-
info "
|
403
|
+
info "Added pullreq_comment #{owner}/#{repo} #{pullreq_id}->#{comment_id}"
|
372
404
|
persister.find(:pull_request_comments, {'repo' => repo, 'owner' => owner,
|
373
|
-
'pullreq_id' => pullreq_id,
|
405
|
+
'pullreq_id' => pullreq_id.to_i,
|
374
406
|
'id' => comment_id}).first
|
375
407
|
else
|
376
|
-
debug "
|
408
|
+
debug "Pull request comment #{owner}/#{repo} #{pullreq_id}->#{comment_id} exists"
|
377
409
|
comment
|
378
410
|
end
|
379
411
|
end
|
@@ -409,11 +441,11 @@ module GHTorrent
|
|
409
441
|
'repo' => repo,
|
410
442
|
'issue_id' => issue_id,
|
411
443
|
'id' => x['id']}).empty?
|
412
|
-
info "
|
444
|
+
info "Added issue_event #{owner}/#{repo} #{issue_id}->#{x['id']}"
|
413
445
|
persister.store(:issue_events, x)
|
414
446
|
end
|
415
447
|
x
|
416
|
-
}
|
448
|
+
}
|
417
449
|
a = persister.find(:issue_events, {'owner' => owner, 'repo' => repo,
|
418
450
|
'issue_id' => issue_id})
|
419
451
|
if a.empty? then issue_events else a end
|
@@ -428,7 +460,7 @@ module GHTorrent
|
|
428
460
|
r = api_request(ghurl "repos/#{owner}/#{repo}/issues/events/#{event_id}")
|
429
461
|
|
430
462
|
if r.empty?
|
431
|
-
warn "
|
463
|
+
warn "Could not find issue_event #{owner}/#{repo} #{issue_id}->#{event_id}. Deleted?"
|
432
464
|
return
|
433
465
|
end
|
434
466
|
|
@@ -436,13 +468,13 @@ module GHTorrent
|
|
436
468
|
r['owner'] = owner
|
437
469
|
r['issue_id'] = issue_id
|
438
470
|
persister.store(:issue_events, r)
|
439
|
-
info "
|
471
|
+
info "Added issue_event #{owner}/#{repo} #{issue_id}->#{event_id}"
|
440
472
|
a = persister.find(:issue_events, {'repo' => repo, 'owner' => owner,
|
441
473
|
'issue_id' => issue_id,
|
442
474
|
'id' => event_id}).first
|
443
|
-
if a.nil? then r
|
475
|
+
if a.nil? then r else a end
|
444
476
|
else
|
445
|
-
debug "
|
477
|
+
debug "Issue event #{owner}/#{repo} #{issue_id}->#{event_id} exists"
|
446
478
|
event
|
447
479
|
end
|
448
480
|
end
|
@@ -463,7 +495,7 @@ module GHTorrent
|
|
463
495
|
persister.store(:issue_comments, x)
|
464
496
|
end
|
465
497
|
x
|
466
|
-
}
|
498
|
+
}
|
467
499
|
a = persister.find(:issue_comments, {'owner' => owner, 'repo' => repo,
|
468
500
|
'issue_id' => issue_id})
|
469
501
|
if a.empty? then comments else a end
|
@@ -478,7 +510,7 @@ module GHTorrent
|
|
478
510
|
r = api_request(ghurl "repos/#{owner}/#{repo}/issues/comments/#{comment_id}")
|
479
511
|
|
480
512
|
if r.empty?
|
481
|
-
warn "
|
513
|
+
warn "Could not find issue_comment #{owner}/#{repo} #{issue_id}->#{comment_id}. Deleted?"
|
482
514
|
return
|
483
515
|
end
|
484
516
|
|
@@ -486,13 +518,13 @@ module GHTorrent
|
|
486
518
|
r['owner'] = owner
|
487
519
|
r['issue_id'] = issue_id
|
488
520
|
persister.store(:issue_comments, r)
|
489
|
-
info "
|
521
|
+
info "Added issue_comment #{owner}/#{repo} #{issue_id}->#{comment_id}"
|
490
522
|
a = persister.find(:issue_comments, {'repo' => repo, 'owner' => owner,
|
491
523
|
'issue_id' => issue_id,
|
492
524
|
'id' => comment_id}).first
|
493
|
-
if a.nil? then r
|
525
|
+
if a.nil? then r else a end
|
494
526
|
else
|
495
|
-
debug "
|
527
|
+
debug "Issue comment #{owner}/#{repo} #{issue_id}->#{comment_id} exists"
|
496
528
|
comment
|
497
529
|
end
|
498
530
|
end
|
@@ -521,19 +553,23 @@ module GHTorrent
|
|
521
553
|
api_request "https://api.github.com/events"
|
522
554
|
end
|
523
555
|
|
524
|
-
# Get all events for the specified repo
|
556
|
+
# Get all events for the specified repo.
|
557
|
+
# GitHub will only return 90 days of events
|
525
558
|
def get_repo_events(owner, repo)
|
526
559
|
url = ghurl("repos/#{owner}/#{repo}/events")
|
527
560
|
r = paged_api_request(url)
|
528
561
|
|
529
562
|
r.each do |e|
|
530
|
-
|
531
|
-
|
563
|
+
unless get_event(e['id']).empty?
|
564
|
+
debug "Repository event #{owner}/#{repo} -> #{e['type']}-#{e['id']} already exists"
|
532
565
|
else
|
533
|
-
|
534
|
-
info "
|
566
|
+
persister.store(:events, e)
|
567
|
+
info "Added event for repository #{owner}/#{repo} -> #{e['type']}-#{e['id']}"
|
535
568
|
end
|
536
569
|
end
|
570
|
+
|
571
|
+
persister.find(:events, {'repo.name' => "#{owner}/#{repo}"})
|
572
|
+
|
537
573
|
end
|
538
574
|
|
539
575
|
# Get a specific event by +id+.
|
@@ -575,8 +611,11 @@ module GHTorrent
|
|
575
611
|
exists = !instances.empty?
|
576
612
|
|
577
613
|
unless exists
|
614
|
+
x = api_request(x['url'])
|
615
|
+
x['repo'] = repo
|
616
|
+
x['owner'] = user
|
578
617
|
persister.store(entity, x)
|
579
|
-
info "
|
618
|
+
info "Added #{entity} #{user}/#{repo} -> #{x[discriminator]}"
|
580
619
|
else
|
581
620
|
if refresh
|
582
621
|
instances.each do |i|
|
@@ -590,10 +629,10 @@ module GHTorrent
|
|
590
629
|
instance_selector = selector.merge({discriminator => id})
|
591
630
|
persister.del(entity, instance_selector)
|
592
631
|
persister.store(entity, x)
|
593
|
-
debug "
|
632
|
+
debug "Refreshing #{entity} #{user}/#{repo} -> #{x[discriminator]}"
|
594
633
|
end
|
595
634
|
else
|
596
|
-
debug "
|
635
|
+
debug "#{entity} #{user}/#{repo} -> #{x[discriminator]} exists"
|
597
636
|
end
|
598
637
|
end
|
599
638
|
|
@@ -621,15 +660,19 @@ module GHTorrent
|
|
621
660
|
end
|
622
661
|
|
623
662
|
def repo_bound_item(user, repo, item_id, entity, url, selector,
|
624
|
-
|
663
|
+
discriminator, order = :asc)
|
625
664
|
stored_item = repo_bound_instance(entity, selector, discriminator, item_id)
|
626
665
|
|
627
|
-
if stored_item.empty?
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
666
|
+
r = if stored_item.empty?
|
667
|
+
repo_bound_items(user, repo, entity, url, selector, discriminator,
|
668
|
+
item_id, false, order).first
|
669
|
+
else
|
670
|
+
stored_item.first
|
671
|
+
end
|
672
|
+
if r.nil?
|
673
|
+
warn "Could not find #{entity} #{user}/#{repo} -> #{item_id}. Deleted?"
|
632
674
|
end
|
675
|
+
r
|
633
676
|
end
|
634
677
|
|
635
678
|
def repo_bound_instance(entity, selector, discriminator, item_id)
|