Class: PullRequestAi::Repo::Reader
- Inherits:
-
Object
- Object
- PullRequestAi::Repo::Reader
- Defined in:
- lib/pull_request_ai/repo/reader.rb
Instance Attribute Summary collapse
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Instance Method Summary collapse
- #current_branch ⇒ Object
- #current_changes(to_base) ⇒ Object
- #destination_branches ⇒ Object
- #flatten_current_changes(to_base) ⇒ Object
-
#initialize(prompt: Prompt.new) ⇒ Reader
constructor
A new instance of Reader.
- #remote_branches ⇒ Object
- #remote_name ⇒ Object
- #remote_uri ⇒ Object
- #repository_host ⇒ Object
- #repository_slug ⇒ Object
Constructor Details
Instance Attribute Details
#prompt ⇒ Object
Returns the value of attribute prompt.
8 9 10 |
# File 'lib/pull_request_ai/repo/reader.rb', line 8 def prompt @prompt end |
Instance Method Details
#current_branch ⇒ Object
14 15 16 |
# File 'lib/pull_request_ai/repo/reader.rb', line 14 def current_branch prompt.configured? ? Success(prompt.current_branch) : Error.failure(:project_not_configured) end |
#current_changes(to_base) ⇒ Object
68 69 70 71 72 |
# File 'lib/pull_request_ai/repo/reader.rb', line 68 def current_changes(to_base) current_branch.bind do |current| changes_between(to_base, current) end end |
#destination_branches ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pull_request_ai/repo/reader.rb', line 56 def destination_branches current_branch.bind do |current| remote_branches.bind do |branches| if branches.include?(current) Success(branches.reject { _1 == current || _1.start_with?('HEAD') }) else Error.failure(:current_branch_not_pushed) end end end end |
#flatten_current_changes(to_base) ⇒ Object
74 75 76 77 78 |
# File 'lib/pull_request_ai/repo/reader.rb', line 74 def flatten_current_changes(to_base) current_changes(to_base).bind do |changes| Success(changes.inject(''.dup) { |result, file| result << file.trimmed_modified_lines }) end end |
#remote_branches ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/pull_request_ai/repo/reader.rb', line 46 def remote_branches remote_name.bind do |name| branches = prompt.remote_branches .reject { !_1.strip.start_with?(name) } .map { _1.strip.sub(%r{\A#{name}/}, '') } .reject(&:empty?) Success(branches) end end |
#remote_name ⇒ Object
18 19 20 |
# File 'lib/pull_request_ai/repo/reader.rb', line 18 def remote_name prompt.configured? ? Success(prompt.remote_name) : Error.failure(:project_not_configured) end |
#remote_uri ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/pull_request_ai/repo/reader.rb', line 36 def remote_uri remote_name.bind do |name| url = prompt.remote_url(name) uri = GitCloneUrl.parse(url) Success(uri) end rescue URI::InvalidComponentError Error.failure(:invalid_repository_url) end |
#repository_host ⇒ Object
30 31 32 33 34 |
# File 'lib/pull_request_ai/repo/reader.rb', line 30 def repository_host remote_uri.bind do |uri| Success(uri.host) end end |