Skip to content

Commit

Permalink
Add Process Summary, Update Email, and Others (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
bibekaryal86 authored Jul 24, 2024
1 parent 5a4f05f commit a5a42a1
Show file tree
Hide file tree
Showing 29 changed files with 683 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
import app.dependency.update.app.model.MongoNpmSkips;
import app.dependency.update.app.model.MongoPackages;
import app.dependency.update.app.model.MongoPlugins;
import app.dependency.update.app.model.dto.Dependencies;
import app.dependency.update.app.model.dto.NpmSkips;
import app.dependency.update.app.model.dto.Packages;
import app.dependency.update.app.model.dto.Plugins;
import app.dependency.update.app.model.MongoProcessSummaries;
import app.dependency.update.app.model.entities.Dependencies;
import app.dependency.update.app.model.entities.NpmSkips;
import app.dependency.update.app.model.entities.Packages;
import app.dependency.update.app.model.entities.Plugins;
import app.dependency.update.app.service.MongoRepoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -23,6 +29,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

@RestController
@RequestMapping("/mongo-repo")
Expand Down Expand Up @@ -213,4 +220,56 @@ public ResponseEntity<String> updateMavenRepoInMongo() {
() -> mongoRepoService.updatePackagesInMongo(mongoRepoService.packagesMap()));
return ResponseEntity.accepted().body("{\"request\": \"submitted\"}");
}

@Operation(summary = "Get Process Summaries")
@GetMapping(value = "/process_summaries", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<MongoProcessSummaries> getProcessSummaries(
@Parameter(
in = ParameterIn.QUERY,
description = "Update Type",
schema =
@Schema(
allowableValues = {
"ALL",
"NPM_DEPENDENCIES",
"GRADLE_DEPENDENCIES",
"PYTHON_DEPENDENCIES"
}))
@RequestParam(required = false, defaultValue = "")
final String updateType,
@Parameter(in = ParameterIn.QUERY, description = "Update Date")
@RequestParam(required = false)
final LocalDate updateTime,
@Parameter(in = ParameterIn.QUERY, description = "Page Number")
@RequestParam(required = false, defaultValue = "0")
final int pageNumber,
@Parameter(in = ParameterIn.QUERY, description = "Page Size")
@RequestParam(required = false, defaultValue = "100")
final int pageSize) {
if (!isUpdateTypeValidForProcessSummaries(updateType)) {
throw new ResponseStatusException(
HttpStatusCode.valueOf(400),
String.format(
"Allowed Values for Update Type: %s, %s, %s, %s",
UpdateType.ALL,
UpdateType.NPM_DEPENDENCIES,
UpdateType.GRADLE_DEPENDENCIES,
UpdateType.PYTHON_DEPENDENCIES));
}

return ResponseEntity.ok(
mongoRepoService.getProcessSummaries(updateType, updateTime, pageNumber, pageSize));
}

private boolean isUpdateTypeValidForProcessSummaries(final String updateType) {
if (isEmpty(updateType)) {
return true;
}
return List.of(
UpdateType.ALL.name(),
UpdateType.NPM_DEPENDENCIES.name(),
UpdateType.GRADLE_DEPENDENCIES.name(),
UpdateType.PYTHON_DEPENDENCIES.name())
.contains(updateType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ResponseEntity<String> updateRepo(
if (updateRepoService.isTaskRunning()) {
return ResponseEntity.unprocessableEntity().body("{\"process\": \"already running\"}");
} else {
if (isInvalidBranchDate(branchDate, updateType)) {
if (checkInvalidBranchDate(branchDate, updateType)) {
return ResponseEntity.badRequest().body("{\"branchDate\": \"empty or invalid format\"}");
}

Expand All @@ -68,13 +68,13 @@ public ResponseEntity<String> updateRepo(
updateType,
isForceCreatePr,
isDeleteUpdateDependenciesOnly,
false);
checkDependenciesUpdate(updateType));
}
return ResponseEntity.accepted().body("{\"request\": \"submitted\"}");
}

@SuppressWarnings("ResultOfMethodCallIgnored")
private boolean isInvalidBranchDate(final String branchDate, final UpdateType updateType) {
private boolean checkInvalidBranchDate(final String branchDate, final UpdateType updateType) {
if (updateType.equals(UpdateType.NPM_SNAPSHOT)
|| updateType.equals(UpdateType.GITHUB_PR_CREATE)
|| updateType.equals(UpdateType.GRADLE_SPOTLESS)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.dependency.update.app.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MongoProcessSummaries {
private List<ProcessSummary> processSummaries;
private int currentPage;
private int totalPages;
private int totalElements;
private int pageSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@Builder
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProcessSummary {
private String updateType;
private int mongoPluginsToUpdate;
private int mongoDependenciesToUpdate;
private int mongoPackagesToUpdate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProcessedRepository {
private String repoName;
private String repoType;
private boolean isPrCreated;
private boolean isPrCreateError;
private boolean isPrMerged;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.dependency.update.app.model.dto;
package app.dependency.update.app.model.entities;

import static app.dependency.update.app.util.ConstantUtils.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.dependency.update.app.model.dto;
package app.dependency.update.app.model.entities;

import static app.dependency.update.app.util.ConstantUtils.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.dependency.update.app.model.dto;
package app.dependency.update.app.model.entities;

import static app.dependency.update.app.util.ConstantUtils.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.dependency.update.app.model.dto;
package app.dependency.update.app.model.entities;

import static app.dependency.update.app.util.ConstantUtils.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package app.dependency.update.app.model.entities;

import static app.dependency.update.app.util.ConstantUtils.*;

import app.dependency.update.app.model.ProcessSummary;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoId;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Document(collection = MONGODB_COLLECTION_PROCESS_SUMMARIES)
public class ProcessSummaries extends ProcessSummary {
@MongoId private ObjectId id;
private LocalDateTime updateDateTime;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.dependency.update.app.repository;

import app.dependency.update.app.model.dto.Dependencies;
import app.dependency.update.app.model.entities.Dependencies;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.dependency.update.app.repository;

import app.dependency.update.app.model.dto.NpmSkips;
import app.dependency.update.app.model.entities.NpmSkips;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.dependency.update.app.repository;

import app.dependency.update.app.model.dto.Packages;
import app.dependency.update.app.model.entities.Packages;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.dependency.update.app.repository;

import app.dependency.update.app.model.dto.Plugins;
import app.dependency.update.app.model.entities.Plugins;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package app.dependency.update.app.repository;

import app.dependency.update.app.model.entities.ProcessSummaries;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface ProcessSummariesRepository extends MongoRepository<ProcessSummaries, String> {
// find by updateType with pagination
Page<ProcessSummaries> findByUpdateType(String updateType, Pageable pageable);

// find by updateDateTime for a given date (hence between start and end of day)
@Query("{ 'updateDateTime' : { $gte: ?0, $lt: ?1 } }")
List<ProcessSummaries> findByUpdateDate(LocalDateTime startOfDay, LocalDateTime endOfDay);

// find by updateType and updateDateTime
@Query("{ 'updateType': ?0, 'updateDateTime' : { $gte: ?1, $lt: ?2 } }")
List<ProcessSummaries> findByUpdateTypeAndUpdateDate(
String updateType, LocalDateTime startOfDay, LocalDateTime endOfDay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import app.dependency.update.app.model.GradlePlugin;
import app.dependency.update.app.model.Repository;
import app.dependency.update.app.model.ScriptFile;
import app.dependency.update.app.model.dto.Dependencies;
import app.dependency.update.app.model.dto.Plugins;
import app.dependency.update.app.model.entities.Dependencies;
import app.dependency.update.app.model.entities.Plugins;
import app.dependency.update.app.service.MongoRepoService;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import app.dependency.update.app.model.Repository;
import app.dependency.update.app.model.ScriptFile;
import app.dependency.update.app.model.dto.Packages;
import app.dependency.update.app.model.entities.Packages;
import app.dependency.update.app.service.MongoRepoService;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -119,9 +120,11 @@ private void checkRepositoryPrMergeRelated(final String output) {
boolean isPrMerged = checkPrMerged(output);
if (isPrMerged) {
// GITHUB_MERGE does not include repository name in threadName
String repoName = findRepoNameForPrMerge(output);
if (!isEmpty(repoName)) {
updateProcessedRepositoriesToPrMerged(repoName);
List<String> repoNames = findRepoNamesForPrMerge(output);
if (!isEmpty(repoNames)) {
for (String repoName : repoNames) {
updateProcessedRepositoriesToPrMerged(repoName);
}
}
}
}
Expand Down Expand Up @@ -153,16 +156,18 @@ private boolean checkPrCreationError(final String output, final String repoName)
}

private boolean checkPrMerged(final String output) {
return output.contains("Merged PR") && !output.contains("already merged");
return output.contains("Merged PR");
}

private String findRepoNameForPrMerge(final String output) {
String regex = "Merging PR: .*/([^/\\s]+)";
Pattern pattern = Pattern.compile(regex);
private List<String> findRepoNamesForPrMerge(final String output) {
List<String> repoNames = new ArrayList<>();
String regex = "^Merged PR: (?!.*already merged).*/([^/\\s]+)";
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(output);
if (matcher.find()) {
return matcher.group(1);
while (matcher.find()) {
String matcherGroup = matcher.group(1);
repoNames.add(matcherGroup);
}
return null;
return repoNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import app.dependency.update.app.model.AppInitData;
import app.dependency.update.app.model.Repository;
import app.dependency.update.app.model.ScriptFile;
import app.dependency.update.app.model.dto.NpmSkips;
import app.dependency.update.app.model.entities.NpmSkips;
import app.dependency.update.app.service.MongoRepoService;
import app.dependency.update.app.util.ProcessUtils;
import java.time.LocalDate;
Expand Down
Loading

0 comments on commit a5a42a1

Please sign in to comment.