use of com.google.startupos.common.repo.GitRepo in project startup-os by google.
the class SnapshotCommand method revertChanges.
private void revertChanges(Map<String, String> repoToInitialBranch) {
if (!repoToInitialBranch.isEmpty()) {
repoToInitialBranch.forEach((repoName, initialBranch) -> {
GitRepo repo = gitRepoFactory.create(fileUtils.joinToAbsolutePath(workspacePath, repoName));
String currentBranch = repo.currentBranch();
if (!currentBranch.equals(initialBranch)) {
repo.switchBranch(initialBranch);
}
});
}
}
use of com.google.startupos.common.repo.GitRepo in project startup-os by google.
the class GithubSyncTool method main.
public static void main(String[] args) throws IOException {
Flags.parseCurrentPackage(args);
GitRepoFactory gitRepoFactory = DaggerGithubSyncTool_GitubSyncToolComponent.builder().build().getGitRepoFactory();
ImmutableMap<String, GitRepo> repoNameToGitRepos = getGitReposMap(repoPaths.get(), gitRepoFactory);
GithubClient githubClient = new GithubClient(login.get(), password.get());
GithubSync githubSync = new GithubSync(githubClient, reviewerDiffLink.get());
githubSync.syncWithGithub(diffNumber.get(), repoNameToGitRepos);
}
use of com.google.startupos.common.repo.GitRepo in project startup-os by google.
the class ReviewerMetadataUpdaterTask method run.
@Override
public void run() {
if (lock.tryLock()) {
try {
GitRepo repo = gitRepoFactory.create(REPO_DIRECTORY);
if (fileUtils.folderEmptyOrNotExists(REPO_DIRECTORY)) {
repo.cloneRepo(repoUrl.get(), REPO_DIRECTORY);
} else {
repo.pull();
}
String globalRegistryFilePath = fileUtils.joinToAbsolutePath(REPO_DIRECTORY, GLOBAL_REGISTRY_FILE);
String newChecksum = md5ForFile(globalRegistryFilePath);
ReviewerRegistry registry = (ReviewerRegistry) fileUtils.readPrototxtUnchecked(globalRegistryFilePath, ReviewerRegistry.newBuilder());
if (!newChecksum.equals(registryChecksum)) {
if (firstRun) {
log.atInfo().log("Storing on first run, checksum: %s", newChecksum);
} else {
log.atInfo().log("New checksum not equal to stored one: new %s, stored %s", newChecksum, registryChecksum);
}
uploadReviewerRegistryToFirestore(registry);
registryChecksum = newChecksum;
} else {
log.atInfo().log("Checksum equals to stored one: %s,", registryChecksum);
}
String repoRegistryFilePath = fileUtils.joinToAbsolutePath(REPO_DIRECTORY, REPO_REGISTRY_FILE);
String newConfigChecksum = md5ForFile(repoRegistryFilePath);
ReviewerConfig config = (ReviewerConfig) fileUtils.readPrototxtUnchecked(repoRegistryFilePath, ReviewerConfig.newBuilder());
if (!newConfigChecksum.equals(configChecksum)) {
if (firstRun) {
log.atInfo().log("Storing in first run, configChecksum: %s", newConfigChecksum);
} else {
log.atInfo().log("New configChecksum not equal to stored one: new %s, stored %s", newConfigChecksum, configChecksum);
}
uploadReviewerConfigToFirestore(config);
configChecksum = newConfigChecksum;
} else {
log.atInfo().log("New ConfigChecksum is equal to stored one: %s,", configChecksum);
}
firstRun = false;
} catch (IOException exception) {
exception.printStackTrace();
} finally {
lock.unlock();
}
}
}
use of com.google.startupos.common.repo.GitRepo in project startup-os by google.
the class DiffCommand method createDiff.
private Diff createDiff() {
DiffNumberResponse response = codeReviewBlockingStub.getAvailableDiffNumber(Empty.getDefaultInstance());
String branchName = String.format("D%s", response.getLastDiffId());
System.out.println("Creating " + branchName);
Long currentTime = new Long(System.currentTimeMillis());
Diff.Builder diffBuilder = Diff.newBuilder().setWorkspace(workspaceName).setDescription(description.get()).addAllIssue(getIssues(buglink.get())).addAllReviewer(getReviewers(reviewers.get())).setId(response.getLastDiffId()).setCreatedTimestamp(currentTime).setModifiedTimestamp(currentTime);
Map<GitRepo, String> repoToInitialBranch = new HashMap<>();
try {
fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
String repoName = Paths.get(path).getFileName().toString();
GitRepo repo = this.gitRepoFactory.create(path);
repoToInitialBranch.put(repo, repo.currentBranch());
System.out.println(String.format("[%s/%s]: switching to diff branch", workspaceName, repoName));
repo.switchBranch(branchName);
});
addGithubRepos(diffBuilder);
} catch (Exception e) {
repoToInitialBranch.forEach((repo, initialBranch) -> {
if (!repo.currentBranch().equals(initialBranch)) {
repo.switchBranch(initialBranch);
}
});
e.printStackTrace();
}
return diffBuilder.build();
}
use of com.google.startupos.common.repo.GitRepo in project startup-os by google.
the class DiffCommand method addGithubRepos.
private void addGithubRepos(Diff.Builder diffBuilder) {
List<String> existingGithubRepoNames = diffBuilder.getGithubPrList().stream().map(GithubPr::getRepo).collect(Collectors.toList());
try {
fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
GitRepo repo = this.gitRepoFactory.create(path);
if (repo.hasChanges(repo.currentBranch())) {
// Example of repoUrl: https://github.com/google/startup-os.git
String repoUrl = repo.getRemoteUrl();
String repoOwner = repoUrl.split("/")[3];
String repoName = repoUrl.split("/")[4].replace(".git", "").trim();
String folderName = Paths.get(path).getFileName().toString();
if (!repoName.equals(folderName)) {
System.out.println(String.format("Repository name from the URL(%s) and folder " + "name from workspace(%s) aren't the same.", repoName, folderName));
}
if (!existingGithubRepoNames.contains(repoName)) {
diffBuilder.addGithubPr(GithubPr.newBuilder().setRepo(repoName).setOwner(repoOwner).build());
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations