Search in sources :

Example 16 with GitRepo

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);
            }
        });
    }
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo)

Example 17 with GitRepo

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);
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo) GitRepoFactory(com.google.startupos.common.repo.GitRepoFactory)

Example 18 with GitRepo

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();
        }
    }
}
Also used : ReviewerConfig(com.google.startupos.tools.reviewer.ReviewerProtos.ReviewerConfig) ReviewerRegistry(com.google.startupos.tools.reviewer.RegistryProtos.ReviewerRegistry) GitRepo(com.google.startupos.common.repo.GitRepo) IOException(java.io.IOException)

Example 19 with GitRepo

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();
}
Also used : Arrays(java.util.Arrays) Empty(com.google.startupos.tools.reviewer.local_server.service.Protos.Empty) ManagedChannel(io.grpc.ManagedChannel) FileUtils(com.google.startupos.common.FileUtils) HashMap(java.util.HashMap) Inject(javax.inject.Inject) GitRepoFactory(com.google.startupos.common.repo.GitRepoFactory) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GitRepo(com.google.startupos.common.repo.GitRepo) Named(javax.inject.Named) FlagDesc(com.google.startupos.common.flags.FlagDesc) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) CodeReviewServiceGrpc(com.google.startupos.tools.reviewer.local_server.service.CodeReviewServiceGrpc) Flags(com.google.startupos.common.flags.Flags) Reviewer(com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer) Collectors(java.util.stream.Collectors) CreateDiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) List(java.util.List) DiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffRequest) Paths(java.nio.file.Paths) GithubPr(com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse) Flag(com.google.startupos.common.flags.Flag) GitRepo(com.google.startupos.common.repo.GitRepo) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) HashMap(java.util.HashMap) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse)

Example 20 with GitRepo

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();
    }
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo)

Aggregations

GitRepo (com.google.startupos.common.repo.GitRepo)21 IOException (java.io.IOException)6 GitRepoFactory (com.google.startupos.common.repo.GitRepoFactory)4 FileUtils (com.google.startupos.common.FileUtils)3 Diff (com.google.startupos.tools.reviewer.local_server.service.Protos.Diff)3 ImmutableList (com.google.common.collect.ImmutableList)2 Flag (com.google.startupos.common.flags.Flag)2 FlagDesc (com.google.startupos.common.flags.FlagDesc)2 Flags (com.google.startupos.common.flags.Flags)2 CiRequest (com.google.startupos.tools.reviewer.ReviewerProtos.CiRequest)2 CiResponse (com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse)2 Repo (com.google.startupos.tools.reviewer.ReviewerProtos.Repo)2 Reviewer (com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer)2 Paths (java.nio.file.Paths)2 Named (javax.inject.Named)2 CommandLine (com.google.startupos.common.CommandLine)1 CommonModule (com.google.startupos.common.CommonModule)1 File (com.google.startupos.common.repo.Protos.File)1 BuildFile (com.google.startupos.tools.build_file_generator.Protos.BuildFile)1 HttpArchiveDeps (com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDeps)1