Class: Gitmine::Branch
- Inherits:
-
Object
- Object
- Gitmine::Branch
- Defined in:
- lib/gitmine/branch.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#issue_id ⇒ Object
class methods.
Class Method Summary collapse
- .find(issue_id) ⇒ Object
-
.find_local(issue_id) ⇒ Object
TODO: specs Return local branch name for issue_id.
-
.find_remote(issue_id) ⇒ Object
TODO: specs Return remote branch name for issue_id.
-
.local_branches ⇒ Object
Return an array of local branches starting with digits Example [‘123-my-branch’, ‘1234-your-branch’] TODO specs.
-
.remote_branches ⇒ Object
Return an array of remote branches TODO specs.
Instance Method Summary collapse
-
#initialize(issue_id) ⇒ Branch
constructor
A new instance of Branch.
- #local ⇒ Object
- #remote ⇒ Object
Constructor Details
#initialize(issue_id) ⇒ Branch
Returns a new instance of Branch.
68 69 70 |
# File 'lib/gitmine/branch.rb', line 68 def initialize(issue_id) @issue_id = issue_id end |
Instance Attribute Details
#issue_id ⇒ Object
class methods
66 67 68 |
# File 'lib/gitmine/branch.rb', line 66 def issue_id @issue_id end |
Class Method Details
.find(issue_id) ⇒ Object
4 5 6 |
# File 'lib/gitmine/branch.rb', line 4 def find(issue_id) new(issue_id) end |
.find_local(issue_id) ⇒ Object
TODO: specs Return local branch name for issue_id
10 11 12 |
# File 'lib/gitmine/branch.rb', line 10 def find_local(issue_id) local_branches.select { |branch| branch[/^#{issue_id}-/] }.first end |
.find_remote(issue_id) ⇒ Object
TODO: specs Return remote branch name for issue_id
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gitmine/branch.rb', line 16 def find_remote(issue_id) remote_branch = remote_branches.select { |branch| branch[/^#{issue_id}-/] }.first unless remote_branch # Fetch and retry Git.fetch clear_memoized_remote_branches! remote_branch = remote_branches.select { |branch| branch[/^#{issue_id}-/] }.first end remote_branch end |
.local_branches ⇒ Object
Return an array of local branches starting with digits Example
['123-my-branch', '1234-your-branch']
TODO specs
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitmine/branch.rb', line 33 def local_branches branches = [] Git.local_branches.each_line do |line| if match = line[/\d+.*$/] branches << match end end branches end |
.remote_branches ⇒ Object
Return an array of remote branches TODO specs
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitmine/branch.rb', line 47 def remote_branches return @@remote_branches if defined?(@@remote_branches) && @@remote_branches branches = [] Git.remote_branches.each_line do |line| if match = line.match(/origin\/(\d+.*)/) branches << match[1] end end @@remote_branches = branches end |
Instance Method Details
#local ⇒ Object
72 73 74 |
# File 'lib/gitmine/branch.rb', line 72 def local LocalBranch.new(issue_id) end |
#remote ⇒ Object
76 77 78 |
# File 'lib/gitmine/branch.rb', line 76 def remote RemoteBranch.new(issue_id) end |