-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathrefresh_pull_request_history.rb
More file actions
executable file
·84 lines (60 loc) · 1.98 KB
/
refresh_pull_request_history.rb
File metadata and controls
executable file
·84 lines (60 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
require 'ghtorrent'
class GHTRefreshPullReqHistory < MultiprocessQueueClient
def clazz
RefreshPullReqHistory
end
end
class RefreshPullReqHistory
include GHTorrent::Settings
include GHTorrent::Retriever
include GHTorrent::Persister
include GHTorrent::APIClient
def initialize(config, queue, options)
@config = config
@queue = queue
end
def logger
@ght.logger
end
def persister
@persister ||= connect(:mongo, settings)
@persister
end
def settings
@config
end
def validate
super
Optimist::die 'Three arguments required' unless args[2] && !args[2].empty?
end
def run(command)
processor = Proc.new do |msg|
owner, repo, pull_req = msg.split(/ /)
@ght ||= GHTorrent::Mirror.new(settings)
col = persister.get_underlying_connection[:pull_requests]
retrieved = api_request("https://api.github.com/repos/#{owner}/#{repo}/pulls/#{pull_req}")
if retrieved.nil?
log.warn("Cannot retrieve #{owner}/#{repo} -> #{pull_req}")
return
end
retrieved['owner'] = owner
retrieved['repo'] = repo
retrieved['number'] = pull_req.to_i
col.delete_one({'owner' => owner, 'repo' => repo, 'number' => pull_req.to_i})
col.insert_one(retrieved)
@ght.db.from(:pull_request_history, :pull_requests, :users, :projects)\
.where(:pull_requests__id => :pull_request_history__pull_request_id)\
.where(:users__id => :projects__owner_id)\
.where(:projects__id => :pull_requests__base_repo_id)\
.where(:users__login => owner)\
.where(:projects__name => repo)\
.where(:pull_requests__pullreq_id => pull_req)\
.delete
@ght.ensure_pull_request(owner, repo, pull_req,
comments = false, commits = false, history = true)
end
command.queue_client(@queue, :after, processor)
end
end
GHTRefreshPullReqHistory.run