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

Commit

Permalink
Updates to syncPullRequest endpoint (#84)
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
  • Loading branch information
dcanar9 authored Jun 30, 2022
1 parent cc42335 commit dd1f89c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 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.14-SNAPSHOT</version>
<version>3.3.15-SNAPSHOT</version>


<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public ResponseEntity<String> cleanup() throws HygieiaException {

@RequestMapping(value = "/syncPullRequest", consumes = APPLICATION_JSON_VALUE,method = POST, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<String> syncPullRequest(@Valid @RequestBody SyncPRRequest request) {
return gitHubService.syncPullRequest(request.getTitle(), request.getRepoUrl(), request.getBranch(), request.getLimit());
return gitHubService.syncPullRequest(request.getTitle(), request.getRepoUrl(), request.getBranch());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class SyncPRRequest extends BaseRequest {
private String title;
private String repoUrl;
private String branch;
private int limit;


public String getRepoUrl() {
Expand All @@ -23,14 +22,6 @@ public void setBranch(String branch) {
this.branch = branch;
}

public int getLimit() {
return limit;
}

public void setLimit(int limit) {
this.limit = limit;
}

public String getTitle() {
return title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
public interface GitHubService {
ResponseEntity<String> cleanup();

ResponseEntity<String> syncPullRequest(String title, String repo, String branch, int limit);
ResponseEntity<String> syncPullRequest(String title, String repo, String branch);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ResponseEntity<String> cleanup() {
.body(GITHUB_COLLECTOR_NAME + " cleanup - " + count + " obsolete GitHub repo's deleted. ");
}

public ResponseEntity<String> syncPullRequest(String title, String repoUrl, String branch, int limit){
public ResponseEntity<String> syncPullRequest(String title, String repoUrl, String branch){
ObjectId githubCollectorId = collectorRepository.findByName(GITHUB_COLLECTOR_NAME).getId();

// get the collector item id from the collectorItems should result in only one
Expand All @@ -73,7 +73,7 @@ public ResponseEntity<String> syncPullRequest(String title, String repoUrl, Stri
if(dashboard.isEmpty()){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(String.format("Unable to find dashboard for title: %s", title));
}
ObjectId componentId = dashboard.get(0).getApplication().getComponents().get(0).getId();
ObjectId componentId = dashboard.get(0).getWidgets().get(0).getComponentId();

com.capitalone.dashboard.model.Component component = componentRepository.findOne(componentId);
if(Objects.isNull(component)){
Expand All @@ -85,7 +85,7 @@ public ResponseEntity<String> syncPullRequest(String title, String repoUrl, Stri
// get all git requests with collectorItemID
List<GitRequest> allGitRequests = gitRequestRepository.findByCollectorItemIdAndRequestType(collectorItemID, "pull");
if (allGitRequests.isEmpty()){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(String.format("Unable to find any gitRequests with the collectorItemId: %s", collectorItem));
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(String.format("Unable to find any gitRequests with the collectorItemId: %s", collectorItemID.toString()));
}

// filter list of gitRequests, if scmUrl not in SCMs list add that gitRequest to the list so we can fix later
Expand All @@ -94,14 +94,16 @@ public ResponseEntity<String> syncPullRequest(String title, String repoUrl, Stri
// iterate through the git requests with the wrong collectorItemId and correct them
for (GitRequest gr: gitRequestsToFix) {
CollectorItem collItem = collectorItemRepository.findRepoByUrlAndBranch(githubCollectorId, gr.getScmUrl(), gr.getScmBranch());
if (Objects.isNull(collItem)){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(String.format("Unable to find collector item for repo: %s", repoUrl));
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()));
}
else {
LOG.info(String.format("Unable to update gitRequest: Unable to find collector item for repo: %s", gr.getScmUrl()));
}
gr.setCollectorItemId(collItem.getId());
gitRequestRepository.save(gr);
LOG.info(String.format("GitRequest with wrong collectorItemId: %s \tcorrectCollectorItemId: %s", gr.getScmUrl(), collItem.getId().toString()));
}
String responseString = String.format("Successfully corrected the following gitRequests with URLs: %s", gitRequestsToFix.stream().
String responseString = String.format("SyncPullRequest: Successfully corrected the following gitRequests with URLs: %s", gitRequestsToFix.stream().
map(gr -> gr.getScmUrl().toString()).collect(Collectors.joining(", ")));
return ResponseEntity.status(HttpStatus.OK).body(responseString);

Expand Down

0 comments on commit dd1f89c

Please sign in to comment.