99import java .io .InputStreamReader ;
1010import java .lang .reflect .Type ;
1111import java .util .ArrayList ;
12+ import java .util .Arrays ;
1213import java .util .Collection ;
1314import java .util .HashMap ;
1415import java .util .HashSet ;
@@ -50,12 +51,57 @@ public static void main(String[] args) throws Exception {
5051 }.getType ();
5152 String json = FileUtils .readFileToString (new File (teamAssignmentsFile ));
5253 HashMap <String , ArrayList <String >> teamAssignments = gson .fromJson (json , collectionType );
53-
5454 String projectDestBaseName = teamAssignments .get ("projectName" ).get (0 );
5555 ArrayList <String > repoDestBaseNames = teamAssignments .get ("repoDestBaseNames" );
5656 String teamDestBaseName = teamAssignments .get ("teamDestBaseName" ).get (0 );
5757 numberOfTeams = Integer .parseInt (teamAssignments .get ("numberOfTeams" ).get (0 ));
5858
59+ if (args .length == 2 ) {
60+ String csvFileName = args [1 ];
61+ if (csvFileName .toLowerCase ().endsWith (".csv" )) {
62+ File csv = new File (csvFileName );
63+ String csvData = FileUtils .readFileToString (csv );
64+ if (csv .exists ()) {
65+ String lines [] = csvData .split ("\\ r?\\ n" );
66+ int teamNum = 0 ;
67+ ArrayList <String > team = new ArrayList <>();
68+ for (String line : lines ) {
69+ List <String > fields = Arrays .asList (line .split ("," ));
70+ int lastTeamNum = teamNum ;
71+ try {
72+
73+ teamNum = Integer .parseInt (fields .get (5 ));
74+
75+ } catch (Exception ex ) {
76+ // System.out.println(fields);
77+
78+ // ex.printStackTrace();
79+ }
80+
81+ if (teamNum > 0 && teamNum != lastTeamNum ) {
82+ if (lastTeamNum == numberOfTeams )
83+ break ;
84+ System .out .println ("Team # " + teamNum );
85+ team = new ArrayList <>();
86+ String teamString = teamNum > 9 ? "" + teamNum : "0" + teamNum ;
87+ teamAssignments .put (teamString , team );
88+ }
89+ if (teamNum > 0 ) {
90+ try {
91+ String username = fields .get (3 );
92+ System .out .println ("\t " +username );
93+ team .add (username );
94+ }catch (Exception e ) {
95+ break ;// end of the list
96+ }
97+
98+ }
99+ }
100+
101+ }
102+ }
103+ }
104+
59105 GitHub github = GitHub .connect ();
60106 GHOrganization dest = github .getMyOrganizations ().get (projectDestBaseName );
61107
@@ -80,8 +126,7 @@ public static void main(String[] args) throws Exception {
80126 for (GHUser c : currentMembers ) {
81127 boolean isTeach = false ;
82128 for (GHUser t : teachingStaff ) {
83- if (t .getLogin ().contains (c .getLogin ())||
84- t .getLogin ().contains ("madhephaestus" )) {
129+ if (t .getLogin ().contains (c .getLogin ()) || t .getLogin ().contains ("madhephaestus" )) {
85130 isTeach = true ;
86131 break ;
87132 }
@@ -123,7 +168,7 @@ public static void main(String[] args) throws Exception {
123168 tmp .mkdirs ();
124169 }
125170 tmp .deleteOnExit ();
126- cloneDirString = tmp .getAbsolutePath () + "/" + sourceRepo ;
171+ cloneDirString = tmp .getAbsolutePath () + "/" + sourceRepo ;
127172 cloneDir = new File (cloneDirString );
128173 if (cloneDir .exists ()) {
129174 System .out .println (cloneDir .getAbsolutePath () + " Exists" );
@@ -172,27 +217,27 @@ public static void main(String[] args) throws Exception {
172217 System .out .println ("Team Found: " + team .getName ());
173218 for (String member : members ) {
174219 try {
175- GHUser memberGH = github .getUser (member );
176- if (memberGH == null ) {
177- System .out .println ("ERROR GitHub user " + member + " does not exist" );
178- continue ;
179- }
180- if (!team .hasMember (memberGH )) {
181- try {
182- team .add (memberGH , Role .MAINTAINER );
183- System .out .println ("Adding " + member + " to " + team .getName ());
184- } catch (Exception e ) {
185- System .out .println ("Inviting " + member + " to " + team .getName ());
220+ GHUser memberGH = github .getUser (member );
221+ if (memberGH == null ) {
222+ System .out .println ("ERROR GitHub user " + member + " does not exist" );
223+ continue ;
224+ }
225+ if (!team .hasMember (memberGH )) {
226+ try {
227+ team .add (memberGH , Role .MAINTAINER );
228+ System .out .println ("Adding " + member + " to " + team .getName ());
229+ } catch (Exception e ) {
230+ System .out .println ("Inviting " + member + " to " + team .getName ());
186231
232+ }
187233 }
188- }
189-
190- allStudents .add (memberGH );
191- }catch (Exception ex ) {
192- System .err .println ("\r \n \r \n ERROR " +member +" is not a valid GitHub username\r \n \r \n " );
234+
235+ allStudents .add (memberGH );
236+ } catch (Exception ex ) {
237+ System .err .println ("\r \n \r \n ERROR " + member + " is not a valid GitHub username\r \n \r \n " );
193238 }
194239 }
195-
240+
196241 for (GHUser t : teachingStaff ) {
197242 if (!t .getLogin ().contains ("madhephaestus" ))
198243 team .add (t , Role .MAINTAINER );
@@ -256,7 +301,7 @@ public static void main(String[] args) throws Exception {
256301 if (deleteAll )
257302 for (GHTeam t : allTeams ) {
258303 if (t .getName ().startsWith ("HomeworkTeam" )) {
259- System .out .println ("Deleting team " + t .getName ());
304+ System .out .println ("Deleting team " + t .getName ());
260305 t .delete ();
261306 }
262307 }
@@ -268,17 +313,17 @@ public static void main(String[] args) throws Exception {
268313 GHRepository repositorie = dest .getRepository (hwRepoName );
269314 if (repositorie == null ) {
270315 repositorie = createRepository (dest , hwRepoName , "Homework for " + u .getLogin ());
271- System .out .println ("Creating Student Homework team " + hwRepoName );
316+ System .out .println ("Creating Student Homework team " + hwRepoName );
272317 }
273318 GHTeam myTeam = existingTeams .get (hwTeam );
274319 if (myTeam == null ) {
275320 myTeam = dest .createTeam (hwTeam , GHOrganization .Permission .ADMIN , repositorie );
276-
321+
277322 }
278323 try {
279324 myTeam .add (u , Role .MAINTAINER );
280- }catch (Exception ex ) {
281- System .out .println ("Inviting " + u .getLogin ()+ " to " + hwTeam );
325+ } catch (Exception ex ) {
326+ System .out .println ("Inviting " + u .getLogin () + " to " + hwTeam );
282327 }
283328 myTeam .add (repositorie , GHOrganization .Permission .ADMIN );
284329 for (GHUser t : teachingStaff ) {
0 commit comments