Class: TeachersPet::Actions::CreateStudentTeams

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

#create_student_teamsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/teachers_pet/actions/create_student_teams.rb', line 4

def create_student_teams
   = self.options[:organization]
  teams_by_name = self.client.existing_teams_by_name()

  students_list = self.read_students_file
  students_list.each do |key, value|
    if value
      # Create one team per group of students
      team_name = key
      usernames = value
    else
      # Create a team with the same name as the student, with that person as the only member
      team_name = key
      usernames = [value]
    end

    team = teams_by_name[team_name]
    if team
      puts "Team @#{}/#{team_name} already exists."
    else
      team = self.client.create_team(, team_name)
    end
    self.client.add_users_to_team(, team, usernames)
  end
end

#runObject



30
31
32
33
# File 'lib/teachers_pet/actions/create_student_teams.rb', line 30

def run
  self.init_client
  self.create_student_teams
end