Class: Mj::Git::RemoteBranch
- Inherits:
-
Object
- Object
- Mj::Git::RemoteBranch
- Defined in:
- lib/mj/git/remote_branch.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #checkout_command ⇒ Object
- #delete ⇒ Object
- #has_pr? ⇒ Boolean
-
#initialize(name, command_executer: CommandExecuter.new) ⇒ RemoteBranch
constructor
A new instance of RemoteBranch.
- #last_commit_date ⇒ Object
- #last_commiter_email ⇒ Object
- #last_commiter_name ⇒ Object
- #length ⇒ Object
- #pr ⇒ Git::PullRequest
- #summary ⇒ Object
- #to_local ⇒ Object
Constructor Details
#initialize(name, command_executer: CommandExecuter.new) ⇒ RemoteBranch
Returns a new instance of RemoteBranch.
8 9 10 11 |
# File 'lib/mj/git/remote_branch.rb', line 8 def initialize(name, command_executer: CommandExecuter.new) @name = name @command_executer = command_executer end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/mj/git/remote_branch.rb', line 6 def name @name end |
Instance Method Details
#checkout_command ⇒ Object
13 14 15 |
# File 'lib/mj/git/remote_branch.rb', line 13 def checkout_command "git checkout -b #{local_branch_name} #{name}" end |
#delete ⇒ Object
62 63 64 |
# File 'lib/mj/git/remote_branch.rb', line 62 def delete @command_executer.execute("git push origin :#{local_branch_name}") end |
#has_pr? ⇒ Boolean
37 38 39 |
# File 'lib/mj/git/remote_branch.rb', line 37 def has_pr? !pr.nil? end |
#last_commit_date ⇒ Object
17 18 19 |
# File 'lib/mj/git/remote_branch.rb', line 17 def last_commit_date @last_commit_date ||= DateTime.parse(@command_executer.execute("git log -1 --format=%cd #{name}").first) end |
#last_commiter_email ⇒ Object
25 26 27 |
# File 'lib/mj/git/remote_branch.rb', line 25 def last_commiter_email @last_commiter_email ||= @command_executer.execute("git log -1 --pretty=format:'%ae' #{name}").first end |
#last_commiter_name ⇒ Object
21 22 23 |
# File 'lib/mj/git/remote_branch.rb', line 21 def last_commiter_name @last_commiter_name ||= @command_executer.execute("git log -1 --pretty=format:'%an' #{name}").first end |
#length ⇒ Object
29 30 31 |
# File 'lib/mj/git/remote_branch.rb', line 29 def length @name.length end |
#pr ⇒ Git::PullRequest
54 55 56 57 58 59 60 |
# File 'lib/mj/git/remote_branch.rb', line 54 def pr if defined?(@pr) return @pr end @pr ||= fetch_pr end |
#summary ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mj/git/remote_branch.rb', line 41 def summary parts = [] parts << "Last Commited by #{last_commiter_name} (#{last_commiter_email}) on #{last_commit_date.strftime("%Y-%m-%d")}" if @pr parts << "PR ##{pr.number} by #{pr..login}" end parts.join(", ") end |
#to_local ⇒ Object
33 34 35 |
# File 'lib/mj/git/remote_branch.rb', line 33 def to_local LocalBranch.new(local_branch_name) end |