Class: GHTRetrieveRepo
- Inherits:
-
GHTorrent::Command
- Object
- GHTorrent::Command
- GHTRetrieveRepo
- Includes:
- GHTorrent::EventProcessing, GHTorrent::Persister, GHTorrent::Retriever, GHTorrent::Settings
- Defined in:
- lib/ghtorrent/commands/ght_retrieve_repo.rb
Constant Summary
Constants included from GHTorrent::Persister
GHTorrent::Persister::ADAPTERS
Constants included from GHTorrent::Settings
GHTorrent::Settings::CONFIGKEYS, GHTorrent::Settings::DEFAULTS
Instance Method Summary collapse
- #ghtorrent ⇒ Object
- #go ⇒ Object
- #persister ⇒ Object
- #prepare_options(options) ⇒ Object
- #stages ⇒ Object
- #validate ⇒ Object
Methods included from GHTorrent::EventProcessing
#CommitCommentEvent, #CreateEvent, #FollowEvent, #ForkEvent, #IssueCommentEvent, #IssuesEvent, #MemberEvent, #PullRequestEvent, #PullRequestReviewCommentEvent, #PushEvent, #WatchEvent
Methods included from GHTorrent::Persister
Methods included from GHTorrent::Retriever
#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
Methods included from GHTorrent::Logging
#debug, #error, #info, #loggerr, #warn
Methods included from GHTorrent::Settings
#config, #merge, #merge_config_values, #override_config, #settings
Methods included from GHTorrent::Utils
included, #read_value, #user_type, #write_value
Methods included from GHTorrent::APIClient
#api_request, #num_pages, #paged_api_request
Methods inherited from GHTorrent::Command
#command_name, #override_config, #process_options, #queue_client, run, #version
Instance Method Details
#ghtorrent ⇒ Object
62 63 64 65 |
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 62 def ghtorrent @ghtorrent ||= TransactedGHTorrent.new(settings) @ghtorrent end |
#go ⇒ Object
67 68 69 70 71 72 73 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_retrieve_repo.rb', line 67 def go self.settings = override_config(settings, :mirror_history_pages_back, 1000) user_entry = ghtorrent.transaction{ghtorrent.ensure_user(ARGV[0], false, false)} if user_entry.nil? Trollop::die "Cannot find user #{ARGV[0]}" end user = user_entry[:login] repo_entry = ghtorrent.transaction{ghtorrent.ensure_repo(ARGV[0], ARGV[1])} if repo_entry.nil? Trollop::die "Cannot find repository #{ARGV[0]}/#{ARGV[1]}" end repo = repo_entry[:name] unless [:no_entities_given] if [:only_stage].nil? stages.each do |x| ghtorrent.send(x, user, repo) end else ghtorrent.send([:only_stage], user, repo) end end # Process repo events unless [:no_events_given] events = get_repo_events(ARGV[0], ARGV[1]).sort{|e| e['id'].to_i} events.each do |event| begin next if @exclude_event_types.include? event['type'] next if [:events_after_given] and event['id'].to_i <= [:events_after] next if [:events_before_given] and event['id'].to_i >= [:events_before] send(event['type'], event) puts "Processed event #{event['type']}-#{event['id']}" rescue StandardError => e puts "Could not process event #{event['type']}-#{event['id']}: #{e.}" end end end end |
#persister ⇒ Object
57 58 59 60 |
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 57 def persister @persister ||= connect(:mongo, settings) @persister end |
#prepare_options(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 15 def () . <<-BANNER An efficient way to get all data for a single repo #{command_name} [options] owner repo BANNER .opt :no_events, 'Skip retrieving events', :default => false .opt :no_entities, 'Skip retrieving entities', :default => false .opt :only_stage, "Only do the provided stage of entity retrieval (one of: #{stages.join(',')})", :type => String .opt :exclude_events, 'Comma separated list of event types to exclude from processing', :type => String .opt :events_after, 'Process all events later than the provided event id', :type => Integer .opt :events_before, 'Process all events earlier than the provided event id', :type => Integer end |
#stages ⇒ Object
51 52 53 54 |
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 51 def stages %w(ensure_commits ensure_forks ensure_pull_requests ensure_issues ensure_watchers ensure_labels ensure_languages) #ensure_project_members end |
#validate ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 35 def validate super Trollop::die 'Two arguments are required' unless args[0] && !args[0].empty? unless [:exclude_events].nil? @exclude_event_types = [:exclude_events].split(/,/) else @exclude_event_types = [] end unless [:only_stage].nil? Trollop::die("Not a valid function: #{[:only_stage]}") unless stages.include? [:only_stage] end end |