Skip to content

Commit f06a74c

Browse files
committed
adding a download for all homework repos
1 parent 02870eb commit f06a74c

2 files changed

Lines changed: 105 additions & 6 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
*
3+
*/
4+
package edu.wpi.rbe;
5+
6+
import java.io.File;
7+
import java.lang.reflect.Type;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.HashSet;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
import org.apache.commons.io.FileUtils;
15+
import org.kohsuke.github.GHOrganization;
16+
import org.kohsuke.github.GHRepository;
17+
import org.kohsuke.github.GHTeam;
18+
import org.kohsuke.github.GHUser;
19+
import org.kohsuke.github.GitHub;
20+
import org.kohsuke.github.PagedIterable;
21+
import org.kohsuke.github.GHTeam.Role;
22+
23+
import com.google.gson.Gson;
24+
import com.google.gson.GsonBuilder;
25+
import com.google.gson.reflect.TypeToken;
26+
27+
/**
28+
* @author hephaestus
29+
*
30+
*/
31+
public class DownloadAllHomeworkRepos {
32+
33+
/**
34+
* @param args
35+
*/
36+
public static void main(String[] args) throws Exception {
37+
String teamAssignmentsFile = args[0];
38+
int numberOfTeams = 0;
39+
40+
Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
41+
Type collectionType = new TypeToken<HashMap<String, ArrayList<String>>>() {
42+
}.getType();
43+
String json = FileUtils.readFileToString(new File(teamAssignmentsFile));
44+
HashMap<String, ArrayList<String>> teamAssignments = gson.fromJson(json, collectionType);
45+
String projectDestBaseName = teamAssignments.get("projectName").get(0);
46+
ArrayList<String> repoDestBaseNames = teamAssignments.get("repoDestBaseNames");
47+
numberOfTeams = Integer.parseInt(teamAssignments.get("numberOfTeams").get(0));
48+
49+
GitHub github = GitHub.connect();
50+
GHOrganization dest = github.getMyOrganizations().get(projectDestBaseName);
51+
52+
if (dest == null) {
53+
System.out.println("FAIL, you do not have access to " + projectDestBaseName);
54+
return;
55+
}
56+
System.out.println("Found " + projectDestBaseName);
57+
58+
Map<String, GHTeam> teams = dest.getTeams();
59+
PagedIterable<GHUser> teachingStaff = teams.get("TeachingStaff").listMembers();
60+
for (GHUser t : teachingStaff) {
61+
System.out.println("Teacher: " + t.getLogin());
62+
}
63+
Map<String, GHRepository> allRepos = dest.getRepositories();
64+
// String repoDestBaseName = repoDestBaseNames.get(x);
65+
for (String key : allRepos.keySet()) {
66+
if (key.startsWith("HomeworkCode")) {
67+
String repoFullName = key;
68+
File tmp = new File(System.getProperty("java.io.tmpdir") + "/gittmp/");
69+
if (!tmp.exists()) {
70+
tmp.mkdirs();
71+
}
72+
tmp.deleteOnExit();
73+
String cloneDirString = tmp.getAbsolutePath() + "/";
74+
File cloneDir = new File(cloneDirString);
75+
File myDir = new File(cloneDirString + repoFullName);
76+
if (!myDir.exists()) {
77+
System.out.println("Cloning " + repoFullName + " to " + cloneDirString);
78+
List<String> commands = new ArrayList<String>();
79+
commands.add("git"); // command
80+
commands.add("clone"); // command
81+
commands.add("git@github.com:" + projectDestBaseName + "/" + repoFullName + ".git"); // command
82+
LabCodeRepoSetupMain.run(commands, cloneDir);
83+
myDir = new File(cloneDirString + repoFullName);
84+
} else {
85+
System.out.println(myDir.getName() + " exists");
86+
List<String> commands = new ArrayList<String>();
87+
commands = new ArrayList<String>();
88+
commands.add("git"); // command
89+
commands.add("pull"); // command
90+
commands.add("origin"); // command
91+
commands.add("master"); // command
92+
LabCodeRepoSetupMain.run(commands, myDir);
93+
}
94+
}
95+
}
96+
97+
}
98+
99+
}

LabCodeRepoSetup/src/main/java/edu/wpi/rbe/LabCodeRepoSetupMain.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public static void main(String[] args) throws Exception {
8989
if (teamNum > 0) {
9090
try {
9191
String username = fields.get(3);
92-
System.out.println("\t"+username);
92+
System.out.println("\t" + username);
9393
team.add(username);
94-
}catch(Exception e) {
94+
} catch (Exception e) {
9595
break;// end of the list
9696
}
97-
97+
9898
}
9999
}
100100

@@ -354,15 +354,15 @@ public static void run(List<String> commands, File dir) throws Exception {
354354

355355
String s = null;
356356
String e = null;
357-
while ((s = stdInput.readLine()) != null||
358-
(e = errInput.readLine()) != null) {
357+
while ((s = stdInput.readLine()) != null || (e = errInput.readLine()) != null) {
359358
if (s != null)
360359
System.out.println(s);
361360
if (e != null)
362361
System.err.println(e);
363362
Thread.sleep(100);
364363
}
365-
while (process.isAlive()) ;
364+
while (process.isAlive())
365+
;
366366
}
367367

368368
public static GHRepository createRepository(GHOrganization dest, String repoName, String description)

0 commit comments

Comments
 (0)