Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Formatting response and fixing bug (#86)
Browse files Browse the repository at this point in the history
* added endpoint to fix gitRequests with the wrong collectorItemId and added logging

* added endpoint to fix gitRequests with the wrong collectorItemId and added logging update

* Increment POM

* Updated syncPullRequest logging, logic, and  removed limit from paramters

* updating method to remove limit parameter

* increment POM version

* removing item from list to make http response accurate

* increment pom version number

* syncPullRequest: Formatting response and fixing bug

* increment pom
  • Loading branch information
dcanar9 authored Jun 30, 2022
1 parent e6156be commit 63d54dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</description>
<url>https://github.com/Hygieia/${repository.name}</url>
<packaging>jar</packaging>
<version>3.3.16-SNAPSHOT</version>
<version>3.3.17-SNAPSHOT</version>


<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -92,19 +93,28 @@ public ResponseEntity<String> syncPullRequest(String title, String repoUrl, Stri
List<GitRequest> gitRequestsToFix = allGitRequests.stream().filter(GR -> !SCMs.contains(GR.getScmUrl().toLowerCase())).collect(Collectors.toList());

// iterate through the git requests with the wrong collectorItemId and correct them
List<GitRequest> fixedGitRequests = new ArrayList<>();
int failedUpdateCount = 0;
for (GitRequest gr: gitRequestsToFix) {
CollectorItem collItem = collectorItemRepository.findRepoByUrlAndBranch(githubCollectorId, gr.getScmUrl(), gr.getScmBranch());
if (Objects.nonNull(collItem)){
gr.setCollectorItemId(collItem.getId());
gitRequestRepository.save(gr);
LOG.info(String.format("GitRequest with wrong collectorItemId: %s \tcorrectCollectorItemId: %s", gr.getScmUrl(), collItem.getId().toString()));
fixedGitRequests.add(gr);
}
else {
LOG.info(String.format("Unable to update gitRequest: Unable to find collector item for repo: %s", gr.getScmUrl()));
gitRequestsToFix.remove(gr); // removing so not in response later
failedUpdateCount++;
}
}
String responseString = String.format("SyncPullRequest: Successfully corrected the following gitRequests with URLs: %s", gitRequestsToFix.stream().
String responseString = "SyncPullRequest: ";

if (failedUpdateCount > 0){
responseString = responseString + "[FAILED TO UPDATE " + String.valueOf(failedUpdateCount) + "GIT REQUEST] ";
}

responseString = responseString + String.format("Successfully corrected the following gitRequests with URLs: %s", fixedGitRequests.stream().
map(gr -> gr.getScmUrl().toString()).collect(Collectors.joining(", ")));
return ResponseEntity.status(HttpStatus.OK).body(responseString);

Expand Down

0 comments on commit 63d54dc

Please sign in to comment.