Class: Neetob::CLI::FetchorupdateRepos::Execute

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/fetchorupdate_repos/execute.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(sandbox = false, repos = ["*"]) ⇒ Execute

Returns a new instance of Execute.



11
12
13
14
15
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 11

def initialize(sandbox = false, repos = ["*"])
  super()
  @sandbox = sandbox
  @repos = repos
end

Instance Attribute Details

#reposObject

Returns the value of attribute repos.



9
10
11
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 9

def repos
  @repos
end

#sandboxObject

Returns the value of attribute sandbox.



9
10
11
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 9

def sandbox
  @sandbox
end

Instance Method Details

#checkout_to_main_and_fetch_commits(repo_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 34

def checkout_to_main_and_fetch_commits(repo_name)
  %x[ cd #{repo_name} && git checkout main && git pull origin main ]
  if $?.success?
    puts "------Successfully pulled main branch of #{repo_name}------"
  else
    puts "------Unable to pull the main branch of #{repo_name} due to conflicts------"
  end
end

#clone_repo(repo_name) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 43

def clone_repo(repo_name)
  `git clone [email protected]:bigbinary/#{repo_name}.git`
  if $?.success?
    puts "------Done cloning #{repo_name}------"
  else
    puts "------Failed cloning #{repo_name}------"
  end
end

#directory_exists(repo_name) ⇒ Object



30
31
32
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 30

def directory_exists(repo_name)
  File.directory?(repo_name)
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/neetob/cli/fetchorupdate_repos/execute.rb', line 17

def run
  neeto_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
  neeto_repos.each do |repo|
    repo_name = repo.split("/").last
    ui.info("\nWorking on #{repo_name}\n")
    if directory_exists(repo_name)
      checkout_to_main_and_fetch_commits(repo_name)
    else
      clone_repo(repo_name)
    end
  end
end