Class: TeachersPet::Actions::PushFiles

Inherits:
Base
  • Object
show all
Defined in:
lib/teachers_pet/actions/push_files.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

#load_filesObject


10
11
12
# File 'lib/teachers_pet/actions/push_files.rb', line 10

def load_files
  @students = self.read_students_file
end

#pushObject


14
15
16
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
# File 'lib/teachers_pet/actions/push_files.rb', line 14

def push
  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.
  # Repositories are given permissions by teams
  org_teams = self.client.get_teams_by_name(@organization)

  # For each student - if an appropraite repository exists,
  # add it to the list.
  remotes_to_add = Hash.new
  @students.keys.sort.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 ** - no repository called #{repo_name}")
    end
    if TeachersPet::Configuration.remoteSsh
      remotes_to_add[student] = "[email protected]#{@sshEndpoint}:#{@organization}/#{repo_name}.git"
    else
      remotes_to_add[student] = "#{self.web}#{@organization}/#{repo_name}.git"
    end
  end

  puts "Adding remotes and pushing files to student repositories."
  remotes_to_add.keys.each do |remote|
    puts "#{remote} --> #{remotes_to_add[remote]}"
    `git remote add #{remote} #{remotes_to_add[remote]}`
    `git push #{remote} master`
  end
end

#read_infoObject


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

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

#runObject


53
54
55
56
57
# File 'lib/teachers_pet/actions/push_files.rb', line 53

def run
  self.read_info
  self.load_files
  self.push
end