Class: TeachersPet::Actions::CloneRepos

Inherits:
Base
  • Object
show all
Defined in:
lib/teachers_pet/actions/clone_repos.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #options

Instance Method Summary collapse

Methods inherited from Base

#execute, #init_client, #initialize, #octokit_config, #read_file, #read_members_file, #read_students_file

Constructor Details

This class inherits a constructor from TeachersPet::Actions::Base

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/teachers_pet/actions/clone_repos.rb', line 17

def create
  cloneMethod = self.get_clone_method

  # create a repo for each student
  self.init_client

  org_hash = self.client.organization(@organization)
  abort('Organization could not be found') if org_hash.nil?
  puts "Found organization at: #{org_hash[:url]}"

  # Load the teams - there should be one team per student.
  org_teams = self.client.get_teams_by_name(@organization)
  # For each student - pull the repository if it exists
  puts "\nCloning assignment repositories for students..."
  @students.keys.each do |student|
    unless org_teams.key?(student)
      puts("  ** ERROR ** - no team for #{student}")
      next
    end
    repo_name = "#{student}-#{@repository}"

    unless self.client.repository?(@organization, repo_name)
      puts " ** ERROR ** - Can't find expected repository '#{repo_name}'"
      next
    end

    web = self.options[:web]
    sshEndpoint = web.gsub("https://","git@").gsub("/",":")
    command = "git clone #{sshEndpoint}#{@organization}/#{repo_name}.git"
    if cloneMethod.eql?('https')
      command = "git clone #{web}#{@organization}/#{repo_name}.git"
    end
    puts " --> Cloning: '#{command}'"
    self.execute(command)
  end
end

#get_clone_methodObject



13
14
15
# File 'lib/teachers_pet/actions/clone_repos.rb', line 13

def get_clone_method
  self.options[:clone_method]
end

#load_filesObject



9
10
11
# File 'lib/teachers_pet/actions/clone_repos.rb', line 9

def load_files
  @students = self.read_students_file
end

#read_infoObject



4
5
6
7
# File 'lib/teachers_pet/actions/clone_repos.rb', line 4

def read_info
  @repository = self.options[:repository]
  @organization = self.options[:organization]
end

#runObject



54
55
56
57
58
# File 'lib/teachers_pet/actions/clone_repos.rb', line 54

def run
  self.read_info
  self.load_files
  self.create
end