Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ public void notifyCommiter(
if(result.equals(VerificationStatus.MERGE_FAILED))
{
status.append(String.format("<tr><td>Merge failed between commits:<td> <b>%s</b> and <b>%s</b></td></td></tr>",parentCommitId.substring(0, 7),commitId.substring(0, 7)));
}
else
} else if(parentCommitId != null) {
status.append(String.format("<tr><td>New process Id:</td><td>vg_%s</td></tr>", parentCommitId));
} else
{
status.append(String.format("<tr><td>Commit Id:</td><td>%s</td></tr>", commitId.substring(0, 7)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ protected void doHandle() {
_commitItem.getParent().getBranchDescriptor().getCommitId(),
_commitItem.getMergedBranchName()
);
}
} else if(!_commitItem.getChildCommit().isEmpty()){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is some room for refactoring here. You have basically the same call to CollectorApi.getEmailSender().notifyCommiter() twice.

I think that a cleaner way would be to do this check !_commitItem.getChildCommit().isEmpty() within the else { .. } block. And then pass the null value in the method call.

Now I see that you have overloaded the method in EmailSender.java and that takes care of it. However, I wouldn't recommend using a method overloading pattern just pass a null value as an argument. There is really no major change in the overloaded method since you are basically calling the overloaded method. Also, this makes the EmailSender API not as clear about its behavior.

So, do the following. Remove the method in EmailSender.java within lines 68-88 and use the other method to make the call from OnFailureHandler.java.

Does that make sense?

CollectorApi.getEmailSender().notifyCommiter(
_commitItem.getBranchDescriptor().getCommitId(),
_commitItem.getStatus(),
_commitItem.getBuildUrl(),
"Verigreen Status - Failure",
EmailSender.getFailedSignature(),
_commitItem.getBranchDescriptor().getCommitter(),
_commitItem.getBranchDescriptor().getProtectedBranch(),
_commitItem.getChildCommit(),
_commitItem.getMergedBranchName()
);
}
else {
CollectorApi.getEmailSender().notifyCommiter(
_commitItem.getBranchDescriptor().getCommitId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,4 +1375,81 @@ public void testPermittedUsersChangesInRT() throws IOException, InterruptedExcep
Assert.assertTrue(ex instanceof RestClientException);
}
}


@Test
public void testScenario() throws IOException, InterruptedException {
String destinationFolderForNewFile = DEFAULT_COMMIT_FOLDER;

String masterBranchCurrentSHA1 =
((JGitOperator) _sourceControlOperator).getRef(
getBranchRefsRemotesFullName(_masterBranch)).getObjectId().getName();

String commiterName = generateUserName();
String commiterEmail = generateEmailAddress();
String content = getContent("test");
String[] branch = generateBranchNames(1);

setProtectedBranch(_masterBranch);
checkoutExistingBranch(_masterBranch);

String commitId =
commitAndPush(
destinationFolderForNewFile,
commiterName,
commiterEmail,
content,
true,
_masterBranch);

String shortCommitId = processCommitId(commitId, commiterName);
checkSuccessfulyProccesedCommitThatShouldPass(
VerigreenUtils.getVerigreenBranchName(shortCommitId),
_masterBranch,
_timeoutForTestInMilis,
commitId,
commiterName,
commiterEmail,
content,
true);

((JGitOperator) _sourceControlOperator).reset(masterBranchCurrentSHA1);
createAndPushBranches(branch);
checkoutExistingBranch(branch[0]);

commitAndPush(
destinationFolderForNewFile,
commiterName,
commiterEmail,
content,
true,
true,
branch[0]);

checkoutExistingBranch(_masterBranch);
_sourceControlOperator.merge(_masterBranch,_masterBranch);
_sourceControlOperator.merge(_masterBranch, branch[0]);

String commitId3 =
commitAndPush(
destinationFolderForNewFile,
commiterName,
commiterEmail,
content,
true,
_masterBranch);

String shortCommitId3 = processCommitId(commitId3, commiterName);

checkSuccessfulyProccesedCommitThatShouldFail(
VerigreenUtils.getVerigreenBranchName(shortCommitId3),
_masterBranch,
_timeoutForTestInMilis,
commitId3,
commiterName,
commiterEmail,
content,
VerificationStatus.GIT_FAILURE,
true);
}
}