Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove PR if max attempt reached #430

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 17 additions & 1 deletion src/main/java/com/lpvs/service/LPVSQueueService.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,23 @@ public void processWebHook(LPVSQueue webhookConfig) {
pullRequest = lpvsPullRequestRepository.saveAndFlush(pullRequest);
log.error("Can't authorize commentResults() " + e);
e.printStackTrace();
m-rudyk marked this conversation as resolved.
Show resolved Hide resolved
delete(webhookConfig);
int currentAttempts = webhookConfig.getAttempts();
o-kopysov marked this conversation as resolved.
Show resolved Hide resolved
if (currentAttempts < maxAttempts) {
webhookConfig.setAttempts(currentAttempts++);
Copy link
Collaborator

Choose a reason for hiding this comment

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

currentAttempts++ increases value after execution setAttempts.
Please use currentAttempts+1 instead.

try {
addFirst(webhookConfig);
} catch (InterruptedException e1) {
log.warn("Failed to update Queue element");
}
queueRepository.save(webhookConfig);
} else {
log.warn(
"Maximum amount of processing webhook reached for pull request: "
+ pullRequest.getId()
+ " "
+ pullRequest.getPullRequestUrl());
delete(webhookConfig);
m-rudyk marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
6 changes: 6 additions & 0 deletions src/test/java/com/lpvs/service/LPVSQueueServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public void testProcessWebHook__NoPRDownloaded() throws IOException {
verifyNoMoreInteractions(mockGitHubService);
verifyNoMoreInteractions(mockDetectService);
verifyNoMoreInteractions(mockLicenseService);

// test when max attempts reached
webhookConfig.setAttempts(maxAttempts);
queueService.processWebHook(webhookConfig);

verify(mockGitHubService, times(2)).getPullRequestFiles(webhookConfig);
}
}

Expand Down
Loading