1- /**
2- *
3- */
4- package edu .wpi .rbe ;
1+ @ Grab (group ='org.kohsuke' , module ='github-api' , version ='1.94' )
52
63import java .io .BufferedReader ;
74import java .io .File ;
1714import java .util .Map ;
1815
1916import org .apache .commons .io .FileUtils ;
17+ import org .kohsuke .github .GHOrganization ;
18+ import org .kohsuke .github .GHTeam .Role ;
19+ /*
2020import org.kohsuke.github.GHCreateRepositoryBuilder;
2121import org.kohsuke.github.GHOrganization;
2222import org.kohsuke.github.GHRepository;
2525import org.kohsuke.github.GHUser;
2626import org.kohsuke.github.GitHub;
2727import org.kohsuke.github.PagedIterable;
28-
28+ */
2929import com .google .gson .Gson ;
3030import com .google .gson .GsonBuilder ;
3131import com .google .gson .reflect .TypeToken ;
3232
33+ import com .neuronrobotics .nrconsole .util .FileSelectionFactory ;
34+ import javafx .stage .FileChooser .ExtensionFilter ;
35+
36+ File servo = ScriptingEngine
37+ .fileFromGit (
38+ "https://github.com/WPIRoboticsEngineering/LabCodeRepoSetup.git" ,//git repo URL
39+ "master" ,//branch
40+ "LabCodeRepoSetup/teamAssignments3001.json" // File from within the Git repo
41+ );
42+
43+ def path = FileSelectionFactory .GetFile (
44+ servo
45+ ,new ExtensionFilter ("json file" ,"*.JSON" ,"*.json" )
46+ )
47+ .getAbsolutePath ()
48+
49+ println path
50+
51+ String [] arg = [path ]as String []
52+
53+ LabCodeRepoSetup .main (arg )
54+
55+
56+
3357/**
3458 * @author hephaestus
3559 *
3660 */
37- public class LabCodeRepoSetupMain {
61+ class LabCodeRepoSetup {
3862
3963 /**
4064 * @param args
4165 * @throws IOException
4266 * @throws InterruptedException
4367 */
44- public static void main (String [] args ) throws Exception {
45- HashSet < GHUser > allStudents = new HashSet <>();
46- String teamAssignmentsFile = args [0 ];
68+ public static void main (def argsMine ) throws Exception {
69+ def allStudents = new HashSet <>();
70+ String teamAssignmentsFile = argsMine [0 ];
4771 int numberOfTeams = 0 ;
4872
4973 Gson gson = new GsonBuilder ().disableHtmlEscaping ().setPrettyPrinting ().create ();
5074 Type collectionType = new TypeToken <HashMap <String , ArrayList <String >>>() {
5175 }.getType ();
52- String json = FileUtils .readFileToString (new File (teamAssignmentsFile ));
76+ File fileOfStuff = new File (teamAssignmentsFile )
77+ println fileOfStuff
78+ String json = fileOfStuff .text
5379 HashMap <String , ArrayList <String >> teamAssignments = gson .fromJson (json , collectionType );
5480 String projectDestBaseName = teamAssignments .get ("projectName" ).get (0 );
5581 ArrayList <String > repoDestBaseNames = teamAssignments .get ("repoDestBaseNames" );
@@ -60,13 +86,13 @@ public static void main(String[] args) throws Exception {
6086 useHW = Boolean .parseBoolean (teamAssignments .get ("homework" ).get (0 ));
6187 } catch (Throwable t ) {
6288 }
63- if (args .length == 2 ) {
64- String csvFileName = args [1 ];
89+ if (argsMine .length == 2 ) {
90+ String csvFileName = argsMine [1 ];
6591 if (csvFileName .toLowerCase ().endsWith (".csv" )) {
6692 File csv = new File (csvFileName );
6793 String csvData = FileUtils .readFileToString (csv );
6894 if (csv .exists ()) {
69- String lines [] = csvData .split ("\\ r?\\ n" );
95+ String [] lines = csvData .split ("\\ r?\\ n" );
7096 int teamNum = 0 ;
7197 ArrayList <String > team = new ArrayList <>();
7298 for (String line : lines ) {
@@ -106,32 +132,32 @@ public static void main(String[] args) throws Exception {
106132 }
107133 }
108134
109- GitHub github = GitHub . connect ();
110- GHOrganization dest = github .getMyOrganizations ().get (projectDestBaseName );
135+ def github = PasswordManager . getGithub ();
136+ def dest = github .getMyOrganizations ().get (projectDestBaseName );
111137
112138 if (dest == null ) {
113139 System .out .println ("FAIL, you do not have access to " + projectDestBaseName );
114140 return ;
115141 }
116142 System .out .println ("Found " + projectDestBaseName );
117143
118- Map < String , GHTeam > teams = dest .getTeams ();
119- GHTeam teachTeam = teams .get ("TeachingStaff" );
120- PagedIterable < GHUser > ts = teachTeam .listMembers ();
144+ def teams = dest .getTeams ();
145+ def teachTeam = teams .get ("TeachingStaff" );
146+ def ts = teachTeam .listMembers ();
121147
122- for (GHUser t : ts ) {
148+ for (def t : ts ) {
123149 System .out .println ("Teacher: " + t .getLogin ());
124150 }
125151 boolean deleteAll = false ;
126152 try {
127153 deleteAll = Boolean .parseBoolean (teamAssignments .get ("deleteall" ).get (0 ));
128154 } catch (Exception e ) {
129155 }
130- ArrayList < GHUser > toRemove = new ArrayList <>();
131- PagedIterable < GHUser > currentMembers = dest .listMembers ();
132- for (GHUser c : currentMembers ) {
156+ def toRemove = new ArrayList <>();
157+ def currentMembers = dest .listMembers ();
158+ for (def c : currentMembers ) {
133159 boolean isTeach = false ;
134- for (GHUser t : teachTeam .listMembers ()) {
160+ for (def t : teachTeam .listMembers ()) {
135161 if (t .getLogin ().contains (c .getLogin ()) || t .getLogin ().contains ("madhephaestus" )) {
136162 isTeach = true ;
137163 break ;
@@ -141,16 +167,16 @@ public static void main(String[] args) throws Exception {
141167 toRemove .add (c );
142168 }
143169 }
144- for (GHUser f : toRemove ) {
170+ for (def f : toRemove ) {
145171 System .out .println ("Removing " + f .getLogin () + " from " + dest .getName ());
146172 dest .remove (f );
147173 }
148174 for (int x = 0 ; x < repoDestBaseNames .size (); x ++) {
149175 String repoDestBaseName = repoDestBaseNames .get (x );
150176 if (deleteAll ) {
151177 System .out .println ("Deleteall flag in json file set, hosing all repos" );
152- PagedIterable < GHRepository > repos = dest .listRepositories ();
153- for (GHRepository R : repos ) {
178+ def repos = dest .listRepositories ();
179+ for (def R : repos ) {
154180 if (R .getFullName ().contains (repoDestBaseName ) || R .getFullName ().contains ("HomeworkCode" )) {
155181 System .out .println ("Deleting stale Repo " + R .getFullName ());
156182 R .delete ();
@@ -166,7 +192,7 @@ public static void main(String[] args) throws Exception {
166192
167193 for (int i = 1 ; i <= numberOfTeams ; i ++) {
168194 String teamString = i > 9 ? "" + i : "0" + i ;
169- GHTeam team = teams .get (teamDestBaseName + teamString );
195+ def team = teams .get (teamDestBaseName + teamString );
170196
171197 if (team == null ) {
172198 System .out .println ("ERROR: no such team " + teamDestBaseName + teamString );
@@ -178,12 +204,12 @@ public static void main(String[] args) throws Exception {
178204 continue ;
179205 }
180206 System .out .println ("Team Found: " + team .getName ());
181- for (GHUser existing : team .getMembers ()) {
207+ for (def existing : team .getMembers ()) {
182208 team .remove (existing );
183209 }
184210 for (String member : members ) {
185211 try {
186- GHUser memberGH = github .getUser (member );
212+ def memberGH = github .getUser (member );
187213 if (memberGH == null ) {
188214 System .out .println ("ERROR GitHub user " + member + " does not exist" );
189215 continue ;
@@ -207,7 +233,7 @@ public static void main(String[] args) throws Exception {
207233 if (team .hasMember (github .getUser ("madhephaestus" )))
208234 team .remove (github .getUser ("madhephaestus" ));// FFS i dont want all these notifications...
209235 String repoFullName = repoDestBaseName + teamString ;
210- GHRepository myTeamRepo = dest .getRepository (repoFullName );
236+ def myTeamRepo = dest .getRepository (repoFullName );
211237
212238 if (myTeamRepo == null ) {
213239 System .out .println ("Missing Repo, creating " + repoFullName );
@@ -366,26 +392,26 @@ public static void main(String[] args) throws Exception {
366392 }
367393
368394 System .out .println ("All Students " + allStudents .size ());
369- PagedIterable < GHTeam > allTeams = dest .listTeams ();
395+ def allTeams = dest .listTeams ();
370396 if (deleteAll )
371- for (GHTeam t : allTeams ) {
397+ for (def t : allTeams ) {
372398 if (t .getName ().startsWith ("HomeworkTeam" )) {
373399 System .out .println ("Deleting team " + t .getName ());
374400 t .delete ();
375401 }
376402 }
377403 if (useHW ) {
378- Map < String , GHTeam > existingTeams = dest .getTeams ();
379- for (GHUser u : allStudents ) {
404+ def existingTeams = dest .getTeams ();
405+ for (def u : allStudents ) {
380406 String hwTeam = "HomeworkTeam-" + u .getLogin ();
381407 String hwRepoName = "HomeworkCode-" + u .getLogin ();
382408
383- GHRepository repositorie = dest .getRepository (hwRepoName );
409+ def repositorie = dest .getRepository (hwRepoName );
384410 if (repositorie == null ) {
385411 System .out .println ("Creating Student Homework team " + hwRepoName );
386412 repositorie = createRepository (dest , hwRepoName , "Homework for " + u .getLogin ());
387413 }
388- GHTeam myTeam = existingTeams .get (hwTeam );
414+ def myTeam = existingTeams .get (hwTeam );
389415 if (myTeam == null ) {
390416 myTeam = dest .createTeam (hwTeam , GHOrganization .Permission .ADMIN , repositorie );
391417
@@ -434,9 +460,9 @@ public static void run(List<String> commands, File dir) throws Exception {
434460 ;
435461 }
436462
437- public static GHRepository createRepository (GHOrganization dest , String repoName , String description )
463+ public static def createRepository (def dest , String repoName , String description )
438464 throws IOException {
439- GHCreateRepositoryBuilder builder ;
465+ def builder ;
440466
441467 builder = dest .createRepository (repoName );
442468
0 commit comments