-
Notifications
You must be signed in to change notification settings - Fork 74
students_team
action
#41
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Create a team from all users named in a students file | ||
|
||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..') | ||
|
||
require 'set' | ||
require 'rubygems' | ||
require 'highline/question' | ||
require 'highline/compatibility' | ||
|
||
require 'teachers_pet/actions/base' | ||
|
||
module TeachersPet | ||
module Actions | ||
class StudentsTeam < Base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be more explicit, I'd call this class/file |
||
def read_info | ||
@organization = ask("What is the organization name?") { |q| q.default = TeachersPet::Configuration.organization } | ||
@student_file = self.get_students_file_path | ||
end | ||
|
||
def load_files | ||
@students = read_file(@student_file, 'Students') | ||
end | ||
|
||
def update_team | ||
self.init_client | ||
|
||
all_team_name='Students' | ||
confirm("Add #{@students.size} members to '#{all_team_name}' team?") | ||
|
||
# Get current members of org team | ||
existing = Hash.new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not actually used... |
||
teams = self.get_teams_by_name(@organization) | ||
studentsteam = teams[all_team_name] || false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this line to student_team_hash = teams[all_team_name] Since |
||
unless studentsteam | ||
puts "\nCreating team #{all_team_name}..." | ||
@client.create_team(@organization, | ||
{ | ||
:name => all_team_name, | ||
:permission => 'push' | ||
}) | ||
studentsteam = self.get_teams_by_name(@organizaiton)['Students'] | ||
end | ||
|
||
# Find and add new students to the org team | ||
all_students = Set.new | ||
@students.each do |team, members| | ||
all_students.merge(members) | ||
end | ||
all_team_members = Set.new(self.get_team_member_logins(studentsteam[:id])) | ||
new_students = all_students - all_team_members | ||
old_students = all_team_members - all_students | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking we could make these variable names more clear, e.g. |
||
|
||
puts "\nMembers of '#{studentsteam[:name]}':" | ||
all_team_members.each do |member| | ||
puts " -> #{member}" | ||
end | ||
puts "\nAdding members:" | ||
new_students.each do |student| | ||
@client.add_team_member(studentsteam[:id], student) | ||
puts " -> #{student}" | ||
end | ||
puts "\nMembers not mentioned:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe rephrasing to something like "Existing members of the team, who weren't listed in the |
||
old_students.each do |student| | ||
puts " -> #{student}" | ||
end | ||
|
||
puts "\n#{all_team_members.length} previous members in '#{studentsteam[:name]}'." | ||
puts "#{new_students.length} members added." | ||
puts "#{(all_students - new_students).length} skipped." | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we break this method down into smaller pieces? |
||
|
||
def run | ||
self.read_info | ||
self.load_files | ||
self.update_team | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: mind moving this comment one line up, above the method definition?