use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.
the class DiffConverterTest method testCommentToFeatureBranchCommit.
@Test
public void testCommentToFeatureBranchCommit() {
Diff diff = Diff.newBuilder().setId(1234).setAuthor(Author.newBuilder().setEmail("author@test.com").build()).setWorkspace("ws1").setCreatedTimestamp(1543989866559L).setModifiedTimestamp(1544008405696L).addCodeThread(Thread.newBuilder().setRepoId("test-repo").setCommitId(FEATURE_BRANCH_COMMIT_ID).setFile(Protos.File.newBuilder().setFilename("test_file.txt").setWorkspace("ws1").setRepoId("test-repo").setCommitId(FEATURE_BRANCH_COMMIT_ID).setFilenameWithRepo("test-repo/test_file.txt").build()).setLineNumber(5).addComment(Comment.newBuilder().setContent("R 5").setTimestamp(1544008385129L).setCreatedBy("reviewer@test.com").setId("DPwKo").build()).setId("KblmQG").build()).setModifiedBy("author@test.com").addGithubPr(GithubPr.newBuilder().setOwner("val-fed").setRepo("test-repo").build()).build();
List<PullRequest> actualPullRequest = diffConverter.toPullRequests(diff, ImmutableMap.of("test-repo", gitRepo));
PullRequest expectedPullRequest = PullRequest.newBuilder().setState("open").setTitle("D1234").setUser(User.newBuilder().setEmail("author@test.com").build()).setCreatedAt("2018-12-05T06:04:26.559Z").setUpdatedAt("2018-12-05T11:13:25.696Z").addReviewComment(ReviewComment.newBuilder().setPath("test_file.txt").setPosition(5).setCommitId(FEATURE_BRANCH_COMMIT_ID).setUser(User.newBuilder().setEmail("reviewer@test.com").build()).setBody("R 5").setCreatedAt("2018-12-05T11:13:05.129Z").setUpdatedAt("2018-12-05T11:13:25.696Z").setReviewerThreadId("KblmQG").setReviewerCommentId("DPwKo").setReviewerLineNumber(5).build()).setBaseBranchName("master").setHeadBranchName("D1234").setRepo("test-repo").setOwner("val-fed").setAssociatedReviewerDiff(1234).build();
assertEquals(expectedPullRequest.toString(), actualPullRequest.get(0).toString());
}
use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.
the class DiffConverterTest method testCommentToBaseBranchCommit.
@Test
public void testCommentToBaseBranchCommit() {
Diff diff = Diff.newBuilder().setId(1234).setAuthor(Author.newBuilder().setEmail("author@test.com").build()).setWorkspace("ws1").setCreatedTimestamp(1543989866559L).setModifiedTimestamp(1544008405696L).addCodeThread(Thread.newBuilder().setRepoId("test-repo").setCommitId(BASE_BRANCH_COMMIT_ID).setFile(Protos.File.newBuilder().setFilename("test_file.txt").setWorkspace("ws1").setRepoId("test-repo").setCommitId(BASE_BRANCH_COMMIT_ID).setFilenameWithRepo("test-repo/test_file.txt").build()).setLineNumber(14).addComment(Comment.newBuilder().setContent("L 14").setTimestamp(1544008405695L).setCreatedBy("reviewer@test.com").setId("s47NL").build()).setId("ayAF7N").build()).setModifiedBy("author@test.com").addGithubPr(GithubPr.newBuilder().setOwner("val-fed").setRepo("test-repo").build()).build();
List<PullRequest> actualPullRequest = diffConverter.toPullRequests(diff, ImmutableMap.of("test-repo", gitRepo));
PullRequest expectedPullRequest = PullRequest.newBuilder().setState("open").setTitle("D1234").setUser(User.newBuilder().setEmail("author@test.com").build()).setCreatedAt("2018-12-05T06:04:26.559Z").setUpdatedAt("2018-12-05T11:13:25.696Z").addReviewComment(ReviewComment.newBuilder().setPath("test_file.txt").setPosition(12).setCommitId(BASE_BRANCH_COMMIT_ID).setUser(User.newBuilder().setEmail("reviewer@test.com").build()).setBody("L 14").setCreatedAt("2018-12-05T11:13:25.695Z").setUpdatedAt("2018-12-05T11:13:25.696Z").setReviewerThreadId("ayAF7N").setReviewerCommentId("s47NL").setReviewerLineNumber(14).build()).setBaseBranchName("master").setHeadBranchName("D1234").setRepo("test-repo").setOwner("val-fed").setAssociatedReviewerDiff(1234).build();
assertEquals(expectedPullRequest.toString(), actualPullRequest.get(0).toString());
}
use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff 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.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.
the class DiffCommand method run.
@Override
public boolean run(String[] args) {
Flags.parseCurrentPackage(args);
Diff diff = (diffNumber == -1) ? createDiff() : updateDiff(diffNumber);
CreateDiffRequest request = CreateDiffRequest.newBuilder().setDiff(diff).build();
// TODO: Check if we changed diff, update only if changed. Write to output if no change.
// TODO: Rename createDiff to createOrUpdateDiff
codeReviewBlockingStub.createDiff(request);
return true;
}
use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.
the class SubmitterTask method tryRegisterListener.
public void tryRegisterListener() {
if (!listenerRegistered) {
firestoreClient.addCollectionListener(ReviewerConstants.DIFF_COLLECTION, Diff.newBuilder(), new ProtoEventListener<ProtoQuerySnapshot<Diff>>() {
@Override
public void onEvent(@Nullable ProtoQuerySnapshot<Diff> snapshot, @Nullable RuntimeException e) {
if (e != null) {
System.err.println("Listen failed: " + e);
return;
}
ArrayList<Diff> updatedDiffs = new ArrayList(diffs);
log.atInfo().log("Received %d changes", snapshot.getProtoChanges().size());
for (ProtoChange<Diff> protoChange : snapshot.getProtoChanges()) {
switch(protoChange.getType()) {
case ADDED:
updatedDiffs.add(protoChange.getProto());
break;
case MODIFIED:
// The indices are made so that this type of sequential remove & add works, see:
// https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/com/google/cloud/firestore/DocumentChange.html#getNewIndex--
updatedDiffs.remove(protoChange.getOldIndex());
updatedDiffs.add(protoChange.getNewIndex(), protoChange.getProto());
break;
case REMOVED:
updatedDiffs.remove(protoChange.getOldIndex());
break;
default:
throw new IllegalStateException("Unknown enum " + protoChange.getType());
}
}
diffs = ImmutableList.copyOf(updatedDiffs);
run();
}
});
listenerRegistered = true;
}
}
Aggregations