Class: GHTUpdateRepo
Constant Summary
GHTorrent::Settings::CONFIGKEYS, GHTorrent::Settings::DEFAULTS
GHTorrent::Persister::ADAPTERS
Instance Method Summary
collapse
#debug, #error, #info, #loggerr, #warn
#config, #merge, #merge_config_values, #override_config, #settings
included, #read_value, #user_type, #write_value
#connect, #disconnect
#get_event, #get_events, #get_repo_events, #retrieve_commit, #retrieve_commit_comment, #retrieve_commit_comments, #retrieve_commits, #retrieve_fork, #retrieve_forks, #retrieve_issue, #retrieve_issue_comment, #retrieve_issue_comments, #retrieve_issue_event, #retrieve_issue_events, #retrieve_issue_labels, #retrieve_issues, #retrieve_languages, #retrieve_org, #retrieve_org_members, #retrieve_orgs, #retrieve_pull_req_comment, #retrieve_pull_req_comments, #retrieve_pull_req_commits, #retrieve_pull_request, #retrieve_pull_requests, #retrieve_repo, #retrieve_repo_collaborator, #retrieve_repo_collaborators, #retrieve_repo_label, #retrieve_repo_labels, #retrieve_user_byemail, #retrieve_user_byusername, #retrieve_user_follower, #retrieve_user_followers, #retrieve_user_following, #retrieve_watcher, #retrieve_watchers
#api_request, #num_pages, #paged_api_request
#command_name, #override_config, #process_options, #queue_client, run, #version
Instance Method Details
#date(arg) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 35
def date(arg)
if arg.class != Time
Time.parse(arg)
else
arg
end
end
|
#db ⇒ Object
31
32
33
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 31
def db
@db ||= @ght.get_db
end
|
#go ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 114
def go
@ght ||= GHTorrent::Mirror.new(settings)
unless ARGV[1].nil?
process_project(ARGV[0], ARGV[1])
exit(0)
end
end
|
#persister ⇒ Object
26
27
28
29
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 26
def persister
@persister ||= connect(:mongo, settings)
@persister
end
|
#prepare_options(options) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 12
def prepare_options(options)
options.banner "Updates the deleted field in the project table with current data\n\n\#{command_name} owner repo\n\n BANNER\nend\n"
|
#process_project(owner, name) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 74
def process_project(owner, name)
@ght.transaction do
in_mongo = persister.find(:repos, {'owner.login' => owner, 'name' => name })
on_github = api_request(ghurl ("repos/#{owner}/#{name}"))
unless in_mongo.empty? and on_github.empty?
in_mysql = retrieve_repo(owner, name)
end
if in_mongo.empty?
if on_github.empty?
if in_mysql.nil?
warn "Repo #{owner}/#{name} does not exist in MySQL"
else
set_deleted(owner, name)
end
else
if in_mysql.nil?
warn "Repo #{owner}/#{name} does not exist in MySQL"
else
update_mysql(owner, name, in_mysql)
end
end
else
if on_github.empty?
set_deleted(owner, name)
else
update_mysql(owner, name, in_mysql)
end
end
end
end
|
#set_deleted(owner, repo) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 43
def set_deleted(owner, repo)
db.from(:projects, :users).\
where(:projects__owner_id => :users__id).\
where(:users__login => owner).\
where(:projects__name => repo).\
update(:projects__deleted => true)
info("Project #{owner}/#{repo} marked as deleted")
end
|
#update_mysql(owner, repo, retrieved) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 52
def update_mysql(owner, repo, retrieved)
parent = unless retrieved['parent'].nil?
@ght.ensure_repo(retrieved['parent']['owner']['login'],
retrieved['parent']['name'])
end
db.from(:projects, :users).\
where(:projects__owner_id => :users__id).\
where(:users__login => owner).\
where(:projects__name => repo).\
update(
:projects__url => retrieved['url'],
:projects__description => retrieved['description'],
:projects__language => retrieved['language'],
:projects__created_at => date(retrieved['created_at']),
:projects__forked_from => unless parent.nil? then parent[:id] end)
debug("Repo #{owner}/#{repo} updated")
@ght.ensure_languages(owner, repo)
end
|
#validate ⇒ Object
21
22
23
24
|
# File 'lib/ghtorrent/commands/ght_update_repo.rb', line 21
def validate
super
Trollop::die "Takes two arguments" if ARGV.size == 1
end
|