ghtorrent 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,3 @@
1
- # Copyright 2012 Georgios Gousios <gousiosg@gmail.com>
2
- #
3
- # Redistribution and use in source and binary forms, with or
4
- # without modification, are permitted provided that the following
5
- # conditions are met:
6
- #
7
- # 1. Redistributions of source code must retain the above
8
- # copyright notice, this list of conditions and the following
9
- # disclaimer.
10
- #
11
- # 2. Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following
13
- # disclaimer in the documentation and/or other materials
14
- # provided with the distribution.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- # AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
- # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
-
29
1
  require 'logger'
30
2
 
31
3
  module GHTorrent
@@ -0,0 +1,23 @@
1
+ require 'sequel'
2
+
3
+ Sequel.migration do
4
+ up do
5
+
6
+ puts("Adding table project members")
7
+
8
+ create_table :project_members do
9
+ foreign_key :repo_id, :projects, :null => false
10
+ foreign_key :user_id, :users, :null => false
11
+ DateTime :created_at, :null => false,
12
+ :default => Sequel::CURRENT_TIMESTAMP
13
+ String :ext_ref_id, :null => false, :size => 24, :default => "0"
14
+ primary_key [:repo_id, :user_id]
15
+ end
16
+ end
17
+
18
+ down do
19
+
20
+ drop_table :project_members
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'sequel'
2
+
3
+ Sequel.migration do
4
+ up do
5
+
6
+ puts("Adding table watchers")
7
+
8
+ create_table :watchers do
9
+ foreign_key :repo_id, :projects, :null => false
10
+ foreign_key :user_id, :users, :null => false
11
+ DateTime :created_at, :null => false,
12
+ :default => Sequel::CURRENT_TIMESTAMP
13
+ String :ext_ref_id, :null => false, :size => 24, :default => "0"
14
+ primary_key [:repo_id, :user_id]
15
+ end
16
+ end
17
+
18
+ down do
19
+
20
+ drop_table :watchers
21
+
22
+ end
23
+ end
@@ -1,31 +1,3 @@
1
- # Copyright 2012 Georgios Gousios <gousiosg@gmail.com>
2
- #
3
- # Redistribution and use in source and binary forms, with or
4
- # without modification, are permitted provided that the following
5
- # conditions are met:
6
- #
7
- # 1. Redistributions of source code must retain the above
8
- # copyright notice, this list of conditions and the following
9
- # disclaimer.
10
- #
11
- # 2. Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following
13
- # disclaimer in the documentation and/or other materials
14
- # provided with the distribution.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- # AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
- # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
-
29
1
  module GHTorrent
30
2
 
31
3
  #
@@ -1,30 +1,4 @@
1
- # Copyright 2012 Georgios Gousios <gousiosg@gmail.com>
2
- #
3
- # Redistribution and use in source and binary forms, with or
4
- # without modification, are permitted provided that the following
5
- # conditions are met:
6
- #
7
- # 1. Redistributions of source code must retain the above
8
- # copyright notice, this list of conditions and the following
9
- # disclaimer.
10
- #
11
- # 2. Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following
13
- # disclaimer in the documentation and/or other materials
14
- # provided with the distribution.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- # AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
- # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
1
+ require 'uri'
28
2
 
29
3
  module GHTorrent
30
4
  module Retriever
@@ -60,11 +34,11 @@ module GHTorrent
60
34
  end
61
35
  end
62
36
 
63
- # Try Github API v2 user search by email. This is optional info, so
37
+ # Try Github user search by email. This is optional info, so
64
38
  # it may not return any data.
65
- # http://develop.github.com/p/users.html
39
+ # http://developer.github.com/v3/search/#email-search
66
40
  def retrieve_user_byemail(email, name)
67
- url = ghurl_v2("user/email/#{email}")
41
+ url = ghurl("legacy/user/email/#{URI.escape(email)}")
68
42
  r = api_request(url)
69
43
 
70
44
  return nil if r.empty?
@@ -127,15 +101,8 @@ module GHTorrent
127
101
  url = ghurl "repos/#{user}/#{repo}/commits?last_sha=#{last_sha}"
128
102
  commits = paged_api_request(url, config(:mirror_commit_pages_new_repo))
129
103
 
130
- commits.reduce(Array.new) do |acc, c|
131
- commit = @persister.find(:commits, {'sha' => "#{c['sha']}"})
132
-
133
- if commit.empty?
134
- acc << retrieve_commit(repo, c['sha'], user)
135
- else
136
- debug "Retriever: Already got commit #{repo} -> #{c['sha']}"
137
- end
138
- acc
104
+ commits.map do |c|
105
+ retrieve_commit(repo, c['sha'], user)
139
106
  end
140
107
  end
141
108
 
@@ -197,45 +164,39 @@ module GHTorrent
197
164
  @persister.find(:org_members, {'org' => org}).map{|o| retrieve_org(o['login'])}
198
165
  end
199
166
 
200
- # Retrieve all commit comments for a specific repository
201
- def retrieve_repo_comments(repo, user)
202
- commit_comments = paged_api_request(ghurl "repos/#{user}/#{repo}/comments")
203
- stored_comments = @persister.find(:commit_comments,
204
- {'repo' => repo,
205
- 'user' => user})
206
- store_commit_comments(repo, user, commit_comments, stored_comments)
207
- end
208
-
209
167
  # Retrieve all comments for a single commit
210
- def retrieve_commit_comments(user, repo, sha, reentrer = false)
211
- # Optimization: if no commits comments are registered for the repo
212
- # get them en masse
213
- #items = @persister.count(:commit_comments, {'repo' => repo, 'user' => user})
214
- #if items == 0 && !reentrer
215
- # retrieve_repo_comments(repo, user)
216
- # return retrieve_commit_comments(user, repo, sha, true)
217
- #end
218
-
168
+ def retrieve_commit_comments(user, repo, sha)
219
169
  stored_comments = @persister.find(:commit_comments, {'commit_id' => sha})
220
170
  retrieved_comments = paged_api_request(ghurl "repos/#{user}/#{repo}/commits/#{sha}/comments")
221
- store_commit_comments(repo, user, stored_comments, retrieved_comments)
222
- @persister.find(:commit_comments, {'commit_id' => sha})
223
- end
224
171
 
225
- # Retrieve a single comment
226
- def retrieve_commit_comment(user, repo, id, reentrer = false)
227
- # Optimization: if no commits comments are registered for the repo
228
- # get them en masse
229
- #items = @persister.count(:commit_comments, {'repo' => repo, 'user' => user})
230
- #if items == 0 && !reentrer
231
- # retrieve_repo_comments(repo, user)
232
- # return retrieve_commit_comment(user, repo, id)
233
- #end
172
+ retrieved_comments.each{ |x|
173
+ x['repo'] = repo
174
+ x['user'] = user
175
+ x['commit_id'] = sha
176
+
177
+ if @persister.find(:commit_comments, {'repo' => repo,
178
+ 'user' => user,
179
+ 'id' => x['id']}).empty?
180
+ @persister.store(:commit_comments, x)
181
+ end
182
+ }
183
+ @persister.find(:commit_comments, {'commit_id' => sha})#.map{|x| x[@uniq] = x['_id']; x}
184
+ end
185
+
186
+ # Retrieve a single comment
187
+ def retrieve_commit_comment(user, repo, id)
234
188
 
235
189
  comment = @persister.find(:commit_comments, {'repo' => repo,
236
- 'user' => user, 'id' => id})
237
- if comment.empty?
190
+ 'user' => user,
191
+ 'id' => id}).first
192
+ if comment.nil?
238
193
  r = api_request(ghurl "repos/#{user}/#{repo}/comments/#{id}")
194
+
195
+ if r.empty?
196
+ debug "Retriever: Commit comment #{id} deleted"
197
+ return
198
+ end
199
+
239
200
  r['repo'] = repo
240
201
  r['user'] = user
241
202
  @persister.store(:commit_comments, r)
@@ -244,43 +205,101 @@ module GHTorrent
244
205
  r
245
206
  else
246
207
  debug "Retriever: Commit comment #{comment['commit_id']} -> #{comment['id']} exists"
247
- comment[@uniq] = comment['_id']
248
208
  comment
249
209
  end
250
210
  end
251
211
 
252
- # Get current Github events
253
- def get_events
254
- api_request "https://api.github.com/events"
255
- end
212
+ # Retrieve all collaborators for a repository
213
+ def retrieve_repo_collaborators(user, repo)
256
214
 
257
- private
215
+ url = ghurl "repos/#{user}/#{repo}/collaborators"
216
+ stored_collaborators = @persister.find(:repo_collaborators,
217
+ {'repo' => repo, 'owner' => user})
258
218
 
259
- def ghurl(path)
260
- config(:mirror_urlbase) + path
219
+ collaborators = paged_api_request url
220
+ collaborators.each do |x|
221
+ x['repo'] = repo
222
+ x['owner'] = user
223
+
224
+ exists = !stored_collaborators.find { |f|
225
+ f['login'] == x['login']
226
+ }.nil?
227
+
228
+ if not exists
229
+ @persister.store(:repo_collaborators, x)
230
+ info "Retriever: Added collaborator #{repo} -> #{x['login']}"
231
+ else
232
+ debug "Retriever: Collaborator #{repo} -> #{x['login']} exists"
233
+ end
234
+ end
235
+
236
+ @persister.find(:repo_collaborators, {'repo' => repo, 'owner' => user})
261
237
  end
262
238
 
263
- def ghurl_v2(path)
264
- config(:mirror_urlbase_v2) + path
239
+ # Retrieve a single repository collaborator
240
+ def retrieve_repo_collaborator(user, repo, new_member)
241
+
242
+ collaborator = @persister.find(:repo_collaborators,
243
+ {'repo' => repo,
244
+ 'owner' => user,
245
+ 'login' => new_member})
246
+
247
+ if collaborator.empty?
248
+ retrieve_repo_collaborators(user, repo).find{|x| x['login'] == new_member}
249
+ else
250
+ collaborator.first
251
+ end
265
252
  end
266
253
 
267
- def store_commit_comments(repo, user, stored_comments, retrieved_comments)
268
- retrieved_comments.each do |x|
254
+ # Retrieve all watchers for a repository
255
+ def retrieve_watchers(user, repo)
256
+ stored_watchers = @persister.find(:watchers,
257
+ {'repo' => repo, 'owner' => user})
269
258
 
270
- exists = !stored_comments.find { |f|
271
- f['commit_id'] == x['commit_id'] && f['id'] == x['id']
272
- }.nil?
259
+ watchers = paged_api_request(ghurl "repos/#{user}/#{repo}/watchers")
260
+ watchers.each do |x|
261
+ x['repo'] = repo
262
+ x['owner'] = user
273
263
 
274
- unless exists
275
- x['repo'] = repo
276
- x['user'] = user
264
+ exists = !stored_watchers.find { |f|
265
+ f['login'] == x['login']
266
+ }.nil?
277
267
 
278
- @persister.store(:commit_comments, x)
279
- info "Retriever: Added commit comment #{x['commit_id']} -> #{x['id']}"
268
+ if not exists
269
+ @persister.store(:watchers, x)
270
+ info "Retriever: Added watcher #{repo} -> #{x['login']}"
280
271
  else
281
- debug "Retriever: Commit comment #{x['commit_id']} -> #{x['id']} exists"
272
+ debug "Retriever: Watcher #{repo} -> #{x['login']} exists"
282
273
  end
283
274
  end
275
+
276
+ @persister.find(:watchers, {'repo' => repo, 'owner' => user})
277
+ end
278
+
279
+ # Retrieve a single watcher for a repositry
280
+ def retrieve_watcher(user, repo, watcher)
281
+ stored_watcher = @persister.find(:watchers,
282
+ {'repo' => repo,
283
+ 'owner' => user,
284
+ 'login' => watcher})
285
+
286
+ if stored_watcher.empty?
287
+ retrieve_watchers(user, repo).find{|x| x['login'] == watcher}
288
+ else
289
+ stored_watcher.first
290
+ end
291
+ end
292
+
293
+ # Get current Github events
294
+ def get_events
295
+ api_request "https://api.github.com/events"
284
296
  end
297
+
298
+ private
299
+
300
+ def ghurl(path)
301
+ config(:mirror_urlbase) + path
302
+ end
303
+
285
304
  end
286
305
  end
@@ -1,31 +1,3 @@
1
- # Copyright 2012 Georgios Gousios <gousiosg@gmail.com>
2
- #
3
- # Redistribution and use in source and binary forms, with or
4
- # without modification, are permitted provided that the following
5
- # conditions are met:
6
- #
7
- # 1. Redistributions of source code must retain the above
8
- # copyright notice, this list of conditions and the following
9
- # disclaimer.
10
- #
11
- # 2. Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following
13
- # disclaimer in the documentation and/or other materials
14
- # provided with the distribution.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- # AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
- # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
-
29
1
  require 'yaml'
30
2
 
31
3
  module GHTorrent
@@ -49,7 +21,7 @@ module GHTorrent
49
21
  :mirror_persister => "mirror.persister",
50
22
  :mirror_commit_pages_new_repo => "mirror.commit_pages_new_repo",
51
23
 
52
- :uniq_id => "uniq_id"
24
+ :uniq_id => "mirror.uniq_id"
53
25
  }
54
26
 
55
27
  def config(key)
@@ -1,31 +1,3 @@
1
- # Copyright 2012 Georgios Gousios <gousiosg@gmail.com>
2
- #
3
- # Redistribution and use in source and binary forms, with or
4
- # without modification, are permitted provided that the following
5
- # conditions are met:
6
- #
7
- # 1. Redistributions of source code must retain the above
8
- # copyright notice, this list of conditions and the following
9
- # disclaimer.
10
- #
11
- # 2. Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following
13
- # disclaimer in the documentation and/or other materials
14
- # provided with the distribution.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- # AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
- # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
- # POSSIBILITY OF SUCH DAMAGE.
28
-
29
1
  module GHTorrent
30
2
  module Utils
31
3
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghtorrent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ version: "0.4"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Georgios Gousios
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2012-06-17 00:00:00 Z
18
+ date: 2012-07-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: amqp
@@ -164,6 +163,8 @@ files:
164
163
  - lib/ghtorrent/migrations/002_add_external_ref_ids.rb
165
164
  - lib/ghtorrent/migrations/003_add_orgs.rb
166
165
  - lib/ghtorrent/migrations/004_add_commit_comments.rb
166
+ - lib/ghtorrent/migrations/005_add_repo_collaborators.rb
167
+ - lib/ghtorrent/migrations/006_add_watchers.rb
167
168
  - lib/ghtorrent/persister.rb
168
169
  - lib/ghtorrent/retriever.rb
169
170
  - lib/ghtorrent/settings.rb
@@ -175,6 +176,7 @@ files:
175
176
  - bin/ght-periodic-dump
176
177
  - bin/ght-rm-dupl
177
178
  - bin/ght-torrent-index
179
+ - LICENSE
178
180
  - Rakefile
179
181
  - README.md
180
182
  - test/callstack_test.rb