Class: Mj::Git::RemoteBranch

Inherits:
Object
  • Object
show all
Defined in:
lib/mj/git/remote_branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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_commandObject



13
14
15
# File 'lib/mj/git/remote_branch.rb', line 13

def checkout_command
  "git checkout -b #{local_branch_name} #{name}"
end

#deleteObject



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

Returns:

  • (Boolean)


37
38
39
# File 'lib/mj/git/remote_branch.rb', line 37

def has_pr?
  !pr.nil?
end

#last_commit_dateObject



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_emailObject



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_nameObject



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

#lengthObject



29
30
31
# File 'lib/mj/git/remote_branch.rb', line 29

def length
  @name.length
end

#prGit::PullRequest

Returns:



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

#summaryObject



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.author.}"
  end

  parts.join(", ")
end

#to_localObject



33
34
35
# File 'lib/mj/git/remote_branch.rb', line 33

def to_local
  LocalBranch.new(local_branch_name)
end