use of com.google.startupos.common.repo.Protos.Commit in project startup-os by google.
the class TestTool method run.
void run(String[] args) throws Exception {
if (args.length > 0) {
String command = args[0];
Repo repo = repoFactory.create(System.getenv("BUILD_WORKSPACE_DIRECTORY"));
if (command.equals("switchBranch")) {
String branch = args[1];
repo.switchBranch(branch);
} else if (command.equals("getCommits")) {
String branch = args[1];
for (Commit commit : repo.getCommits(branch)) {
System.out.println();
System.out.println(commit);
}
} else if (command.equals("getFilesInCommit")) {
String commitId = args[1];
for (File file : repo.getFilesInCommit(commitId)) {
System.out.println();
System.out.println(file);
}
} else if (command.equals("getUncommittedFiles")) {
for (File file : repo.getUncommittedFiles()) {
System.out.println(file);
}
} else if (command.equals("merge")) {
String branch = args[1];
repo.merge(branch);
} else if (command.equals("isMerged")) {
String branch = args[1];
repo.isMerged(branch);
} else if (command.equals("removeBranch")) {
String branch = args[1];
repo.removeBranch(branch);
} else if (command.equals("listBranches")) {
for (String branch : repo.listBranches()) {
System.out.println(branch);
}
} else if (command.equals("getTextDiff")) {
File file1 = File.newBuilder().setCommitId(args[1]).setFilename("tools/aa/AaModule.java").build();
File file2 = File.newBuilder().setCommitId(args[2]).setFilename("tools/aa/AaModule.java").build();
System.out.println(repo.getTextDiff(file1, file2));
} else if (command.equals("getFileContents")) {
System.out.println(repo.getFileContents(args[1], args[2]));
} else {
System.out.println("Please specify command");
}
}
}
use of com.google.startupos.common.repo.Protos.Commit in project startup-os by google.
the class CodeReviewServiceGetDiffFilesTest method testGetDiffFiles_whenFileIsModified.
@Test
public void testGetDiffFiles_whenFileIsModified() {
writeFile("new_file_content");
final String lastCommitId = repo.commit(repo.getUncommittedFiles(), COMMIT_MESSAGE).getId();
Commit lastCommit = Commit.newBuilder().setId(lastCommitId).addFile(File.newBuilder().setFilename("test_file.txt").setWorkspace("ws1").setRepoId(REPO_ID).setCommitId(lastCommitId).setAction(File.Action.MODIFY).setFilenameWithRepo("startup-os/test_file.txt").build()).build();
assertEquals(getExpectedResponseAddingCommit(lastCommit), getResponse());
}
use of com.google.startupos.common.repo.Protos.Commit 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();
}
use of com.google.startupos.common.repo.Protos.Commit in project startup-os by google.
the class CodeReviewService method addWorkspaceAndRepoToCommits.
private ImmutableList<Commit> addWorkspaceAndRepoToCommits(ImmutableList<Commit> commits, String workspace, String repoId) {
ImmutableList.Builder<Commit> result = ImmutableList.builder();
for (Commit commit : commits) {
ImmutableList<File> files = addWorkspaceAndRepoToFiles(commit.getFileList(), workspace, repoId);
commit = commit.toBuilder().clearFile().addAllFile(files).build();
result.add(commit);
}
return result.build();
}
use of com.google.startupos.common.repo.Protos.Commit in project startup-os by google.
the class CodeReviewService method getDiffFiles.
@Override
public void getDiffFiles(DiffFilesRequest request, StreamObserver<DiffFilesResponse> responseObserver) {
if (request.getWorkspace().isEmpty() || request.getDiffId() <= 0) {
responseObserver.onError(Status.INVALID_ARGUMENT.withDescription("Workspace must be set and diff_id must be > 0.\nrequest:\n" + request).asRuntimeException());
return;
}
logger.atInfo().log("DiffFiles request\n%s", request);
String workspacePath;
String workspace;
String branch;
boolean isHead;
if (workspaceExists(request.getWorkspace())) {
workspacePath = getWorkspacePath(request.getWorkspace());
workspace = request.getWorkspace();
branch = "D" + request.getDiffId();
isHead = false;
} else {
logger.atInfo().log("Workspace %s does not exist. Fallbacking to head.", request.getWorkspace());
workspacePath = fileUtils.joinToAbsolutePath(basePath, "head");
workspace = "";
branch = "remotes/origin/D" + request.getDiffId();
isHead = true;
}
DiffFilesResponse.Builder response = DiffFilesResponse.newBuilder();
try {
fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
String repoName = Paths.get(path).getFileName().toString();
Repo repo = repoFactory.create(path);
if (!isHead) {
ImmutableList<Commit> commits = addWorkspaceAndRepoToCommits(repo.getCommits(branch), workspace, repoName);
ImmutableList<File> uncommittedFiles = addWorkspaceAndRepoToFiles(repo.getUncommittedFiles(), workspace, repoName);
response.addBranchInfo(BranchInfo.newBuilder().setDiffId(request.getDiffId()).setRepoId(repoName).addAllCommit(commits).addAllUncommittedFile(uncommittedFiles).build());
} else {
ImmutableList<Commit> commits = ImmutableList.of();
if (repo.branchExists(branch)) {
commits = addWorkspaceAndRepoToCommits(repo.getCommits(branch), workspace, repoName);
} else {
logger.atInfo().log("Branch %s does not exist in head", branch);
}
response.addBranchInfo(BranchInfo.newBuilder().setDiffId(request.getDiffId()).setRepoId(repoName).addAllCommit(commits).build());
}
});
} catch (IOException e) {
e.printStackTrace();
}
responseObserver.onNext(response.build());
responseObserver.onCompleted();
}
Aggregations