ghtorrent 0.8 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,8 +38,9 @@ module GHTorrent
38
38
  end
39
39
  end
40
40
 
41
+ # Default logger
41
42
  def logger
42
- raise Exception.new("Unimplemented")
43
+ @logger ||= Logger.new(STDOUT)
43
44
  end
44
45
  end
45
46
  end
@@ -6,12 +6,24 @@ Sequel.migration do
6
6
  up do
7
7
  puts "Fixing table issue_labels"
8
8
 
9
- alter_table :issue_labels do
10
- drop_column :repo_id
11
- drop_column :ext_ref_id
12
- add_foreign_key :issue_id, :issues
13
- add_primary_key ([:issue_id, :label_id])
9
+ #alter_table :issue_labels do
10
+ # drop_constraint 'issue_labels_ibfk_1'
11
+ # drop_constraint 'issue_labels_ibfk_2'
12
+ # drop_column :repo_id
13
+ # drop_column :ext_ref_id
14
+ # drop_column :label_id
15
+ #add_foreign_key :label_id, :repo_labels
16
+ #add_foreign_key :issue_id, :issues
17
+ #add_primary_key ([:issue_id, :label_id])
18
+ #end
19
+
20
+ drop_table :issue_labels
21
+ create_table :issue_labels do
22
+ foreign_key :label_id, :repo_labels
23
+ foreign_key :issue_id, :issues
24
+ primary_key [:issue_id, :label_id]
14
25
  end
26
+
15
27
  end
16
28
 
17
29
  down do
@@ -7,7 +7,7 @@ Sequel.migration do
7
7
  puts "Adding column user_id to table pull_rq"
8
8
 
9
9
  alter_table :pull_request_history do
10
- add_foreign_key :actor_id, :user
10
+ add_foreign_key :actor_id, :users
11
11
  end
12
12
 
13
13
  puts 'Remember to run the fixes/update_pull_request_history_actor.rb
@@ -216,16 +216,11 @@ module GHTorrent
216
216
  end
217
217
 
218
218
  # Retrieve all comments for a single commit
219
- def retrieve_commit_comments(user, repo, sha)
220
- retrieved_comments = paged_api_request(ghurl "repos/#{user}/#{repo}/commits/#{sha}/comments")
219
+ def retrieve_commit_comments(owner, repo, sha)
220
+ retrieved_comments = paged_api_request(ghurl "repos/#{owner}/#{repo}/commits/#{sha}/comments")
221
221
 
222
222
  retrieved_comments.each { |x|
223
- x['repo'] = repo
224
- x['user'] = user
225
- x['commit_id'] = sha
226
-
227
- if persister.find(:commit_comments, {'repo' => repo,
228
- 'user' => user,
223
+ if persister.find(:commit_comments, { 'commit_id' => x['commit_id'],
229
224
  'id' => x['id']}).empty?
230
225
  persister.store(:commit_comments, x)
231
226
  end
@@ -234,25 +229,21 @@ module GHTorrent
234
229
  end
235
230
 
236
231
  # Retrieve a single comment
237
- def retrieve_commit_comment(user, repo, id)
232
+ def retrieve_commit_comment(owner, repo, sha, id)
238
233
 
239
- comment = persister.find(:commit_comments, {'repo' => repo,
240
- 'user' => user,
241
- 'id' => id}).first
234
+ comment = persister.find(:commit_comments, {'commit_id' => sha,
235
+ 'id' => id}).first
242
236
  if comment.nil?
243
- r = api_request(ghurl "repos/#{user}/#{repo}/comments/#{id}")
237
+ r = api_request(ghurl "repos/#{owner}/#{repo}/comments/#{id}")
244
238
 
245
239
  if r.empty?
246
240
  debug "Retriever: Commit comment #{id} deleted"
247
241
  return
248
242
  end
249
243
 
250
- r['repo'] = repo
251
- r['user'] = user
252
244
  persister.store(:commit_comments, r)
253
245
  info "Retriever: Added commit comment #{r['commit_id']} -> #{r['id']}"
254
- persister.find(:commit_comments, {'repo' => repo, 'user' => user,
255
- 'id' => id}).first
246
+ persister.find(:commit_comments, {'commit_id' => sha, 'id' => id}).first
256
247
  else
257
248
  debug "Retriever: Commit comment #{comment['commit_id']} -> #{comment['id']} exists"
258
249
  comment
@@ -34,7 +34,9 @@ module GHTorrent
34
34
 
35
35
  :respect_api_ratelimit => 'mirror.respect_api_ratelimit',
36
36
 
37
- :attach_ip => 'mirror.attach_ip'
37
+ :attach_ip => 'mirror.attach_ip',
38
+
39
+ :rescue_loops => 'mirror.rescue_loops'
38
40
  }
39
41
 
40
42
  DEFAULTS = {
@@ -63,7 +65,9 @@ module GHTorrent
63
65
 
64
66
  :respect_api_ratelimit => 'true',
65
67
 
66
- :attach_ip => '0.0.0.0'
68
+ :attach_ip => '0.0.0.0',
69
+
70
+ :rescue_loops => 'true'
67
71
  }
68
72
 
69
73
  def config(key, use_default = true)
@@ -87,9 +91,9 @@ module GHTorrent
87
91
  more_keys.each {|k,v| CONFIGKEYS[k] = v}
88
92
  end
89
93
 
90
- def merge_config_values(values)
91
- values.reduce(settings) {|acc, k|
92
- acc.merge_recursive write_value(settings, CONFIGKEYS[k[0]], k[1])
94
+ def merge_config_values(config, values)
95
+ values.reduce(config) {|acc, k|
96
+ acc.merge_recursive write_value(config, CONFIGKEYS[k[0]], k[1])
93
97
  }
94
98
  end
95
99
 
@@ -0,0 +1,91 @@
1
+ require 'ghtorrent/ghtorrent'
2
+
3
+
4
+ # A version of the GHTorrent class that creates a transaction per processed
5
+ # item
6
+ class TransactedGhtorrent < GHTorrent::Mirror
7
+
8
+ def ensure_commit(repo, sha, user, comments = true)
9
+ check_transaction do
10
+ super(repo, sha, user, comments)
11
+ end
12
+ end
13
+
14
+ def ensure_commit_comment(owner, repo, sha, comment_id)
15
+ check_transaction do
16
+ super(owner, repo, sha, comment_id)
17
+ end
18
+ end
19
+
20
+ def ensure_fork(owner, repo, fork_id)
21
+ check_transaction do
22
+ super(owner, repo, fork_id)
23
+ end
24
+ end
25
+
26
+ def ensure_pull_request(owner, repo, pullreq_id,
27
+ comments = true, commits = true, history = true,
28
+ state = nil, actor = nil, created_at = nil)
29
+ check_transaction do
30
+ super(owner, repo, pullreq_id, comments, commits, history, state, actor, created_at)
31
+ end
32
+ end
33
+
34
+ def ensure_pullreq_comment(owner, repo, pullreq_id, comment_id)
35
+ check_transaction do
36
+ super(owner, repo, pullreq_id, comment_id)
37
+ end
38
+ end
39
+
40
+ def ensure_issue(owner, repo, issue_id, events = true, comments = true, labels = true)
41
+ check_transaction do
42
+ super(owner, repo, issue_id, events, comments, labels)
43
+ end
44
+ end
45
+
46
+ def ensure_issue_event(owner, repo, issue_id, event_id)
47
+ check_transaction do
48
+ super(owner, repo, issue_id, event_id)
49
+ end
50
+ end
51
+
52
+ def ensure_issue_comment(owner, repo, issue_id, comment_id, pull_req_id = nil)
53
+ check_transaction do
54
+ super(owner, repo, issue_id, comment_id, pull_req_id)
55
+ end
56
+ end
57
+
58
+ def ensure_issue_label(owner, repo, issue_id, name)
59
+ check_transaction do
60
+ super(owner, repo, issue_id, name)
61
+ end
62
+ end
63
+
64
+ def ensure_project_member(owner, repo, new_member, date_added)
65
+ check_transaction do
66
+ super(owner, repo, new_member, date_added)
67
+ end
68
+ end
69
+
70
+ def ensure_watcher(owner, repo, watcher, date_added = nil)
71
+ check_transaction do
72
+ super(owner, repo, watcher, date_added)
73
+ end
74
+ end
75
+
76
+ def ensure_repo_label(owner, repo, name)
77
+ check_transaction do
78
+ super(owner, repo, name)
79
+ end
80
+ end
81
+
82
+ def check_transaction(&block)
83
+ if @db.in_transaction?
84
+ yield block
85
+ else
86
+ transaction do
87
+ yield block
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GHTorrent
2
2
 
3
- VERSION = '0.8'
3
+ VERSION = '0.8.1'
4
4
 
5
5
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ include GHTorrent::Settings
4
+ include GHTorrent::APIClient
5
+
6
+ describe 'The API client' do
7
+
8
+ def stub_config(remaining, reset)
9
+ stub_request(:get, "https://#{config(:github_username)}:#{config(:github_passwd)}@api.github.com/events").
10
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'ghtorrent'}).
11
+ to_return(:status => 200, :body => (1..30).to_a,
12
+ :headers => {'x-ratelimit-remaining' => remaining,
13
+ 'x-ratelimit-reset' => reset})
14
+ end
15
+
16
+ it 'call /events should return 30 results' do
17
+ stub_config(1000, 1000)
18
+ r = api_request 'https://api.github.com/events', false
19
+ expect(r.size).to eq(30)
20
+ end
21
+
22
+ it 'should resume from sleep' do
23
+ time = Time.now.to_i
24
+ stub_config(2, Time.now.to_i + 1)
25
+ api_request 'https://api.github.com/events', false
26
+
27
+
28
+ stub_config(1000, 1000)
29
+ api_request 'https://api.github.com/events', false
30
+ expect(Time.now.to_i - time).to be_within(0.3).of(3)
31
+ end
32
+
33
+ it 'should sleep for 7 seconds' do
34
+ stub_config(2, Time.now.to_i + 5)
35
+
36
+ time = Time.now.to_i
37
+ api_request 'https://api.github.com/events', false
38
+ expect(Time.now.to_i - time).to be_within(0.3).of(7)
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,21 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ require 'ghtorrent'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ end
14
+
15
+ def settings
16
+ YAML::load_file('config.yaml')
17
+ end
18
+
19
+ def logger
20
+ Logger.new(STDERR)
21
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghtorrent
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
5
- prerelease:
4
+ version: 0.8.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Georgios Gousios
@@ -10,60 +9,53 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-09-23 00:00:00.000000000 Z
12
+ date: 2013-12-17 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: amqp
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
22
- version: 1.0.0
20
+ version: 1.1.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
30
- version: 1.0.0
27
+ version: 1.1.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: mongo
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ~>
37
33
  - !ruby/object:Gem::Version
38
- version: 1.8.0
34
+ version: 1.9.0
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ~>
45
40
  - !ruby/object:Gem::Version
46
- version: 1.8.0
41
+ version: 1.9.0
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: bson_ext
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ~>
53
47
  - !ruby/object:Gem::Version
54
- version: 1.8.0
48
+ version: 1.9.0
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ~>
61
54
  - !ruby/object:Gem::Version
62
- version: 1.8.0
55
+ version: 1.9.0
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: trollop
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - ~>
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :runtime
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - ~>
77
68
  - !ruby/object:Gem::Version
@@ -79,37 +70,48 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: sequel
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - ~>
85
75
  - !ruby/object:Gem::Version
86
- version: '3.47'
76
+ version: 4.5.0
87
77
  type: :runtime
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - ~>
93
82
  - !ruby/object:Gem::Version
94
- version: '3.47'
83
+ version: 4.5.0
95
84
  - !ruby/object:Gem::Dependency
96
- name: daemons
85
+ name: rspec
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - ~>
101
89
  - !ruby/object:Gem::Version
102
- version: 1.1.0
103
- type: :runtime
90
+ version: 2.14.0
91
+ type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - ~>
109
96
  - !ruby/object:Gem::Version
110
- version: 1.1.0
111
- description: ! "A library and a collection of associated programs\n to
112
- mirror and process Github data"
97
+ version: 2.14.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: webmock
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '1.16'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '1.16'
112
+ description: |-
113
+ A library and a collection of associated programs
114
+ to mirror and process Github data
113
115
  email: gousiosg@gmail.com
114
116
  executables:
115
117
  - ght-data-retrieval
@@ -123,6 +125,7 @@ executables:
123
125
  extensions: []
124
126
  extra_rdoc_files: []
125
127
  files:
128
+ - lib/ghtorrent.rb
126
129
  - lib/ghtorrent/adapters/base_adapter.rb
127
130
  - lib/ghtorrent/adapters/mongo_persister.rb
128
131
  - lib/ghtorrent/adapters/noop_persister.rb
@@ -134,7 +137,9 @@ files:
134
137
  - lib/ghtorrent/commands/ght_get_more_commits.rb
135
138
  - lib/ghtorrent/commands/ght_load.rb
136
139
  - lib/ghtorrent/commands/ght_mirror_events.rb
140
+ - lib/ghtorrent/commands/ght_retrieve_dependents.rb
137
141
  - lib/ghtorrent/commands/ght_retrieve_repo.rb
142
+ - lib/ghtorrent/commands/ght_retrieve_repos.rb
138
143
  - lib/ghtorrent/commands/ght_retrieve_user.rb
139
144
  - lib/ghtorrent/commands/ght_rm_dupl.rb
140
145
  - lib/ghtorrent/gh_torrent_exception.rb
@@ -162,60 +167,49 @@ files:
162
167
  - lib/ghtorrent/retriever.rb
163
168
  - lib/ghtorrent/settings.rb
164
169
  - lib/ghtorrent/time.rb
170
+ - lib/ghtorrent/transacted_ghtorrent.rb
165
171
  - lib/ghtorrent/utils.rb
166
- - lib/ghtorrent.rb
167
172
  - lib/version.rb
168
173
  - bin/ght-data-retrieval
169
174
  - bin/ght-get-more-commits
170
175
  - bin/ght-load
171
176
  - bin/ght-mirror-events
172
177
  - bin/ght-process-event
178
+ - bin/ght-retrieve-dependents
173
179
  - bin/ght-retrieve-repo
180
+ - bin/ght-retrieve-repos
174
181
  - bin/ght-retrieve-user
175
182
  - bin/ght-rm-dupl
176
183
  - CHANGELOG
177
184
  - Gemfile
178
185
  - Gemfile.lock
179
186
  - LICENSE
180
- - Rakefile
181
187
  - README.md
188
+ - Rakefile
189
+ - spec/api_client_spec.rb
190
+ - spec/spec_helper.rb
182
191
  homepage: https://github.com/gousiosg/github-mirror
183
192
  licenses: []
184
- post_install_message: !binary |-
185
- WxtbMzJtVmVyc2lvbiAwLjgbWzBtXSBSZXRyaWV2ZSBhbmQgcHJvY2VzcyBp
186
- c3N1ZSBsYWJlbHMKWxtbMzJtVmVyc2lvbiAwLjgbWzBtXSBSZXRyaXZlIGFu
187
- ZCBwcm9jZXNzIGFjdG9ycyBmb3IgcHVsbCByZXF1ZXN0IGV2ZW50cwpbG1sz
188
- Mm1WZXJzaW9uIDAuOBtbMG1dIFJldHJpZXZlIHB1bGxyZXEgY29tbWVudHMg
189
- Zm9yIHByb2plY3RzIHdpdGggbm8gaXNzdWV0cmFja2VyClsbWzMybVZlcnNp
190
- b24gMC44G1swbV0gQmV0dGVyIGhldXJpc3RpY3MgZm9yIGF2b2lkaW5nIGR1
191
- bHBpY2F0ZSBlbnRyaWVzIGluIHB1bGwgcmVxdWVzdCBoaXN0b3JpZXMKWxtb
192
- MzJtVmVyc2lvbiAwLjgbWzBtXSBUaGUgZXZlbnQgbG9hZGVyIG5vdyBsb2Fk
193
- cyBldmVudHMgYnkgSURzIHRvIHJlZHVjZSBwcmVzc3VyZSB0byB0aGUgcXVl
194
- dWUKWxtbMzJtVmVyc2lvbiAwLjgbWzBtXSBDb21wb3VuZCBpbmRleGVzIGlu
195
- IE1vbmdvREIgYnkgZGVmYXVsdApbG1szMm1WZXJzaW9uIDAuOBtbMG1dIFgt
196
- UmF0ZUxpbWl0LVJlc2V0IGhlYWRlciBzdXBwb3J0ClsbWzMybVZlcnNpb24g
197
- MC44G1swbV0gUmVtb3ZlIGxvdHMgb2YgZGVhZCBjb2RlLCBnZW5lcmFsIGNs
198
- ZWFudXBzCg==
193
+ metadata: {}
194
+ post_install_message:
199
195
  rdoc_options:
200
196
  - --charset=UTF-8
201
197
  require_paths:
202
198
  - lib
203
199
  required_ruby_version: !ruby/object:Gem::Requirement
204
- none: false
205
200
  requirements:
206
- - - ! '>='
201
+ - - '>='
207
202
  - !ruby/object:Gem::Version
208
203
  version: '0'
209
204
  required_rubygems_version: !ruby/object:Gem::Requirement
210
- none: false
211
205
  requirements:
212
- - - ! '>='
206
+ - - '>='
213
207
  - !ruby/object:Gem::Version
214
208
  version: '0'
215
209
  requirements: []
216
210
  rubyforge_project:
217
- rubygems_version: 1.8.25
211
+ rubygems_version: 2.0.3
218
212
  signing_key:
219
- specification_version: 3
213
+ specification_version: 4
220
214
  summary: Mirror and process Github data
221
215
  test_files: []