Class: GHTRetrieveRepo

Inherits:
GHTorrent::Command show all
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

Methods included from GHTorrent::EventProcessing

#CommitCommentEvent, #CreateEvent, #FollowEvent, #ForkEvent, #IssueCommentEvent, #IssuesEvent, #MemberEvent, #PullRequestEvent, #PullRequestReviewCommentEvent, #PushEvent, #WatchEvent

Methods included from GHTorrent::Persister

#connect, #disconnect

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

#ghtorrentObject



62
63
64
65
# File 'lib/ghtorrent/commands/ght_retrieve_repo.rb', line 62

def ghtorrent
  @ghtorrent ||= TransactedGHTorrent.new(settings)
  @ghtorrent
end

#goObject



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 options[:no_entities_given]
    if options[:only_stage].nil?
      stages.each do |x|
        ghtorrent.send(x, user, repo)
      end
    else
      ghtorrent.send(options[:only_stage], user, repo)
    end
  end

  # Process repo events
  unless options[: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 options[:events_after_given] and event['id'].to_i <= options[:events_after]
        next if options[:events_before_given] and event['id'].to_i >= options[: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.message}"
      end
    end
  end

end

#persisterObject



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 prepare_options(options)
  options.banner <<-BANNER
An efficient way to get all data for a single repo

#{command_name} [options] owner repo

  BANNER
  options.opt :no_events, 'Skip retrieving events', :default => false
  options.opt :no_entities, 'Skip retrieving entities', :default => false

  options.opt :only_stage, "Only do the provided stage of entity retrieval (one of: #{stages.join(',')})",
              :type => String
  options.opt :exclude_events, 'Comma separated list of event types to exclude from processing',
              :type => String
  options.opt :events_after, 'Process all events later than the provided event id',
              :type => Integer
  options.opt :events_before, 'Process all events earlier than the provided event id',
              :type => Integer
end

#stagesObject



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

#validateObject



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 options[:exclude_events].nil?
    @exclude_event_types = options[:exclude_events].split(/,/)
  else
    @exclude_event_types = []
  end

  unless options[:only_stage].nil?
    Trollop::die("Not a valid function: #{options[:only_stage]}") unless stages.include? options[:only_stage]
  end

end