Class: GitHubLayer

Inherits:
Object
  • Object
show all
Defined in:
lib/homer/github_layer.rb

Constant Summary collapse

REPO_NAME =
'dotfiles'

Class Method Summary collapse

Class Method Details

.create_repo_if_repo_does_not_exist(directory) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/homer/github_layer.rb', line 17

def create_repo_if_repo_does_not_exist(directory)
  Dir.chdir(directory)
  return if origin_added_as_remote?
  puts "I need your GitHub login to create a '#{REPO_NAME}' repo if it doesn't exist already"
   = ask("Login: ")
  password = ask("Password: ") { |q| q.echo = false } 
  github = Github.new(login: , password: password)
  begin
    github.repos.get(github., REPO_NAME)
  rescue Github::Error::NotFound
    github.repos.create(name: REPO_NAME)
  end
  %x{git init .}
  %x{git remote add origin [email protected]:#{}/#{REPO_NAME}.git}
end

.origin_added_as_remote?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/homer/github_layer.rb', line 33

def origin_added_as_remote?
  remotes = %x{git remote -v}
  return remotes.include?("origin\t")
end

.push(directory) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/homer/github_layer.rb', line 9

def push(directory)
  create_repo_if_repo_does_not_exist(directory)
  %x{git pull origin master}
  %x{git add .}
  %x{git commit -m "Homer push"}
  %x{git push origin master}
end