Class: MakersToolbelt::FetchPullRequests
- Inherits:
-
Object
- Object
- MakersToolbelt::FetchPullRequests
- Defined in:
- lib/makers_toolbelt/fetch_pull_requests.rb
Constant Summary collapse
- OPEN_SWITCHES =
['-a', '--all', '-o', '--open']
- CLOSED_SWITCHES =
['-a', '--all', '-c', '--closed']
- GITHUB_REMOTE_REGEX =
/github\.com(?::|\/)?(.+\/[\w\-]+)(?:\.git|\/)?\n/
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #include_closed? ⇒ Boolean
- #include_open? ⇒ Boolean
-
#initialize(options = {}) ⇒ FetchPullRequests
constructor
A new instance of FetchPullRequests.
- #repo ⇒ Object
- #repo_from_remote_path(path) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FetchPullRequests
Returns a new instance of FetchPullRequests.
12 13 14 15 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 12 def initialize( = {}) @options = @filter = [:filter] || '--open' end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
10 11 12 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 10 def filter @filter end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 10 def @options end |
Instance Method Details
#include_closed? ⇒ Boolean
47 48 49 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 47 def include_closed? CLOSED_SWITCHES.include? filter end |
#include_open? ⇒ Boolean
43 44 45 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 43 def include_open? OPEN_SWITCHES.include? filter end |
#repo ⇒ Object
32 33 34 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 32 def repo @repo ||= repo_from_remote_path(origin_path) end |
#repo_from_remote_path(path) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 36 def repo_from_remote_path(path) @regex ||= GITHUB_REMOTE_REGEX @regex.match(path).captures.first rescue fail NotFoundError.new('Could not find remote origin') end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/makers_toolbelt/fetch_pull_requests.rb', line 17 def run() pulls = [] pulls << open_pull_requests if include_open? pulls << closed_pull_requests if include_closed? pulls.flatten!.select! {|p| p.head.repo } pulls.map { |p| [p.head.repo.owner.login, p.head.repo.html_url] }.each do |name, url| puts "adding #{name}" `git remote add #{name} #{url}` puts "fetching #{url}" `git fetch #{name}` end end |