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
@@ -0,0 +1,140 @@
|
|
1
|
+
module GHTorrent
|
2
|
+
module EventProcessing
|
3
|
+
|
4
|
+
def PushEvent(data)
|
5
|
+
data['payload']['commits'].each do |c|
|
6
|
+
url = c['url'].split(/\//)
|
7
|
+
|
8
|
+
unless url[7].match(/[a-f0-9]{40}$/)
|
9
|
+
error "Ignoring commit #{sha}"
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
ghtorrent.ensure_commit(url[5], url[7], url[4])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def WatchEvent(data)
|
18
|
+
owner = data['repo']['name'].split(/\//)[0]
|
19
|
+
repo = data['repo']['name'].split(/\//)[1]
|
20
|
+
watcher = data['actor']['login']
|
21
|
+
created_at = data['created_at']
|
22
|
+
|
23
|
+
ghtorrent.ensure_watcher(owner, repo, watcher, created_at)
|
24
|
+
end
|
25
|
+
|
26
|
+
def FollowEvent(data)
|
27
|
+
follower = data['actor']['login']
|
28
|
+
followed = data['payload']['target']['login']
|
29
|
+
created_at = data['created_at']
|
30
|
+
|
31
|
+
ghtorrent.ensure_user_follower(followed, follower, created_at)
|
32
|
+
end
|
33
|
+
|
34
|
+
def MemberEvent(data)
|
35
|
+
owner = data['actor']['login']
|
36
|
+
repo = data['repo']['name'].split(/\//)[1]
|
37
|
+
new_member = data['payload']['member']['login']
|
38
|
+
date_added = data['created_at']
|
39
|
+
|
40
|
+
ghtorrent.transaction do
|
41
|
+
pr_members = ghtorrent.get_db[:project_members]
|
42
|
+
project = ghtorrent.ensure_repo(owner, repo)
|
43
|
+
new_user = ghtorrent.ensure_user(new_member, false, false)
|
44
|
+
|
45
|
+
if project.nil? or new_user.nil?
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
memb_exist = pr_members.first(:user_id => new_user[:id],
|
50
|
+
:repo_id => project[:id])
|
51
|
+
|
52
|
+
if memb_exist.nil?
|
53
|
+
added = if date_added.nil?
|
54
|
+
max(project[:created_at], new_user[:created_at])
|
55
|
+
else
|
56
|
+
date_added
|
57
|
+
end
|
58
|
+
|
59
|
+
pr_members.insert(
|
60
|
+
:user_id => new_user[:id],
|
61
|
+
:repo_id => project[:id],
|
62
|
+
:created_at => ghtorrent.date(added)
|
63
|
+
)
|
64
|
+
info "Added project member #{repo} -> #{new_member}"
|
65
|
+
else
|
66
|
+
debug "Project member #{repo} -> #{new_member} exists"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def CommitCommentEvent(data)
|
73
|
+
user = data['repo']['name'].split(/\//)[0]
|
74
|
+
repo = data['repo']['name'].split(/\//)[1]
|
75
|
+
id = data['payload']['comment']['id']
|
76
|
+
sha = data['payload']['comment']['commit_id']
|
77
|
+
|
78
|
+
ghtorrent.ensure_commit_comment(user, repo, sha, id)
|
79
|
+
end
|
80
|
+
|
81
|
+
def PullRequestEvent(data)
|
82
|
+
owner = data['payload']['pull_request']['base']['repo']['owner']['login']
|
83
|
+
repo = data['payload']['pull_request']['base']['repo']['name']
|
84
|
+
pullreq_id = data['payload']['number']
|
85
|
+
action = data['payload']['action']
|
86
|
+
actor = data['actor']['login']
|
87
|
+
created_at = data['created_at']
|
88
|
+
|
89
|
+
ghtorrent.ensure_pull_request(owner, repo, pullreq_id, true, true, true,
|
90
|
+
action, actor, created_at)
|
91
|
+
end
|
92
|
+
|
93
|
+
def ForkEvent(data)
|
94
|
+
owner = data['repo']['name'].split(/\//)[0]
|
95
|
+
repo = data['repo']['name'].split(/\//)[1]
|
96
|
+
fork_id = data['payload']['forkee']['id']
|
97
|
+
|
98
|
+
forkee_owner = data['payload']['forkee']['owner']['login']
|
99
|
+
forkee_repo = data['payload']['forkee']['name']
|
100
|
+
|
101
|
+
ghtorrent.ensure_fork(owner, repo, fork_id)
|
102
|
+
ghtorrent.ensure_repo_recursive(forkee_owner, forkee_repo, true)
|
103
|
+
end
|
104
|
+
|
105
|
+
def PullRequestReviewCommentEvent(data)
|
106
|
+
owner = data['repo']['name'].split(/\//)[0]
|
107
|
+
repo = data['repo']['name'].split(/\//)[1]
|
108
|
+
comment_id = data['payload']['comment']['id']
|
109
|
+
pullreq_id = data['payload']['comment']['_links']['pull_request']['href'].split(/\//)[-1]
|
110
|
+
|
111
|
+
ghtorrent.ensure_pullreq_comment(owner, repo, pullreq_id, comment_id)
|
112
|
+
end
|
113
|
+
|
114
|
+
def IssuesEvent(data)
|
115
|
+
owner = data['repo']['name'].split(/\//)[0]
|
116
|
+
repo = data['repo']['name'].split(/\//)[1]
|
117
|
+
issue_id = data['payload']['issue']['number']
|
118
|
+
|
119
|
+
ghtorrent.ensure_issue(owner, repo, issue_id)
|
120
|
+
end
|
121
|
+
|
122
|
+
def IssueCommentEvent(data)
|
123
|
+
owner = data['repo']['name'].split(/\//)[0]
|
124
|
+
repo = data['repo']['name'].split(/\//)[1]
|
125
|
+
issue_id = data['payload']['issue']['number']
|
126
|
+
comment_id = data['payload']['comment']['id']
|
127
|
+
|
128
|
+
ghtorrent.ensure_issue_comment(owner, repo, issue_id, comment_id)
|
129
|
+
end
|
130
|
+
|
131
|
+
def CreateEvent(data)
|
132
|
+
owner = data['repo']['name'].split(/\//)[0]
|
133
|
+
repo = data['repo']['name'].split(/\//)[1]
|
134
|
+
return unless data['payload']['ref_type'] == 'repository'
|
135
|
+
|
136
|
+
ghtorrent.ensure_repo(owner, repo)
|
137
|
+
ghtorrent.ensure_repo_recursive(owner, repo, false)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/lib/ghtorrent/ghtorrent.rb
CHANGED
@@ -14,13 +14,14 @@ module GHTorrent
|
|
14
14
|
include GHTorrent::Retriever
|
15
15
|
include GHTorrent::Persister
|
16
16
|
|
17
|
-
attr_reader :settings, :persister, :
|
17
|
+
attr_reader :settings, :persister, :logger
|
18
18
|
|
19
19
|
def initialize(settings)
|
20
20
|
@settings = settings
|
21
|
-
|
22
|
-
@
|
23
|
-
|
21
|
+
|
22
|
+
@retry_on_error = Array.new
|
23
|
+
@retry_on_error << Mysql2::Error if defined? Mysql2::Error
|
24
|
+
@retry_on_error << SQLite3::Exception if defined? SQLite3::Exception
|
24
25
|
end
|
25
26
|
|
26
27
|
def dispose
|
@@ -50,136 +51,6 @@ module GHTorrent
|
|
50
51
|
@persister
|
51
52
|
end
|
52
53
|
|
53
|
-
##
|
54
|
-
# Ensure that a user exists, or fetch its latest state from Github
|
55
|
-
# ==Parameters:
|
56
|
-
# [user] The email or login name to lookup the user by
|
57
|
-
def get_commit(user, repo, sha)
|
58
|
-
|
59
|
-
unless sha.match(/[a-f0-9]{40}$/)
|
60
|
-
error "GHTorrent: Ignoring commit #{sha}"
|
61
|
-
return
|
62
|
-
end
|
63
|
-
|
64
|
-
transaction do
|
65
|
-
ensure_commit(repo, sha, user)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Add a user as member to a project
|
71
|
-
# ==Parameters:
|
72
|
-
# [owner] The login of the repository owner
|
73
|
-
# [repo] The name of the repository
|
74
|
-
# [new_member] The login of the member to add
|
75
|
-
# [date_added] The timestamp that the add event took place
|
76
|
-
def get_project_member(owner, repo, new_member, date_added)
|
77
|
-
transaction do
|
78
|
-
ensure_project_member(owner, repo, new_member, date_added)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
##
|
83
|
-
# Add a commit comment to a commit
|
84
|
-
# ==Parameters:
|
85
|
-
# [user] The login of the repository owner
|
86
|
-
# [repo] The name of the repository
|
87
|
-
# [comment_id] The login of the member to add
|
88
|
-
def get_commit_comment(user, repo, sha, comment_id)
|
89
|
-
transaction do
|
90
|
-
ensure_commit_comment(user, repo, sha, comment_id)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
##
|
95
|
-
# Add a watcher to a repository
|
96
|
-
# ==Parameters:
|
97
|
-
# [owner] The login of the repository owner
|
98
|
-
# [repo] The name of the repository
|
99
|
-
# [watcher] The login of the member to add
|
100
|
-
# [date_added] The timestamp that the add event took place
|
101
|
-
def get_watcher(owner, repo, watcher, date_added)
|
102
|
-
transaction do
|
103
|
-
ensure_watcher(owner, repo, watcher, date_added)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
##
|
108
|
-
# Add a follower to user
|
109
|
-
# ==Parameters:
|
110
|
-
# [follower] The login of the repository owner
|
111
|
-
# [followed] The name of the repository
|
112
|
-
# [date_added] The timestamp that the add event took place
|
113
|
-
def get_follower(follower, followed, date_added)
|
114
|
-
transaction do
|
115
|
-
ensure_user_follower(followed, follower, date_added)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# Get a pull request and record the changes it affects
|
121
|
-
# ==Parameters:
|
122
|
-
# [owner] The owner of the repository to which the pullreq will be applied
|
123
|
-
# [repo] The repository to which the pullreq will be applied
|
124
|
-
# [pullreq_id] The ID of the pull request relative to the repository
|
125
|
-
def get_pull_request(owner, repo, pullreq_id, state, actor, created_at)
|
126
|
-
transaction do
|
127
|
-
ensure_pull_request(owner, repo, pullreq_id, true, true, true, state, actor, created_at)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
##
|
132
|
-
# Retrieve details about a project fork (including the forked project)
|
133
|
-
# ==Parameters:
|
134
|
-
# [owner] The login of the repository owner
|
135
|
-
# [repo] The name of the repository
|
136
|
-
# [fork_id] The fork item id
|
137
|
-
def get_fork(owner, repo, fork_id)
|
138
|
-
transaction do
|
139
|
-
ensure_fork(owner, repo, fork_id)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
##
|
144
|
-
# Retrieve a pull request review comment
|
145
|
-
# ==Parameters:
|
146
|
-
# [owner] The login of the repository owner
|
147
|
-
# [repo] The name of the repository
|
148
|
-
# [fork_id] The fork item id
|
149
|
-
# [date_added] The timestamp that the add event took place
|
150
|
-
def get_pullreq_comment(owner, repo, pullreq_id, comment_id)
|
151
|
-
transaction do
|
152
|
-
ensure_pullreq_comment(owner, repo, pullreq_id, comment_id)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
##
|
157
|
-
# Retrieve an issue
|
158
|
-
# ==Parameters:
|
159
|
-
# [owner] The login of the repository owner
|
160
|
-
# [repo] The name of the repository
|
161
|
-
# [issue_id] The fork item id
|
162
|
-
# [action] The action that took place for the issue
|
163
|
-
# [date_added] The timestamp that the add event took place
|
164
|
-
def get_issue(owner, repo, issue_id)
|
165
|
-
transaction do
|
166
|
-
ensure_issue(owner, repo, issue_id)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
##
|
171
|
-
# Retrieve a issue comment
|
172
|
-
# ==Parameters:
|
173
|
-
# [owner] The login of the repository owner
|
174
|
-
# [repo] The name of the repository
|
175
|
-
# [issue_id] The fork item id
|
176
|
-
# [comment_id] The issue comment unique identifier
|
177
|
-
def get_issue_comment(owner, repo, issue_id, comment_id)
|
178
|
-
transaction do
|
179
|
-
ensure_issue_comment(owner, repo, issue_id, comment_id)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
54
|
##
|
184
55
|
# Make sure a commit exists
|
185
56
|
#
|
@@ -188,7 +59,7 @@ module GHTorrent
|
|
188
59
|
c = retrieve_commit(repo, sha, user)
|
189
60
|
|
190
61
|
if c.nil?
|
191
|
-
warn "
|
62
|
+
warn "Commit #{user}/#{repo} -> #{sha} does not exist"
|
192
63
|
return
|
193
64
|
end
|
194
65
|
|
@@ -210,7 +81,7 @@ module GHTorrent
|
|
210
81
|
# [sha] The first commit to start retrieving from. If nil, then retrieval
|
211
82
|
# starts from what the project considers as master branch.
|
212
83
|
# [return_retrieved] Should retrieved commits be returned? If not, memory is
|
213
|
-
# saved while processing them
|
84
|
+
# saved while processing them.
|
214
85
|
def ensure_commits(user, repo, sha = nil, return_retrieved = false)
|
215
86
|
|
216
87
|
commits = ['foo'] # Dummy entry for simplifying the loop below
|
@@ -253,14 +124,14 @@ module GHTorrent
|
|
253
124
|
if parent.nil?
|
254
125
|
c = retrieve_commit(url[5], url[7], url[4])
|
255
126
|
if c.nil?
|
256
|
-
warn "
|
127
|
+
warn "Could not retrieve commit_parent #{url[4]}/#{url[5]} -> #{url[7]} to #{this[:sha]}"
|
257
128
|
next
|
258
129
|
end
|
259
130
|
parent = store_commit(c, url[5], url[4])
|
260
131
|
end
|
261
132
|
|
262
133
|
if parent.nil?
|
263
|
-
warn "
|
134
|
+
warn "Could not find #{url[4]}/#{url[5]} -> #{url[7]}, parent to commit #{this[:sha]}"
|
264
135
|
next
|
265
136
|
end
|
266
137
|
|
@@ -269,9 +140,9 @@ module GHTorrent
|
|
269
140
|
|
270
141
|
parents.insert(:commit_id => this[:id],
|
271
142
|
:parent_id => parent[:id])
|
272
|
-
info "
|
143
|
+
info "Added commit_parent #{parent[:sha]} to commit #{this[:sha]}"
|
273
144
|
else
|
274
|
-
debug "
|
145
|
+
debug "Parent #{parent[:sha]} for commit #{this[:sha]} exists"
|
275
146
|
end
|
276
147
|
parents.first(:commit_id => this[:id], :parent_id => parent[:id])
|
277
148
|
end
|
@@ -288,7 +159,7 @@ module GHTorrent
|
|
288
159
|
project = ensure_repo(user, repo)
|
289
160
|
|
290
161
|
if project.nil?
|
291
|
-
warn "
|
162
|
+
warn "Repo #{user}/#{repo} does not exist"
|
292
163
|
return
|
293
164
|
end
|
294
165
|
|
@@ -301,11 +172,11 @@ module GHTorrent
|
|
301
172
|
:project_id => project[:id],
|
302
173
|
:commit_id => commitid
|
303
174
|
)
|
304
|
-
|
175
|
+
info "Added commit_assoc of #{sha} with #{user}/#{repo}"
|
305
176
|
@db[:project_commits].first(:project_id => project[:id],
|
306
177
|
:commit_id => commitid)
|
307
178
|
else
|
308
|
-
debug "
|
179
|
+
debug "Association of commit #{sha} with repo #{user}/#{repo} exists"
|
309
180
|
exists
|
310
181
|
end
|
311
182
|
end
|
@@ -314,7 +185,6 @@ module GHTorrent
|
|
314
185
|
# Add (or update) an entry for a commit author. This method uses information
|
315
186
|
# in the JSON object returned by Github to add (or update) a user in the
|
316
187
|
# metadata database with a full user entry (both Git and Github details).
|
317
|
-
# Resolution of how
|
318
188
|
#
|
319
189
|
# ==Parameters:
|
320
190
|
# [githubuser] A hash containing the user's Github login
|
@@ -323,8 +193,6 @@ module GHTorrent
|
|
323
193
|
# The (added/modified) user entry as a Hash.
|
324
194
|
def commit_user(githubuser, commituser)
|
325
195
|
|
326
|
-
raise GHTorrentException.new "git user is null" if commituser.nil?
|
327
|
-
|
328
196
|
users = @db[:users]
|
329
197
|
|
330
198
|
name = commituser['name']
|
@@ -347,7 +215,7 @@ module GHTorrent
|
|
347
215
|
# user has probably changed his user name. Treat the user's by-email
|
348
216
|
# description as valid.
|
349
217
|
if added.nil? and not byemail.nil?
|
350
|
-
warn "
|
218
|
+
warn "Found user #{byemail[:login]} with same email #{email} as non existing user #{login}. Assigning user #{login} to #{byemail[:login]}"
|
351
219
|
return users.first(:login => byemail[:login])
|
352
220
|
end
|
353
221
|
|
@@ -358,7 +226,7 @@ module GHTorrent
|
|
358
226
|
# On absense of something better to do, try to find the user by email
|
359
227
|
# and return a "fake" user entry.
|
360
228
|
if added.nil?
|
361
|
-
warn "
|
229
|
+
warn "User account for user #{login} deleted from Github"
|
362
230
|
return ensure_user("#{name}<#{email}>", false, false)
|
363
231
|
end
|
364
232
|
|
@@ -399,7 +267,7 @@ module GHTorrent
|
|
399
267
|
# ==Returns:
|
400
268
|
# If the user can be retrieved, it is returned as a Hash. Otherwise,
|
401
269
|
# the result is nil
|
402
|
-
def ensure_user(user, followers, orgs)
|
270
|
+
def ensure_user(user, followers = true, orgs = true)
|
403
271
|
# Github only supports alpa-nums and dashes in its usernames.
|
404
272
|
# All other sympbols are treated as emails.
|
405
273
|
if not user.match(/^[\w\-]*$/)
|
@@ -408,12 +276,13 @@ module GHTorrent
|
|
408
276
|
email = email.split(">")[0]
|
409
277
|
name = name.strip unless name.nil?
|
410
278
|
email = email.strip unless email.nil?
|
411
|
-
rescue
|
412
|
-
|
279
|
+
rescue StandardError
|
280
|
+
warn "Not a valid email address: #{user}"
|
281
|
+
return
|
413
282
|
end
|
414
283
|
|
415
284
|
unless is_valid_email(email)
|
416
|
-
warn
|
285
|
+
warn "Extracted email(#{email}) not valid for user #{user}"
|
417
286
|
end
|
418
287
|
u = ensure_user_byemail(email, name)
|
419
288
|
else
|
@@ -441,12 +310,12 @@ module GHTorrent
|
|
441
310
|
u = retrieve_user_byusername(user)
|
442
311
|
|
443
312
|
if u.nil?
|
444
|
-
warn "
|
313
|
+
warn "User #{user} does not exist"
|
445
314
|
return
|
446
315
|
end
|
447
316
|
|
448
317
|
email = unless u['email'].nil?
|
449
|
-
if u['email'].strip ==
|
318
|
+
if u['email'].strip == '' then
|
450
319
|
nil
|
451
320
|
else
|
452
321
|
u['email'].strip
|
@@ -459,20 +328,20 @@ module GHTorrent
|
|
459
328
|
:email => email,
|
460
329
|
:location => u['location'],
|
461
330
|
:fake => false,
|
331
|
+
:deleted => false,
|
462
332
|
:type => user_type(u['type']),
|
463
|
-
:created_at => date(u['created_at'])
|
464
|
-
:ext_ref_id => u[@ext_uniq])
|
333
|
+
:created_at => date(u['created_at']))
|
465
334
|
|
466
|
-
info "
|
335
|
+
info "Added user #{user}"
|
467
336
|
|
468
337
|
if user_type(u['type']) == 'ORG'
|
469
|
-
info "
|
338
|
+
info "User #{user} is an organization. Retrieving members"
|
470
339
|
ensure_org(u['login'], true)
|
471
340
|
end
|
472
341
|
|
473
342
|
users.first(:login => user)
|
474
343
|
else
|
475
|
-
debug "
|
344
|
+
debug "User #{user} exists"
|
476
345
|
usr
|
477
346
|
end
|
478
347
|
end
|
@@ -506,7 +375,7 @@ module GHTorrent
|
|
506
375
|
followed_user = ensure_user(followed, false, false)
|
507
376
|
|
508
377
|
if followed_user.nil? or follower_user.nil?
|
509
|
-
warn "Could not
|
378
|
+
warn "Could not find follower #{follower} or user #{followed}"
|
510
379
|
return
|
511
380
|
end
|
512
381
|
|
@@ -525,29 +394,42 @@ module GHTorrent
|
|
525
394
|
retrieved = retrieve_user_follower(followed, follower)
|
526
395
|
|
527
396
|
if retrieved.nil?
|
528
|
-
warn "
|
397
|
+
warn "Could not retrieve follower #{follower} for #{followed}"
|
529
398
|
return
|
530
399
|
end
|
531
400
|
|
532
401
|
followers.insert(:user_id => followed_id,
|
533
402
|
:follower_id => follower_id,
|
534
|
-
:created_at => added
|
535
|
-
|
536
|
-
info "GHTorrent: User #{follower} follows #{followed}"
|
403
|
+
:created_at => added)
|
404
|
+
info "Added follower #{follower} to #{followed}"
|
537
405
|
else
|
538
|
-
debug "
|
406
|
+
debug "Follower #{follower} for user #{followed} exists"
|
539
407
|
end
|
540
408
|
|
541
409
|
unless date_added.nil?
|
542
|
-
followers.filter(:user_id => followed_id,
|
543
|
-
|
544
|
-
|
545
|
-
debug "GHTorrent: Updating follower #{followed} -> #{follower}, created_at -> #{date(date_added)}"
|
410
|
+
followers.filter(:user_id => followed_id, :follower_id => follower_id)
|
411
|
+
.update(:created_at => date(date_added))
|
412
|
+
info "Updated follower #{followed} -> #{follower}, created_at -> #{date(date_added)}"
|
546
413
|
end
|
547
414
|
|
548
415
|
followers.first(:user_id => followed_id, :follower_id => follower_id)
|
549
416
|
end
|
550
417
|
|
418
|
+
def ensure_user_following(user)
|
419
|
+
curuser = ensure_user(user, false, false)
|
420
|
+
following = @db.from(:followers, :users).\
|
421
|
+
where(:followers__follower_id => curuser[:id]).\
|
422
|
+
where(:followers__user_id => :users__id).select(:login).all
|
423
|
+
|
424
|
+
retrieve_user_following(user).reduce([]) do |acc, x|
|
425
|
+
if following.find {|y| y[:login] == x['follows']}.nil?
|
426
|
+
acc << x
|
427
|
+
else
|
428
|
+
acc
|
429
|
+
end
|
430
|
+
end.map { |x| save{ensure_user_follower(x['follows'], user) }}.select{|x| !x.nil?}
|
431
|
+
end
|
432
|
+
|
551
433
|
##
|
552
434
|
# Try to retrieve a user by email. Search the DB first, fall back to
|
553
435
|
# Github search API if unsuccessful.
|
@@ -567,15 +449,15 @@ module GHTorrent
|
|
567
449
|
u = retrieve_user_byemail(email, name)
|
568
450
|
|
569
451
|
if u.nil? or u['login'].nil?
|
570
|
-
|
452
|
+
warn "Could not retrieve user #{email} through search API query"
|
571
453
|
login = (0...8).map { 65.+(rand(25)).chr }.join
|
572
454
|
users.insert(:email => email,
|
573
455
|
:name => name,
|
574
456
|
:login => login,
|
575
457
|
:fake => true,
|
576
|
-
:
|
577
|
-
:
|
578
|
-
info "
|
458
|
+
:deleted => false,
|
459
|
+
:created_at => Time.now)
|
460
|
+
info "Added user fake #{login} -> #{email}"
|
579
461
|
users.first(:login => login)
|
580
462
|
else
|
581
463
|
in_db = users.first(:login => u['login'])
|
@@ -586,23 +468,23 @@ module GHTorrent
|
|
586
468
|
:email => u['email'],
|
587
469
|
:location => u['location'],
|
588
470
|
:fake => false,
|
589
|
-
:
|
590
|
-
:
|
591
|
-
info "
|
471
|
+
:deleted => false,
|
472
|
+
:created_at => date(u['created_at']))
|
473
|
+
info "Added user #{u['login']} (#{email}) through search API query"
|
592
474
|
else
|
593
475
|
in_db.update(:name => u['name'],
|
594
476
|
:company => u['company'],
|
595
477
|
:email => u['email'],
|
596
478
|
:location => u['location'],
|
597
479
|
:fake => false,
|
598
|
-
:
|
599
|
-
:
|
600
|
-
|
480
|
+
:deleted => false,
|
481
|
+
:created_at => date(u['created_at']))
|
482
|
+
debug "User #{u['login']} with email #{email} exists"
|
601
483
|
end
|
602
484
|
users.first(:login => u['login'])
|
603
485
|
end
|
604
486
|
else
|
605
|
-
debug "
|
487
|
+
debug "User with email #{email} exists"
|
606
488
|
usr
|
607
489
|
end
|
608
490
|
end
|
@@ -617,141 +499,196 @@ module GHTorrent
|
|
617
499
|
# == Returns:
|
618
500
|
# If the repo can be retrieved, it is returned as a Hash. Otherwise,
|
619
501
|
# the result is nil
|
620
|
-
def ensure_repo(user, repo,
|
621
|
-
watchers = true, forks = true, labels = true)
|
502
|
+
def ensure_repo(user, repo, recursive = false)
|
622
503
|
|
623
504
|
repos = @db[:projects]
|
624
505
|
curuser = ensure_user(user, false, false)
|
625
506
|
|
626
507
|
if curuser.nil?
|
627
|
-
warn "
|
508
|
+
warn "Could not find user #{user}"
|
628
509
|
return
|
629
510
|
end
|
630
511
|
|
631
512
|
currepo = repos.first(:owner_id => curuser[:id], :name => repo)
|
632
513
|
|
633
|
-
|
634
|
-
|
514
|
+
unless currepo.nil?
|
515
|
+
debug "Repo #{user}/#{repo} exists"
|
516
|
+
return currepo
|
517
|
+
end
|
635
518
|
|
636
|
-
|
637
|
-
warn "Repo #{user}/#{repo} does not exist"
|
638
|
-
return
|
639
|
-
end
|
519
|
+
r = retrieve_repo(user, repo)
|
640
520
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
:language => r['language'],
|
646
|
-
:created_at => date(r['created_at']),
|
647
|
-
:ext_ref_id => r[@ext_uniq])
|
521
|
+
if r.nil?
|
522
|
+
warn "Could not retrieve repo #{user}/#{repo}"
|
523
|
+
return
|
524
|
+
end
|
648
525
|
|
649
|
-
|
650
|
-
|
651
|
-
|
526
|
+
repos.insert(:url => r['url'],
|
527
|
+
:owner_id => curuser[:id],
|
528
|
+
:name => r['name'],
|
529
|
+
:description => r['description'],
|
530
|
+
:language => r['language'],
|
531
|
+
:created_at => date(r['created_at']))
|
652
532
|
|
653
|
-
|
533
|
+
unless r['parent'].nil?
|
534
|
+
parent_owner = r['parent']['owner']['login']
|
535
|
+
parent_repo = r['parent']['name']
|
654
536
|
|
655
|
-
|
537
|
+
parent = ensure_repo(parent_owner, parent_repo)
|
656
538
|
|
657
|
-
|
658
|
-
end
|
539
|
+
repos.filter(:owner_id => curuser[:id], :name => repo).update(:forked_from => parent[:id])
|
659
540
|
|
660
|
-
info "
|
541
|
+
info "Repo #{user}/#{repo} is a fork from #{parent_owner}/#{parent_repo}"
|
542
|
+
end
|
661
543
|
|
662
|
-
|
663
|
-
watchdog = nil
|
664
|
-
unless parent.nil?
|
665
|
-
watchdog = Thread.new do
|
666
|
-
slept = 0
|
667
|
-
while true do
|
668
|
-
debug "GHTorrent: In ensure_repo_fork for #{slept} seconds"
|
669
|
-
sleep 1
|
670
|
-
slept += 1
|
671
|
-
end
|
672
|
-
end
|
673
|
-
# Fast path to project forking. Retrieve all commits page by page
|
674
|
-
# until we reach a commit that has been registered with the parent
|
675
|
-
# repository. Then, copy all remaining parent commits to this repo.
|
676
|
-
debug "GHTorrent: Retrieving commits for #{user}/#{repo} until we reach a commit shared with the parent"
|
677
|
-
|
678
|
-
sha = nil
|
679
|
-
# Refresh the latest commits for the parent.
|
680
|
-
retrieve_commits(parent_repo, sha, parent_owner, 1).each do |c|
|
681
|
-
sha = c['sha']
|
682
|
-
ensure_commit(parent_repo, sha, parent_owner, true)
|
683
|
-
end
|
544
|
+
info "Added repo #{user}/#{repo}"
|
684
545
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
546
|
+
ensure_repo_recursive(owner, repo, !r['parent'].nil?) if recursive
|
547
|
+
|
548
|
+
repos.first(:owner_id => curuser[:id], :name => repo)
|
549
|
+
end
|
550
|
+
|
551
|
+
def ensure_repo_recursive(owner, repo, is_fork)
|
552
|
+
|
553
|
+
if is_fork
|
554
|
+
r = retrieve_repo(owner, repo)
|
555
|
+
parent_owner = r['parent']['owner']['login']
|
556
|
+
parent_repo = r['parent']['name']
|
557
|
+
ensure_fork_commits(owner, repo, parent_owner, parent_repo)
|
558
|
+
else
|
559
|
+
ensure_commits(owner, repo)
|
560
|
+
end
|
561
|
+
|
562
|
+
functions = %w(ensure_labels ensure_pull_requests
|
563
|
+
ensure_issues ensure_watchers ensure_forks ensure_languages)
|
564
|
+
|
565
|
+
functions.each do |x|
|
566
|
+
send(x, owner, repo)
|
567
|
+
end
|
568
|
+
|
569
|
+
end
|
570
|
+
|
571
|
+
# Get details about the languages used in the repository
|
572
|
+
def ensure_languages(owner, repo)
|
573
|
+
currepo = ensure_repo(owner, repo)
|
574
|
+
langs = retrieve_languages(owner, repo)
|
575
|
+
|
576
|
+
if langs.nil? or langs.empty?
|
577
|
+
warn "Could not find languages for repo #{owner}/#{repo}"
|
578
|
+
return
|
579
|
+
end
|
580
|
+
|
581
|
+
ts = Time.now
|
582
|
+
langs.keys.each do |lang|
|
583
|
+
@db[:project_languages].insert(
|
584
|
+
:project_id => currepo[:id],
|
585
|
+
:language => lang.downcase,
|
586
|
+
:lines => langs[lang],
|
587
|
+
:created_at => ts
|
588
|
+
)
|
589
|
+
info "Added project_language #{owner}/#{repo} -> #{lang} (#{langs[lang]} lines)"
|
590
|
+
end
|
591
|
+
@db[:project_languages].where(:project_id => currepo[:id]).where(:created_at => ts).all
|
592
|
+
end
|
593
|
+
|
594
|
+
# Fast path to project forking. Retrieve all commits page by page
|
595
|
+
# until we reach a commit that has been registered with the parent
|
596
|
+
# repository. Then, copy all remaining parent commits to this repo.
|
597
|
+
def ensure_fork_commits(owner, repo, parent_owner, parent_repo)
|
598
|
+
|
599
|
+
currepo = ensure_repo(owner, repo)
|
600
|
+
|
601
|
+
if currepo.nil?
|
602
|
+
warn "Could not find repo #{owner}/#{repo}"
|
603
|
+
return
|
604
|
+
end
|
605
|
+
|
606
|
+
parent = ensure_repo(parent_owner, parent_repo)
|
607
|
+
|
608
|
+
if parent.nil?
|
609
|
+
warn "Could not find repo #{owner}/#{repo}, parent of #{owner}/#{repo}"
|
610
|
+
return
|
611
|
+
end
|
612
|
+
|
613
|
+
watchdog = Thread.new do
|
614
|
+
slept = 0
|
615
|
+
while true do
|
616
|
+
debug "In ensure_fork_commits (#{owner}/#{repo} fork from #{parent_owner}/#{parent_repo}) for #{slept} seconds"
|
617
|
+
sleep 1
|
618
|
+
slept += 1
|
619
|
+
end
|
620
|
+
end
|
621
|
+
begin
|
622
|
+
info "Retrieving commits for #{owner}/#{repo} until we reach a commit shared with the parent"
|
623
|
+
|
624
|
+
sha = nil
|
625
|
+
# Refresh the latest commits for the parent.
|
626
|
+
retrieve_commits(parent_repo, sha, parent_owner, 1).each do |c|
|
627
|
+
sha = c['sha']
|
628
|
+
ensure_commit(parent_repo, sha, parent_owner)
|
629
|
+
end
|
698
630
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
631
|
+
sha = nil
|
632
|
+
found = false
|
633
|
+
while not found
|
634
|
+
processed = 0
|
635
|
+
commits = retrieve_commits(repo, sha, owner, 1)
|
636
|
+
|
637
|
+
# If only one commit has been retrieved (and this is the same as
|
638
|
+
# the commit since which we query commits from) this mean that
|
639
|
+
# there are no more commits.
|
640
|
+
if commits.size == 1 and commits[0]['sha'] == sha
|
641
|
+
info "Could not find shared commit and no more commits for #{owner}/#{repo}"
|
642
|
+
break
|
643
|
+
end
|
644
|
+
|
645
|
+
for c in commits
|
646
|
+
processed += 1
|
647
|
+
exists_in_parent =
|
648
|
+
!@db.from(:project_commits, :commits).\
|
703
649
|
where(:project_commits__commit_id => :commits__id).\
|
704
650
|
where(:project_commits__project_id => parent[:id]).\
|
705
651
|
where(:commits__sha => c['sha']).first.nil?
|
706
652
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
end
|
715
|
-
end
|
716
|
-
if processed == 0
|
717
|
-
warn "No commits found for #{user}/#{repo}, repo deleted?"
|
718
|
-
found = true
|
719
|
-
end
|
653
|
+
sha = c['sha']
|
654
|
+
if exists_in_parent
|
655
|
+
found = true
|
656
|
+
info "Found commit #{sha} shared with parent, switching to copying commits"
|
657
|
+
break
|
658
|
+
else
|
659
|
+
ensure_commit(repo, sha, owner)
|
720
660
|
end
|
661
|
+
end
|
721
662
|
|
722
|
-
|
723
|
-
|
724
|
-
|
663
|
+
if processed == 0
|
664
|
+
warn "Could not find commits for #{owner}/#{repo}, repo deleted?"
|
665
|
+
break
|
666
|
+
end
|
667
|
+
end
|
725
668
|
|
726
|
-
|
669
|
+
if found
|
670
|
+
shared_commit = @db[:commits].first(:sha => sha)
|
671
|
+
copied = 0
|
672
|
+
@db.from(:project_commits, :commits).\
|
727
673
|
where(:project_commits__commit_id => :commits__id).\
|
728
674
|
where(:project_commits__project_id => parent[:id]).\
|
729
675
|
where('commits.created_at < ?', shared_commit[:created_at]).\
|
730
676
|
select(:commits__id, :commits__sha).\
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
677
|
+
each do |c|
|
678
|
+
copied += 1
|
679
|
+
begin
|
680
|
+
@db[:project_commits].insert(
|
681
|
+
:project_id => currepo[:id],
|
682
|
+
:commit_id => c[:id]
|
683
|
+
)
|
684
|
+
info "Copied commit #{c[:sha]} #{parent_owner}/#{parent_repo} -> #{owner}/#{repo} (#{copied} total)"
|
685
|
+
rescue StandardError => e
|
686
|
+
warn "Could not copy commit #{c[:sha]} #{parent_owner}/#{parent_repo} -> #{owner}/#{repo} : #{e.message}"
|
687
|
+
end
|
737
688
|
end
|
738
|
-
end
|
739
|
-
else
|
740
|
-
ensure_commits(user, repo) if commits
|
741
|
-
end
|
742
|
-
ensure_project_members(user, repo) if project_members
|
743
|
-
ensure_watchers(user, repo) if watchers
|
744
|
-
ensure_forks(user, repo) if forks
|
745
|
-
ensure_labels(user, repo) if labels
|
746
|
-
ensure
|
747
|
-
unless watchdog.nil?
|
748
|
-
watchdog.exit
|
749
|
-
end
|
750
689
|
end
|
751
|
-
|
752
|
-
|
753
|
-
debug "GHTorrent: Repo #{user}/#{repo} exists"
|
754
|
-
currepo
|
690
|
+
ensure
|
691
|
+
watchdog.exit
|
755
692
|
end
|
756
693
|
end
|
757
694
|
|
@@ -782,6 +719,7 @@ module GHTorrent
|
|
782
719
|
new_user = ensure_user(new_member, false, false)
|
783
720
|
|
784
721
|
if project.nil? or new_user.nil?
|
722
|
+
warn "Could not find repo #{owner}/#{repo} or member #{new_member}"
|
785
723
|
return
|
786
724
|
end
|
787
725
|
|
@@ -797,26 +735,25 @@ module GHTorrent
|
|
797
735
|
retrieved = retrieve_repo_collaborator(owner, repo, new_member)
|
798
736
|
|
799
737
|
if retrieved.nil?
|
800
|
-
warn "
|
738
|
+
warn "Could not retrieve member #{new_member} of #{owner}/#{repo}"
|
801
739
|
return
|
802
740
|
end
|
803
741
|
|
804
742
|
pr_members.insert(
|
805
743
|
:user_id => new_user[:id],
|
806
744
|
:repo_id => project[:id],
|
807
|
-
:created_at => date(added)
|
808
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
745
|
+
:created_at => date(added)
|
809
746
|
)
|
810
|
-
info "
|
747
|
+
info "Added project_member #{repo} -> #{new_member}"
|
811
748
|
else
|
812
|
-
debug "
|
749
|
+
debug "Project member #{repo} -> #{new_member} exists"
|
813
750
|
end
|
814
751
|
|
815
752
|
unless date_added.nil?
|
816
753
|
pr_members.filter(:user_id => new_user[:id],
|
817
754
|
:repo_id => project[:id])\
|
818
755
|
.update(:created_at => date(date_added))
|
819
|
-
info "
|
756
|
+
info "Updated project member #{repo} -> #{new_member}, created_at -> #{date(date_added)}"
|
820
757
|
end
|
821
758
|
end
|
822
759
|
|
@@ -842,7 +779,7 @@ module GHTorrent
|
|
842
779
|
org = ensure_org(organization, members)
|
843
780
|
|
844
781
|
if org.nil?
|
845
|
-
warn "
|
782
|
+
warn "Could not find organization #{organization}"
|
846
783
|
return
|
847
784
|
end
|
848
785
|
|
@@ -854,10 +791,10 @@ module GHTorrent
|
|
854
791
|
if participates.nil?
|
855
792
|
org_members.insert(:user_id => usr[:id],
|
856
793
|
:org_id => org[:id])
|
857
|
-
info "
|
794
|
+
info "Added participation #{organization} -> #{user}"
|
858
795
|
org_members.first(:user_id => usr[:id], :org_id => org[:id])
|
859
796
|
else
|
860
|
-
debug "
|
797
|
+
debug "Participation #{organization} -> #{user} exists"
|
861
798
|
participates
|
862
799
|
end
|
863
800
|
|
@@ -877,7 +814,7 @@ module GHTorrent
|
|
877
814
|
|
878
815
|
# Not an organization, don't go ahead
|
879
816
|
if org[:type] != 'ORG'
|
880
|
-
warn "
|
817
|
+
warn "User #{organization} is not an organization"
|
881
818
|
return nil
|
882
819
|
end
|
883
820
|
end
|
@@ -921,7 +858,7 @@ module GHTorrent
|
|
921
858
|
retrieved = retrieve_commit_comment(owner, repo, sha, comment_id)
|
922
859
|
|
923
860
|
if retrieved.nil?
|
924
|
-
warn "
|
861
|
+
warn "Could not retrieve commit_comment #{sha}->#{comment_id}"
|
925
862
|
return
|
926
863
|
end
|
927
864
|
|
@@ -934,12 +871,11 @@ module GHTorrent
|
|
934
871
|
:line => retrieved['line'],
|
935
872
|
:position => retrieved['position'],
|
936
873
|
:comment_id => retrieved['id'],
|
937
|
-
:ext_ref_id => retrieved[@ext_uniq],
|
938
874
|
:created_at => date(retrieved['created_at'])
|
939
875
|
)
|
940
|
-
info "
|
876
|
+
info "Added commit_comment #{owner}/#{repo} -> #{sha}/#{retrieved['id']} by user #{user[:login]}"
|
941
877
|
else
|
942
|
-
|
878
|
+
debug "Commit comment #{sha} -> #{comment_id} exists"
|
943
879
|
end
|
944
880
|
@db[:commit_comments].first(:comment_id => comment_id)
|
945
881
|
end
|
@@ -950,7 +886,7 @@ module GHTorrent
|
|
950
886
|
currepo = ensure_repo(owner, repo)
|
951
887
|
|
952
888
|
if currepo.nil?
|
953
|
-
warn "Could not
|
889
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving watchers"
|
954
890
|
return
|
955
891
|
end
|
956
892
|
|
@@ -976,7 +912,7 @@ module GHTorrent
|
|
976
912
|
new_watcher = ensure_user(watcher, false, false)
|
977
913
|
|
978
914
|
if new_watcher.nil? or project.nil?
|
979
|
-
warn "
|
915
|
+
warn "Could not find watcher #{watcher} or repo #{owner}/#{repo}"
|
980
916
|
return
|
981
917
|
end
|
982
918
|
|
@@ -993,26 +929,25 @@ module GHTorrent
|
|
993
929
|
retrieved = retrieve_watcher(owner, repo, watcher)
|
994
930
|
|
995
931
|
if retrieved.nil?
|
996
|
-
warn "
|
932
|
+
warn "Could not retrieve watcher #{watcher} of repo #{owner}/#{repo}"
|
997
933
|
return
|
998
934
|
end
|
999
935
|
|
1000
936
|
watchers.insert(
|
1001
937
|
:user_id => new_watcher[:id],
|
1002
938
|
:repo_id => project[:id],
|
1003
|
-
:created_at => date(added)
|
1004
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
939
|
+
:created_at => date(added)
|
1005
940
|
)
|
1006
|
-
info "
|
941
|
+
info "Added watcher #{owner}/#{repo} -> #{watcher}"
|
1007
942
|
else
|
1008
|
-
debug "
|
943
|
+
debug "Watcher #{owner}/#{repo} -> #{watcher} exists"
|
1009
944
|
end
|
1010
945
|
|
1011
946
|
unless date_added.nil?
|
1012
947
|
watchers.filter(:user_id => new_watcher[:id],
|
1013
948
|
:repo_id => project[:id])\
|
1014
949
|
.update(:created_at => date(date_added))
|
1015
|
-
info "
|
950
|
+
info "Updated watcher #{owner}/#{repo} -> #{watcher}, created_at -> #{date_added}"
|
1016
951
|
end
|
1017
952
|
|
1018
953
|
watchers.first(:user_id => new_watcher[:id],
|
@@ -1024,7 +959,7 @@ module GHTorrent
|
|
1024
959
|
def ensure_pull_requests(owner, repo, refresh = false)
|
1025
960
|
currepo = ensure_repo(owner, repo)
|
1026
961
|
if currepo.nil?
|
1027
|
-
warn "Could not
|
962
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving pull requests"
|
1028
963
|
return
|
1029
964
|
end
|
1030
965
|
|
@@ -1045,7 +980,7 @@ module GHTorrent
|
|
1045
980
|
end
|
1046
981
|
|
1047
982
|
# Adds a pull request history event
|
1048
|
-
def ensure_pull_request_history(id, ts,
|
983
|
+
def ensure_pull_request_history(id, ts, act, actor)
|
1049
984
|
user = unless actor.nil?
|
1050
985
|
ensure_user(actor, false, false)
|
1051
986
|
end
|
@@ -1063,18 +998,17 @@ module GHTorrent
|
|
1063
998
|
if entry.nil?
|
1064
999
|
pull_req_history.insert(:pull_request_id => id,
|
1065
1000
|
:created_at => ts,
|
1066
|
-
:ext_ref_id => unq,
|
1067
1001
|
:action => act,
|
1068
1002
|
:actor_id => unless user.nil? then user[:id] end)
|
1069
|
-
info "
|
1003
|
+
info "Added pullreq_event (#{id}) -> (#{act}) by (#{actor}) timestamp #{ts}"
|
1070
1004
|
else
|
1071
|
-
|
1005
|
+
debug "Pull request (#{id}) event (#{act}) by (#{actor}) timestamp #{ts} exists"
|
1072
1006
|
if entry[:actor_id].nil? and not user.nil?
|
1073
1007
|
pull_req_history.where(:pull_request_id => id,
|
1074
1008
|
:created_at => (ts - 3)..(ts + 3),
|
1075
1009
|
:action => act)\
|
1076
1010
|
.update(:actor_id => user[:id])
|
1077
|
-
|
1011
|
+
info "Updated pull request (#{id}) event (#{act}) timestamp #{ts}, actor -> #{user[:login]}"
|
1078
1012
|
end
|
1079
1013
|
end
|
1080
1014
|
end
|
@@ -1090,6 +1024,7 @@ module GHTorrent
|
|
1090
1024
|
project = ensure_repo(owner, repo)
|
1091
1025
|
|
1092
1026
|
if project.nil?
|
1027
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving pull request #{pullreq_id}"
|
1093
1028
|
return
|
1094
1029
|
end
|
1095
1030
|
|
@@ -1117,11 +1052,11 @@ module GHTorrent
|
|
1117
1052
|
head = if has_head_repo(req)
|
1118
1053
|
req['head']['repo']['full_name']
|
1119
1054
|
else
|
1120
|
-
|
1055
|
+
'(head deleted)'
|
1121
1056
|
end
|
1122
1057
|
|
1123
|
-
<<-eos.gsub(/\s+/,
|
1124
|
-
|
1058
|
+
<<-eos.gsub(/\s+/, ' ').strip
|
1059
|
+
pull_req #{req['number']}
|
1125
1060
|
#{head} -> #{req['base']['repo']['full_name']}
|
1126
1061
|
eos
|
1127
1062
|
end
|
@@ -1129,7 +1064,7 @@ module GHTorrent
|
|
1129
1064
|
retrieved = retrieve_pull_request(owner, repo, pullreq_id)
|
1130
1065
|
|
1131
1066
|
if retrieved.nil?
|
1132
|
-
warn "
|
1067
|
+
warn "Could not retrieve pull_req #{owner}/#{repo} -> #{pullreq_id}"
|
1133
1068
|
return
|
1134
1069
|
end
|
1135
1070
|
|
@@ -1145,7 +1080,7 @@ module GHTorrent
|
|
1145
1080
|
head_commit = ensure_commit(retrieved['base']['repo']['name'],
|
1146
1081
|
retrieved['head']['sha'],
|
1147
1082
|
retrieved['base']['repo']['owner']['login'])
|
1148
|
-
|
1083
|
+
debug log_msg(retrieved) + ' is intra-branch'
|
1149
1084
|
else
|
1150
1085
|
head_repo = if has_head_repo(retrieved)
|
1151
1086
|
ensure_repo(retrieved['head']['repo']['owner']['login'],
|
@@ -1175,7 +1110,7 @@ module GHTorrent
|
|
1175
1110
|
:pullreq_id => pullreq_id,
|
1176
1111
|
:intra_branch => is_intra_branch(retrieved)
|
1177
1112
|
)
|
1178
|
-
info log_msg(retrieved)
|
1113
|
+
info 'Added ' + log_msg(retrieved)
|
1179
1114
|
else
|
1180
1115
|
debug log_msg(retrieved) + ' exists'
|
1181
1116
|
end
|
@@ -1195,28 +1130,26 @@ module GHTorrent
|
|
1195
1130
|
:issue_id => pullreq_id,
|
1196
1131
|
:pull_request => true,
|
1197
1132
|
:pull_request_id => pull_req[:id],
|
1198
|
-
:created_at => date(retrieved['created_at'])
|
1199
|
-
|
1200
|
-
debug 'Adding accompanying issue for ' + log_msg(retrieved)
|
1133
|
+
:created_at => date(retrieved['created_at']))
|
1134
|
+
debug 'Added accompanying_issue for ' + log_msg(retrieved)
|
1201
1135
|
else
|
1202
|
-
debug 'Accompanying issue
|
1136
|
+
debug 'Accompanying issue for ' + log_msg(retrieved) + ' exists'
|
1203
1137
|
end
|
1204
1138
|
|
1205
1139
|
if history
|
1206
1140
|
# Actions on pull requests
|
1207
1141
|
opener = pull_req_user[:login]
|
1208
1142
|
ensure_pull_request_history(pull_req[:id], date(retrieved['created_at']),
|
1209
|
-
|
1143
|
+
'opened', opener)
|
1210
1144
|
|
1211
1145
|
merger = if retrieved['merged_by'].nil? then actor else retrieved['merged_by']['login'] end
|
1212
1146
|
ensure_pull_request_history(pull_req[:id], date(retrieved['merged_at']),
|
1213
|
-
|
1147
|
+
'merged', merger) if (merged && state != 'merged')
|
1214
1148
|
|
1215
1149
|
closer = if merged then merger else actor end
|
1216
1150
|
ensure_pull_request_history(pull_req[:id], date(retrieved['closed_at']),
|
1217
|
-
|
1218
|
-
ensure_pull_request_history(pull_req[:id], date(created_at),
|
1219
|
-
state, actor) unless state.nil?
|
1151
|
+
'closed', closer) if (closed && state != 'closed')
|
1152
|
+
ensure_pull_request_history(pull_req[:id], date(created_at), state, actor) unless state.nil?
|
1220
1153
|
end
|
1221
1154
|
ensure_pull_request_commits(owner, repo, pullreq_id) if commits
|
1222
1155
|
ensure_pullreq_comments(owner, repo, pullreq_id) if comments
|
@@ -1229,14 +1162,14 @@ module GHTorrent
|
|
1229
1162
|
currepo = ensure_repo(owner, repo)
|
1230
1163
|
|
1231
1164
|
if currepo.nil?
|
1232
|
-
warn "
|
1165
|
+
warn "Could not find repository #{owner}/#{repo} for retrieving pull req comments"
|
1233
1166
|
return
|
1234
1167
|
end
|
1235
1168
|
|
1236
1169
|
pull_req = ensure_pull_request(owner, repo, pullreq_id, false, false, false)
|
1237
1170
|
|
1238
1171
|
if pull_req.nil?
|
1239
|
-
warn "Could not
|
1172
|
+
warn "Could not find pull_req #{owner}/#{repo} -> #{pullreq_id}"
|
1240
1173
|
return
|
1241
1174
|
end
|
1242
1175
|
|
@@ -1261,7 +1194,7 @@ module GHTorrent
|
|
1261
1194
|
pull_req = ensure_pull_request(owner, repo, pullreq_id, false, false, false)
|
1262
1195
|
|
1263
1196
|
if pull_req.nil?
|
1264
|
-
warn "
|
1197
|
+
warn "Could not find pull req #{owner}/#{repo} -> #{pullreq_id} for retrieving comment #{comment_id}"
|
1265
1198
|
return
|
1266
1199
|
end
|
1267
1200
|
|
@@ -1272,14 +1205,14 @@ module GHTorrent
|
|
1272
1205
|
retrieved = retrieve_pull_req_comment(owner, repo, pullreq_id, comment_id)
|
1273
1206
|
|
1274
1207
|
if retrieved.nil?
|
1275
|
-
warn "
|
1208
|
+
warn "Could not retrieve pullreq_comment #{comment_id} for #{owner}/#{repo} -> #{pullreq_id}"
|
1276
1209
|
return
|
1277
1210
|
end
|
1278
1211
|
|
1279
1212
|
commenter = ensure_user(retrieved['user']['login'], false, false)
|
1280
1213
|
|
1281
1214
|
if commenter.nil?
|
1282
|
-
warn "Could not
|
1215
|
+
warn "Could not find commenter #{retrieved['user']['login']}" +
|
1283
1216
|
"for pullreq comment #{owner}/#{repo} -> #{pullreq_id}(#{comment_id}) "
|
1284
1217
|
end
|
1285
1218
|
|
@@ -1292,14 +1225,13 @@ module GHTorrent
|
|
1292
1225
|
:position => retrieved['original_position'],
|
1293
1226
|
:body => retrieved['body'][0..254],
|
1294
1227
|
:commit_id => (commit[:id] unless commit.nil?),
|
1295
|
-
:created_at => retrieved['created_at']
|
1296
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
1228
|
+
:created_at => date(retrieved['created_at'])
|
1297
1229
|
)
|
1298
|
-
|
1230
|
+
info "Added pullreq_comment #{comment_id} for #{owner}/#{repo} -> #{pullreq_id}"
|
1299
1231
|
@db[:pull_request_comments].first(:pull_request_id => pull_req[:id],
|
1300
1232
|
:comment_id => comment_id)
|
1301
1233
|
else
|
1302
|
-
debug "
|
1234
|
+
debug "Comment #{comment_id} for pullreq #{owner}/#{repo} -> #{pullreq_id} exists"
|
1303
1235
|
exists
|
1304
1236
|
end
|
1305
1237
|
end
|
@@ -1308,7 +1240,7 @@ module GHTorrent
|
|
1308
1240
|
pullreq = ensure_pull_request(owner, repo, pullreq_id, false, false, false)
|
1309
1241
|
|
1310
1242
|
if pullreq.nil?
|
1311
|
-
warn "
|
1243
|
+
warn "Could not find pull request #{owner}/#{repo} -> #{pullreq_id} for retrieving commits"
|
1312
1244
|
return
|
1313
1245
|
end
|
1314
1246
|
|
@@ -1316,8 +1248,8 @@ module GHTorrent
|
|
1316
1248
|
next if c.nil?
|
1317
1249
|
head_repo_owner = c['url'].split(/\//)[4]
|
1318
1250
|
head_repo_name = c['url'].split(/\//)[5]
|
1319
|
-
x = ensure_commit(head_repo_name, c['sha'], head_repo_owner
|
1320
|
-
acc << x
|
1251
|
+
x = ensure_commit(head_repo_name, c['sha'], head_repo_owner)
|
1252
|
+
acc << x unless x.nil?
|
1321
1253
|
acc
|
1322
1254
|
}.map do |c|
|
1323
1255
|
save do
|
@@ -1327,9 +1259,9 @@ module GHTorrent
|
|
1327
1259
|
@db[:pull_request_commits].insert(:pull_request_id => pullreq[:id],
|
1328
1260
|
:commit_id => c[:id])
|
1329
1261
|
|
1330
|
-
info "
|
1262
|
+
info "Added pullreq_commit #{c[:sha]} to #{owner}/#{repo} -> #{pullreq_id}"
|
1331
1263
|
else
|
1332
|
-
debug "
|
1264
|
+
debug "Commit #{c[:sha]} in pullreq #{owner}/#{repo} -> #{pullreq_id} exists"
|
1333
1265
|
exists
|
1334
1266
|
end
|
1335
1267
|
end
|
@@ -1342,11 +1274,11 @@ module GHTorrent
|
|
1342
1274
|
# ==Parameters:
|
1343
1275
|
# [owner] The user to which the project belongs
|
1344
1276
|
# [repo] The repository/project to find forks for
|
1345
|
-
def ensure_forks(owner, repo
|
1277
|
+
def ensure_forks(owner, repo)
|
1346
1278
|
currepo = ensure_repo(owner, repo)
|
1347
1279
|
|
1348
1280
|
if currepo.nil?
|
1349
|
-
warn "Could not
|
1281
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving forks"
|
1350
1282
|
return
|
1351
1283
|
end
|
1352
1284
|
|
@@ -1373,7 +1305,7 @@ module GHTorrent
|
|
1373
1305
|
fork = retrieve_fork(owner, repo, fork_id)
|
1374
1306
|
|
1375
1307
|
if fork.nil?
|
1376
|
-
warn "
|
1308
|
+
warn "Could not retrieve fork #{owner}/#{repo} -> #{fork_id}"
|
1377
1309
|
return
|
1378
1310
|
end
|
1379
1311
|
|
@@ -1383,10 +1315,11 @@ module GHTorrent
|
|
1383
1315
|
r = ensure_repo(fork_owner, fork_name)
|
1384
1316
|
|
1385
1317
|
if r.nil?
|
1386
|
-
warn "
|
1318
|
+
warn "Could not add #{fork_owner}/#{fork_name} as fork of #{owner}/#{repo}"
|
1387
1319
|
else
|
1388
|
-
info "
|
1320
|
+
info "Added fork #{fork_owner}/#{fork_name} of #{owner}/#{repo}"
|
1389
1321
|
end
|
1322
|
+
r
|
1390
1323
|
end
|
1391
1324
|
|
1392
1325
|
##
|
@@ -1394,7 +1327,7 @@ module GHTorrent
|
|
1394
1327
|
def ensure_issues(owner, repo, refresh = false)
|
1395
1328
|
currepo = ensure_repo(owner, repo)
|
1396
1329
|
if currepo.nil?
|
1397
|
-
warn "
|
1330
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving issues"
|
1398
1331
|
return
|
1399
1332
|
end
|
1400
1333
|
|
@@ -1423,7 +1356,7 @@ module GHTorrent
|
|
1423
1356
|
repository = ensure_repo(owner, repo)
|
1424
1357
|
|
1425
1358
|
if repo.nil?
|
1426
|
-
warn "
|
1359
|
+
warn "Could not find repo #{owner}/#{repo} for retrieving issue #{issue_id}"
|
1427
1360
|
return
|
1428
1361
|
end
|
1429
1362
|
|
@@ -1433,15 +1366,15 @@ module GHTorrent
|
|
1433
1366
|
retrieved = retrieve_issue(owner, repo, issue_id)
|
1434
1367
|
|
1435
1368
|
if retrieved.nil?
|
1436
|
-
warn "
|
1369
|
+
warn "Could not retrieve issue #{owner}/#{repo} -> #{issue_id}"
|
1437
1370
|
return
|
1438
1371
|
end
|
1439
1372
|
|
1440
1373
|
# Pull requests and issues share the same issue_id
|
1441
1374
|
pull_req = unless retrieved['pull_request'].nil? or
|
1442
1375
|
retrieved['pull_request']['patch_url'].nil?
|
1443
|
-
|
1444
|
-
ensure_pull_request(owner, repo, issue_id)
|
1376
|
+
debug "Issue #{owner}/#{repo}->#{issue_id} is a pull request"
|
1377
|
+
ensure_pull_request(owner, repo, issue_id, false, false, false)
|
1445
1378
|
end
|
1446
1379
|
|
1447
1380
|
if cur_issue.nil?
|
@@ -1457,14 +1390,13 @@ module GHTorrent
|
|
1457
1390
|
:issue_id => issue_id,
|
1458
1391
|
:pull_request => if pull_req.nil? then false else true end,
|
1459
1392
|
:pull_request_id => unless pull_req.nil? then pull_req[:id] end,
|
1460
|
-
:created_at => date(retrieved['created_at'])
|
1461
|
-
:ext_ref_id => retrieved[@ext_uniq])
|
1393
|
+
:created_at => date(retrieved['created_at']))
|
1462
1394
|
|
1463
|
-
info "
|
1395
|
+
info "Added issue #{owner}/#{repo} -> #{issue_id}"
|
1464
1396
|
else
|
1465
|
-
|
1397
|
+
debug "Issue #{owner}/#{repo}->#{issue_id} exists"
|
1466
1398
|
if cur_issue[:pull_request] == false and not pull_req.nil?
|
1467
|
-
info "
|
1399
|
+
info "Updated issue #{owner}/#{repo}->#{issue_id} as pull request"
|
1468
1400
|
issues.filter(:issue_id => issue_id, :repo_id => repository[:id]).update(
|
1469
1401
|
:pull_request => true,
|
1470
1402
|
:pull_request_id => pull_req[:id])
|
@@ -1483,13 +1415,13 @@ module GHTorrent
|
|
1483
1415
|
currepo = ensure_repo(owner, repo)
|
1484
1416
|
|
1485
1417
|
if currepo.nil?
|
1486
|
-
warn "
|
1418
|
+
warn "Could not find repository #{owner}/#{repo} for retrieving events for issue #{issue_id}"
|
1487
1419
|
return
|
1488
1420
|
end
|
1489
1421
|
|
1490
1422
|
issue = ensure_issue(owner, repo, issue_id, false, false, false)
|
1491
1423
|
if issue.nil?
|
1492
|
-
warn "Could not
|
1424
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving events"
|
1493
1425
|
return
|
1494
1426
|
end
|
1495
1427
|
|
@@ -1512,7 +1444,7 @@ module GHTorrent
|
|
1512
1444
|
issue = ensure_issue(owner, repo, issue_id, false, false, false)
|
1513
1445
|
|
1514
1446
|
if issue.nil?
|
1515
|
-
warn "
|
1447
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving event #{event_id}"
|
1516
1448
|
return
|
1517
1449
|
end
|
1518
1450
|
|
@@ -1525,10 +1457,10 @@ module GHTorrent
|
|
1525
1457
|
retrieved = retrieve_issue_event(owner, repo, issue_id, event_id)
|
1526
1458
|
|
1527
1459
|
if retrieved.nil?
|
1528
|
-
warn "
|
1460
|
+
warn "Could not retrieve issue_event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}"
|
1529
1461
|
return
|
1530
1462
|
elsif retrieved['actor'].nil?
|
1531
|
-
warn "
|
1463
|
+
warn "Could not find issue_event_actor #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}"
|
1532
1464
|
return
|
1533
1465
|
end
|
1534
1466
|
|
@@ -1541,18 +1473,18 @@ module GHTorrent
|
|
1541
1473
|
else nil
|
1542
1474
|
end
|
1543
1475
|
|
1544
|
-
if retrieved['event'] ==
|
1476
|
+
if retrieved['event'] == 'assigned'
|
1545
1477
|
|
1546
1478
|
def update_assignee(owner, repo, issue, actor)
|
1547
1479
|
@db[:issues].first(:id => issue[:id]).update(:assignee_id => actor[:id])
|
1548
|
-
info "
|
1480
|
+
info "Updated #{owner}/#{repo} -> #{issue[:id]}, assignee -> #{actor[:id]}"
|
1549
1481
|
end
|
1550
1482
|
|
1551
1483
|
if issue[:assignee_id].nil? then
|
1552
1484
|
update_assignee(owner, repo, issue, actor)
|
1553
1485
|
else
|
1554
1486
|
existing = @db[:issue_events].\
|
1555
|
-
filter(:issue_id => issue[:id],:action =>
|
1487
|
+
filter(:issue_id => issue[:id],:action => 'assigned').\
|
1556
1488
|
order(Sequel.desc(:created_at)).first
|
1557
1489
|
if existing.nil?
|
1558
1490
|
update_assignee(owner, repo, issue, actor)
|
@@ -1568,15 +1500,13 @@ module GHTorrent
|
|
1568
1500
|
:actor_id => unless actor.nil? then actor[:id] end,
|
1569
1501
|
:action => retrieved['event'],
|
1570
1502
|
:action_specific => action_specific,
|
1571
|
-
:created_at => date(retrieved['created_at'])
|
1572
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
1573
|
-
)
|
1503
|
+
:created_at => date(retrieved['created_at']))
|
1574
1504
|
|
1575
|
-
info "
|
1505
|
+
info "Added issue_event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}"
|
1576
1506
|
@db[:issue_events].first(:issue_id => issue[:id],
|
1577
1507
|
:event_id => event_id)
|
1578
1508
|
else
|
1579
|
-
debug "
|
1509
|
+
debug "Issue event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str} exists"
|
1580
1510
|
curevent
|
1581
1511
|
end
|
1582
1512
|
end
|
@@ -1590,7 +1520,7 @@ module GHTorrent
|
|
1590
1520
|
currepo = ensure_repo(owner, repo)
|
1591
1521
|
|
1592
1522
|
if currepo.nil?
|
1593
|
-
warn "
|
1523
|
+
warn "Could not find repository #{owner}/#{repo} for retrieving issue comments for issue #{issue_id}"
|
1594
1524
|
return
|
1595
1525
|
end
|
1596
1526
|
|
@@ -1601,7 +1531,7 @@ module GHTorrent
|
|
1601
1531
|
end
|
1602
1532
|
|
1603
1533
|
if issue.nil?
|
1604
|
-
warn "Could not
|
1534
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving issue comments"
|
1605
1535
|
return
|
1606
1536
|
end
|
1607
1537
|
|
@@ -1629,7 +1559,7 @@ module GHTorrent
|
|
1629
1559
|
end
|
1630
1560
|
|
1631
1561
|
if issue.nil?
|
1632
|
-
warn "
|
1562
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving comment #{comment_id}"
|
1633
1563
|
return
|
1634
1564
|
end
|
1635
1565
|
|
@@ -1642,7 +1572,7 @@ module GHTorrent
|
|
1642
1572
|
retrieved = retrieve_issue_comment(owner, repo, issue_id, comment_id)
|
1643
1573
|
|
1644
1574
|
if retrieved.nil?
|
1645
|
-
warn "
|
1575
|
+
warn "Could not retrieve issue_comment #{issue_comment_str}"
|
1646
1576
|
return
|
1647
1577
|
end
|
1648
1578
|
|
@@ -1652,15 +1582,14 @@ module GHTorrent
|
|
1652
1582
|
:comment_id => comment_id,
|
1653
1583
|
:issue_id => issue[:id],
|
1654
1584
|
:user_id => unless user.nil? then user[:id] end,
|
1655
|
-
:created_at => date(retrieved['created_at'])
|
1656
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
1585
|
+
:created_at => date(retrieved['created_at'])
|
1657
1586
|
)
|
1658
1587
|
|
1659
|
-
info "
|
1588
|
+
info "Added issue_comment #{issue_comment_str}"
|
1660
1589
|
@db[:issue_comments].first(:issue_id => issue[:id],
|
1661
1590
|
:comment_id => comment_id)
|
1662
1591
|
else
|
1663
|
-
debug "
|
1592
|
+
debug "Issue comment #{issue_comment_str} exists"
|
1664
1593
|
curcomment
|
1665
1594
|
end
|
1666
1595
|
end
|
@@ -1670,6 +1599,11 @@ module GHTorrent
|
|
1670
1599
|
def ensure_labels(owner, repo, refresh = false)
|
1671
1600
|
currepo = ensure_repo(owner, repo)
|
1672
1601
|
|
1602
|
+
if currepo.nil?
|
1603
|
+
warn "Could not find #{owner}/#{repo} for retrieving issue labels"
|
1604
|
+
return
|
1605
|
+
end
|
1606
|
+
|
1673
1607
|
repo_labels = @db[:repo_labels].filter(:repo_id => currepo[:id]).all
|
1674
1608
|
|
1675
1609
|
retrieve_repo_labels(owner, repo, refresh).reduce([]) do |acc, x|
|
@@ -1687,7 +1621,7 @@ module GHTorrent
|
|
1687
1621
|
currepo = ensure_repo(owner, repo)
|
1688
1622
|
|
1689
1623
|
if currepo.nil?
|
1690
|
-
warn "
|
1624
|
+
warn "Could not find #{owner}/#{repo} for retrieving label #{name}"
|
1691
1625
|
return
|
1692
1626
|
end
|
1693
1627
|
|
@@ -1697,17 +1631,16 @@ module GHTorrent
|
|
1697
1631
|
retrieved = retrieve_repo_label(owner, repo, name)
|
1698
1632
|
|
1699
1633
|
if retrieved.nil?
|
1700
|
-
warn "
|
1634
|
+
warn "Could not retrieve repo_label #{owner}/#{repo} -> #{name}"
|
1701
1635
|
return
|
1702
1636
|
end
|
1703
1637
|
|
1704
1638
|
@db[:repo_labels].insert(
|
1705
1639
|
:repo_id => currepo[:id],
|
1706
|
-
:name => name
|
1707
|
-
:ext_ref_id => retrieved[@ext_uniq]
|
1640
|
+
:name => name
|
1708
1641
|
)
|
1709
1642
|
|
1710
|
-
info "
|
1643
|
+
info "Added repo_label #{owner}/#{repo} -> #{name}"
|
1711
1644
|
@db[:repo_labels].first(:repo_id => currepo[:id], :name => name)
|
1712
1645
|
else
|
1713
1646
|
label
|
@@ -1721,7 +1654,7 @@ module GHTorrent
|
|
1721
1654
|
issue = ensure_issue(owner, repo, issue_id, false, false, false)
|
1722
1655
|
|
1723
1656
|
if issue.nil?
|
1724
|
-
warn "
|
1657
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving labels"
|
1725
1658
|
return
|
1726
1659
|
end
|
1727
1660
|
|
@@ -1747,14 +1680,14 @@ module GHTorrent
|
|
1747
1680
|
issue = ensure_issue(owner, repo, issue_id, false, false, false)
|
1748
1681
|
|
1749
1682
|
if issue.nil?
|
1750
|
-
warn "
|
1683
|
+
warn "Could not find issue #{owner}/#{repo} -> #{issue_id} to assign label #{name}"
|
1751
1684
|
return
|
1752
1685
|
end
|
1753
1686
|
|
1754
1687
|
label = ensure_repo_label(owner, repo, name)
|
1755
1688
|
|
1756
1689
|
if label.nil?
|
1757
|
-
warn "
|
1690
|
+
warn "Could not find repo label #{owner}/#{repo} -> #{name}"
|
1758
1691
|
return
|
1759
1692
|
end
|
1760
1693
|
|
@@ -1767,10 +1700,11 @@ module GHTorrent
|
|
1767
1700
|
:label_id => label[:id],
|
1768
1701
|
:issue_id => issue[:id],
|
1769
1702
|
)
|
1770
|
-
info "
|
1703
|
+
info "Added issue_label #{name} to issue #{owner}/#{repo} -> #{issue_id}"
|
1771
1704
|
@db[:issue_labels].first(:label_id => label[:id],
|
1772
1705
|
:issue_id => issue[:id])
|
1773
1706
|
else
|
1707
|
+
debug "Issue label #{name} to issue #{owner}/#{repo} -> #{issue_id} exists"
|
1774
1708
|
issue_lbl
|
1775
1709
|
end
|
1776
1710
|
|
@@ -1785,15 +1719,16 @@ module GHTorrent
|
|
1785
1719
|
result = nil
|
1786
1720
|
start_time = Time.now
|
1787
1721
|
begin
|
1788
|
-
@db.transaction(:rollback => :reraise, :isolation => :
|
1722
|
+
@db.transaction(:rollback => :reraise, :isolation => :repeatable,
|
1723
|
+
:retry_on => @retry_on_error, :num_retries => 3) do
|
1789
1724
|
result = yield block
|
1790
1725
|
end
|
1791
1726
|
total = Time.now.to_ms - start_time.to_ms
|
1792
|
-
debug "
|
1727
|
+
debug "Transaction committed (#{total} ms)"
|
1793
1728
|
result
|
1794
|
-
rescue
|
1729
|
+
rescue StandardError => e
|
1795
1730
|
total = Time.now.to_ms - start_time.to_ms
|
1796
|
-
warn "
|
1731
|
+
warn "Transaction failed (#{total} ms)"
|
1797
1732
|
raise e
|
1798
1733
|
ensure
|
1799
1734
|
GC.start
|
@@ -1804,9 +1739,9 @@ module GHTorrent
|
|
1804
1739
|
if config(:rescue_loops) == 'true'
|
1805
1740
|
begin
|
1806
1741
|
yield block
|
1807
|
-
rescue
|
1808
|
-
|
1809
|
-
|
1742
|
+
rescue StandardError => e
|
1743
|
+
error e.message
|
1744
|
+
error e.backtrace.join("\n")
|
1810
1745
|
nil
|
1811
1746
|
end
|
1812
1747
|
else
|
@@ -1826,20 +1761,19 @@ module GHTorrent
|
|
1826
1761
|
repository = ensure_repo(user, repo)
|
1827
1762
|
|
1828
1763
|
if repository.nil?
|
1829
|
-
warn "
|
1764
|
+
warn "Could not find repo #{user}/#{repo} for storing commit #{c['sha']}"
|
1830
1765
|
end
|
1831
1766
|
|
1832
1767
|
commits.insert(:sha => c['sha'],
|
1833
1768
|
:author_id => author[:id],
|
1834
1769
|
:committer_id => commiter[:id],
|
1835
1770
|
:project_id => if repository.nil? then nil else repository[:id] end ,
|
1836
|
-
:created_at => date(c['commit']['author']['date'])
|
1837
|
-
:ext_ref_id => c[@ext_uniq]
|
1771
|
+
:created_at => date(c['commit']['author']['date'])
|
1838
1772
|
)
|
1839
|
-
|
1773
|
+
info "Added commit #{user}/#{repo} -> #{c['sha']} "
|
1840
1774
|
commits.first(:sha => c['sha'])
|
1841
1775
|
else
|
1842
|
-
debug "
|
1776
|
+
debug "Commit #{user}/#{repo} -> #{c['sha']} exists"
|
1843
1777
|
commit
|
1844
1778
|
end
|
1845
1779
|
end
|