Search in sources :

Example 6 with File

use of com.google.startupos.common.repo.Protos.File in project startup-os by google.

the class CodeReviewServiceTextDiffTest method testTextDiff_deletedFile.

// DELETE, any file
@Test
public void testTextDiff_deletedFile() {
    File file = File.newBuilder().setRepoId("startup-os").setWorkspace(TEST_WORKSPACE).setFilename(TEST_FILE).setAction(Action.DELETE).build();
    TextDiffResponse response = getResponse(file);
    assertEquals(getExpectedResponse(""), response);
}
Also used : TextDiffResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.TextDiffResponse) File(com.google.startupos.common.repo.Protos.File) Test(org.junit.Test)

Example 7 with File

use of com.google.startupos.common.repo.Protos.File in project startup-os by google.

the class CodeReviewServiceTextDiffTest method testTextDiff_locallyModifiedWorkspaceExistsNewFile.

// ADD, locally modified, workspace exists, new file
@Test
public void testTextDiff_locallyModifiedWorkspaceExistsNewFile() {
    writeFile("somefile.txt", TEST_FILE_CONTENTS);
    writeFile(TEST_FILE_CONTENTS);
    File file = File.newBuilder().setRepoId("startup-os").setWorkspace(TEST_WORKSPACE).setFilename("somefile.txt").build();
    TextDiffResponse response = getResponse(file);
    assertEquals(getExpectedResponse(TEST_FILE_CONTENTS), response);
}
Also used : TextDiffResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.TextDiffResponse) File(com.google.startupos.common.repo.Protos.File) Test(org.junit.Test)

Example 8 with File

use of com.google.startupos.common.repo.Protos.File in project startup-os by google.

the class SnapshotCommand method run.

@Override
public boolean run(String[] args) {
    if (diffNumber == -1) {
        System.out.println(RED_ERROR + "Cannot find diff number");
        return false;
    }
    String branchName = String.format("D%d", diffNumber);
    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(repoName, repo.currentBranch());
            repo.switchBranch(branchName);
            ImmutableList<File> files = repo.getUncommittedFiles();
            if (files.isEmpty()) {
                System.out.println(String.format("[%s]: No files to update", repoName));
                // Only skips this iteration
                return;
            }
            String message = branchName + ":\n" + files.stream().map(File::getFilename).collect(Collectors.joining("\n"));
            repo.commit(files, String.format(message, branchName));
            System.out.println(String.format("[%s]: Committed changes", repoName));
        });
    } catch (Exception e) {
        revertChanges(repoToInitialBranch);
        e.printStackTrace();
    }
    return true;
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo) File(com.google.startupos.common.repo.Protos.File)

Example 9 with File

use of com.google.startupos.common.repo.Protos.File in project startup-os by google.

the class GitRepo method getFilesInCommit.

@Override
public ImmutableList<File> getFilesInCommit(String commitId) {
    CommandResult commandResult = runCommand("diff-tree --no-commit-id --name-status -r " + commitId);
    ImmutableList.Builder<File> result = ImmutableList.builder();
    try {
        ImmutableList<String> lines = splitLines(commandResult.stdout);
        for (String line : lines) {
            String[] parts = line.split("\t");
            File file = File.newBuilder().setAction(getAction(parts[0].trim())).setCommitId(commitId).setFilename(parts[1].trim()).build();
            result.add(file);
        }
    } catch (IllegalStateException e) {
        throw new IllegalStateException("getFilesInCommit failed for commit " + commitId, e);
    }
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) File(com.google.startupos.common.repo.Protos.File)

Example 10 with File

use of com.google.startupos.common.repo.Protos.File in project startup-os by google.

the class GitRepo method commit.

@Override
public Commit commit(ImmutableList<File> files, String message) {
    Commit.Builder commitBuilder = Commit.newBuilder();
    for (File file : files) {
        addFile(file.getFilename());
    }
    runCommand(Arrays.asList("commit", "-m", "\"" + message + "\""));
    String commitId = getHeadCommitId();
    for (File file : files) {
        commitBuilder.addFile(file.toBuilder().setCommitId(commitId));
    }
    return commitBuilder.setId(commitId).build();
}
Also used : Commit(com.google.startupos.common.repo.Protos.Commit) File(com.google.startupos.common.repo.Protos.File)

Aggregations

File (com.google.startupos.common.repo.Protos.File)19 Test (org.junit.Test)11 TextDiffResponse (com.google.startupos.tools.reviewer.local_server.service.Protos.TextDiffResponse)9 Commit (com.google.startupos.common.repo.Protos.Commit)4 Repo (com.google.startupos.common.repo.Repo)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 GitRepo (com.google.startupos.common.repo.GitRepo)1 DiffFilesResponse (com.google.startupos.tools.reviewer.local_server.service.Protos.DiffFilesResponse)1