Class: LearnSubmit::Submission::GitInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_submit/submission/git_interactor.rb

Constant Summary collapse

LEARN_ORG_NAMES =
[
  'learn-co-curriculum',
  'learn-co-students'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, message:) ⇒ GitInteractor

Returns a new instance of GitInteractor.



12
13
14
15
16
# File 'lib/learn_submit/submission/git_interactor.rb', line 12

def initialize(username:, message:)
  @username = username
  @message  = message || 'Done.'
  @git      = set_git
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



4
5
6
# File 'lib/learn_submit/submission/git_interactor.rb', line 4

def git
  @git
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/learn_submit/submission/git_interactor.rb', line 4

def message
  @message
end

#old_remote_nameObject

Returns the value of attribute old_remote_name.



5
6
7
# File 'lib/learn_submit/submission/git_interactor.rb', line 5

def old_remote_name
  @old_remote_name
end

#old_urlObject

Returns the value of attribute old_url.



5
6
7
# File 'lib/learn_submit/submission/git_interactor.rb', line 5

def old_url
  @old_url
end

#remote_nameObject

Returns the value of attribute remote_name.



5
6
7
# File 'lib/learn_submit/submission/git_interactor.rb', line 5

def remote_name
  @remote_name
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/learn_submit/submission/git_interactor.rb', line 4

def username
  @username
end

Instance Method Details

#branch_nameObject



31
32
33
# File 'lib/learn_submit/submission/git_interactor.rb', line 31

def branch_name
  git.branch.name
end

#commit_and_pushObject



18
19
20
21
22
23
24
# File 'lib/learn_submit/submission/git_interactor.rb', line 18

def commit_and_push
  check_remote
  add_changes
  commit_changes

  push!
end

#repo_nameObject



26
27
28
29
# File 'lib/learn_submit/submission/git_interactor.rb', line 26

def repo_name
  url = git.remote(remote_name).url
  url.match(/^.+\w+\/(.*?)(?:\.git)?$/)[1]
end