use of com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig in project startup-os by google.
the class ReviewerMetadataUpdaterTaskTool method main.
public static void main(String[] args) {
Flags.parseCurrentPackage(args);
System.out.println(serviceAccountJson.get());
FirestoreProtoClient client = new FirestoreProtoClient(serviceAccountJson.get());
ReviewerMetadataUpdaterTask reviewerMetadataUpdaterTask = DaggerReviewerMetadataUpdaterTaskTool_ReviewerMetadataUpdaterTaskToolComponent.builder().setFirestoreProtoClient(client).build().getReviewerMetadataUpdaterTask();
try {
ReviewerConfig startupOsReviewerConfig = reviewerMetadataUpdaterTask.getRemoteReviewerConfig(reviewerMetadataUpdaterTask.getRemoteStartupOsReviewerConfigPath());
ReviewerConfig hasadnaReviewerConfig = reviewerMetadataUpdaterTask.getRemoteReviewerConfig(reviewerMetadataUpdaterTask.getRemoteHasadnaReviewerConfigPath());
ReviewerConfig mergedReviewerConfig = reviewerMetadataUpdaterTask.mergeReviewerConfigData(startupOsReviewerConfig, hasadnaReviewerConfig);
System.out.println("Merged ReviewerConfig:\n" + mergedReviewerConfig.toString());
} catch (IOException e) {
System.out.println(e);
}
}
use of com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig 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.tools.reviewer.ReviewerProtos.ReviewerConfig in project startup-os by google.
the class ReviewerMetadataUpdaterTask method mergeReviewerConfigData.
public ReviewerConfig mergeReviewerConfigData(ReviewerConfig reviewerConfig1, ReviewerConfig reviewerConfig2) {
final String displayName = reviewerConfig1.getDisplayName();
LinkedHashSet<Repo> repoList = new LinkedHashSet<>();
repoList.addAll(reviewerConfig1.getRepoList());
repoList.addAll(reviewerConfig2.getRepoList());
LinkedHashSet<Project> projectList = new LinkedHashSet<>();
projectList.addAll(reviewerConfig1.getProjectList());
projectList.addAll(reviewerConfig2.getProjectList());
LinkedHashSet<User> mergedUsersList = new LinkedHashSet<>();
for (User user1 : reviewerConfig1.getUserList()) {
User user2 = getUser(reviewerConfig2, user1.getId());
if (user2.getId().isEmpty()) {
mergedUsersList.add(user1);
} else {
// Users defined in both repos. Merging data.
if (!user1.getEmail().isEmpty()) {
if (!user1.getEmail().equals(user2.getEmail())) {
log.atInfo().log("***Emails for user %s differ between files.", user1.getId());
}
}
if (!user1.getImageUrl().isEmpty()) {
if (!user1.getImageUrl().equals(user2.getImageUrl())) {
log.atInfo().log("***Image Urls for user %s differ between files.", user1.getId());
}
}
if (user1.getCrystals() != user2.getCrystals()) {
log.atInfo().log("***Crystals amount for user %s differ between files.", user1.getId());
}
LinkedHashSet<SocialNetwork> mergedUserSocialNetworks = new LinkedHashSet<>();
mergedUserSocialNetworks.addAll(user1.getSocialNetworkList());
LinkedHashSet<String> mergedUserSkillList = new LinkedHashSet<>();
mergedUserSkillList.addAll(user1.getSkillList());
LinkedHashSet<String> mergedUserProjectIdList = new LinkedHashSet<>();
mergedUserProjectIdList.addAll(user1.getProjectIdList());
mergedUserProjectIdList.addAll(user2.getProjectIdList());
LinkedHashSet<Contribution> mergedUserContributions = new LinkedHashSet<>();
mergedUserContributions.addAll(user1.getTopContributionList());
mergedUserContributions.addAll(user2.getTopContributionList());
User.Builder mergedUserBuilder = User.newBuilder().setId(user1.getId()).setFirstName(user1.getFirstName()).setLastName(user1.getLastName()).setEmail(user1.getEmail()).setImageUrl(user1.getImageUrl()).setCrystals(user1.getCrystals()).addAllSocialNetwork(user1.getSocialNetworkList()).addAllSkill(user1.getSkillList()).addAllProjectId(mergedUserProjectIdList).addAllTopContribution(mergedUserContributions);
mergedUsersList.add(mergedUserBuilder.build());
}
}
List<User> usersDefinedOnlyInReviewerConfig2 = reviewerConfig2.getUserList().stream().filter(user2 -> {
boolean isUser2NotContainedInMergedUsers = true;
for (User mergedUser : mergedUsersList) {
if (mergedUser.getId().equals(user2.getId())) {
isUser2NotContainedInMergedUsers = false;
break;
}
}
return isUser2NotContainedInMergedUsers;
}).collect(Collectors.toList());
mergedUsersList.addAll(usersDefinedOnlyInReviewerConfig2);
int totalCrystals = reviewerConfig1.getTotalCrystal();
ReviewerConfig.Builder mergedReviewerConfig = ReviewerConfig.newBuilder().setDisplayName(displayName).addAllRepo(repoList).addAllProject(projectList).addAllUser(mergedUsersList).setTotalCrystal(totalCrystals);
return mergedReviewerConfig.build();
}
use of com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig in project startup-os by google.
the class ReviewerConfigTest method totalCrystalCorrectTest.
@Test
public void totalCrystalCorrectTest() throws IOException {
ReviewerConfig config = (ReviewerConfig) fileUtils.readPrototxt("reviewer_config.prototxt", ReviewerConfig.newBuilder());
int crystalSum = 0;
List<User> userList = config.getUserList();
for (User user : userList) {
crystalSum += user.getCrystals();
}
assertEquals(config.getTotalCrystal(), crystalSum);
}
use of com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig in project startup-os by google.
the class RulesUpdater method main.
public static void main(String[] args) {
Flags.parseCurrentPackage(args);
FileUtils fileUtils = DaggerCommonComponent.create().getFileUtils();
String configPath;
String outputPath;
String buildWorkspaceDirectory = System.getenv("BUILD_WORKSPACE_DIRECTORY");
if (Paths.get(config.get()).isAbsolute()) {
configPath = config.get();
} else {
configPath = Paths.get(buildWorkspaceDirectory, config.get()).toAbsolutePath().toString();
}
if (Paths.get(output.get()).isAbsolute()) {
outputPath = output.get();
} else {
outputPath = Paths.get(buildWorkspaceDirectory, output.get()).toAbsolutePath().toString();
}
ReviewerConfig reviewerConfig = (ReviewerConfig) fileUtils.readPrototxtUnchecked(configPath, ReviewerConfig.newBuilder());
String rules = String.format(RULES_TEMPLATE, reviewerConfig.getUserList().stream().map(ReviewerProtos.User::getEmail).map(email -> String.format(EMAIL_CLAUSE, email)).collect(Collectors.joining(" || ")));
fileUtils.writeStringUnchecked(rules, outputPath);
}
Aggregations