forked from BancroftRoboDogs/LabCodeRepoSetup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushOutUpdate.groovy
94 lines (78 loc) · 3.09 KB
/
PushOutUpdate.groovy
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.lang.reflect.Type
import org.apache.commons.io.FileUtils
import org.kohsuke.github.GHOrganization
import org.kohsuke.github.GHRepository
import org.kohsuke.github.GitHub
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Repository;
String teamAssignmentsFile = ScriptingEngine.gitScriptRun("https://github.com/WPIRoboticsEngineering/LabCodeRepoSetup.git", "getFile.groovy")
GitHub github = PasswordManager.getGithub();
int numberOfTeams = 0;
Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
Type collectionType = new TypeToken<HashMap<String, ArrayList<String>>>() {
}.getType();
String json = new File(teamAssignmentsFile).text;
HashMap<String, ArrayList<String>> teamAssignments = gson.fromJson(json, collectionType);
String projectDestBaseName = teamAssignments.get("projectName").get(0);
ArrayList<String> repoDestBaseNames = teamAssignments.get("repoDestBaseNames");
numberOfTeams = Integer.parseInt(teamAssignments.get("numberOfTeams").get(0));
GHOrganization dest = github.getMyOrganizations().get(projectDestBaseName);
if (dest == null) {
System.out.println("FAIL, you do not have access to " + projectDestBaseName);
return;
}
System.out.println("Found " + projectDestBaseName);
for (int x = 0; x < repoDestBaseNames.size(); x++) {
String repoDestBaseName = repoDestBaseNames.get(x);
String sourceProj = teamAssignments.get(repoDestBaseName).get(0);
String sourceRepo = teamAssignments.get(repoDestBaseName).get(1);
def URLOfupstream= "https://github.com/" + sourceProj + "/" + sourceRepo + ".git"
for (int i = 1; i <= numberOfTeams; i++) {
try {
String teamString = i > 9 ? "" + i : "0" + i;
String repoFullName = repoDestBaseName + teamString;
def URLOfStudentRepo = "https://github.com/" + projectDestBaseName + "/" + repoFullName + ".git"
GHRepository myTeamRepo = dest.getRepository(repoFullName);
if (myTeamRepo == null) {
println repoFullName+ " doesnt exist"
continue;
}
if(Thread.interrupted())
return;
ScriptingEngine.pull(URLOfStudentRepo)
Repository repoOfStudent=ScriptingEngine.getRepository(URLOfStudentRepo)
Git git = new Git(repoOfStudent);
repoOfStudent.getConfig().setString("remote", "origin", "url", URLOfupstream);
try {
def returnVal= git
.pull()
.setCredentialsProvider(PasswordManager.getCredentialProvider())
.call();
for(def result:returnVal)
println result
}catch(Throwable t) {
t.printStackTrace()
}
repoOfStudent.getConfig().setString("remote", "origin", "url", URLOfStudentRepo);
try {
def returnVal= git
.push()
.setCredentialsProvider(PasswordManager.getCredentialProvider())
.setRemote("origin")
.call()
for(def result:returnVal)
println result
}catch(Throwable t) {
t.printStackTrace()
}
git.close()
} catch (Throwable t) {
t.printStackTrace();
}
}
}