Skip to content

Commit

Permalink
fix: fixed repository download (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich authored Oct 10, 2024
1 parent 26cf462 commit db205a2
Show file tree
Hide file tree
Showing 24 changed files with 441 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up JDK 23
- name: "Set up JDK 23"
uses: oracle-actions/setup-java@v1
with:
website: oracle.com
Expand Down
14 changes: 10 additions & 4 deletions api-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>api-server</artifactId>
<version>1.0-SNAPSHOT</version>
Expand Down Expand Up @@ -104,6 +104,10 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
Expand Down Expand Up @@ -236,7 +240,9 @@
<typeMapping>file=byte[]</typeMapping>
</typeMappings>
<configOptions>
<additionalModelTypeAnnotations>@lombok.Data @lombok.NoArgsConstructor @lombok.AllArgsConstructor(staticName = "of")</additionalModelTypeAnnotations>
<additionalModelTypeAnnotations>@lombok.Data
@lombok.NoArgsConstructor @lombok.AllArgsConstructor(staticName
= "of")</additionalModelTypeAnnotations>
<sourceFolder>src/main/java</sourceFolder>
<unhandledException>true</unhandledException>
<serializableModel>true</serializableModel>
Expand Down Expand Up @@ -322,4 +328,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.repoachiever.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

/**
* Represents retrieved GitHub repository details.
*/
@Getter
@ApplicationScoped
public class GitHubRepositoriesDto {
/**
* Represents remote repository short name.
*/
@Valid
@NotNull
@JsonProperty("name")
public String name;

/**
* Represents remote repository default branch.
*/
@Valid
@NotNull
@JsonProperty("default_branch")
public String defaultBranch;
}
22 changes: 22 additions & 0 deletions api-server/src/main/java/com/repoachiever/dto/GitHubUserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.repoachiever.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

/**
* Represents retrieved GitHub user details.
*/
@Getter
@ApplicationScoped
public class GitHubUserDto {
/**
* Represents user name.
*/
@Valid
@NotNull
@JsonProperty("login")
public String login;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;

/**
Expand Down Expand Up @@ -189,11 +188,6 @@ public static class Cluster {
@Getter
public static class Worker {
@NotNull
@Pattern(
regexp =
"(((([0-9]|[0-5][0-9])(-([0-9]|[0-5][0-9]))?,)*([0-9]|[0-5][0-9])(-([0-9]|[0-5][0-9]))?)|(([\\*]|[0-9]|[0-5][0-9])/([0-9]|[0-5][0-9]))|([\\?])|([\\*]))[\\s](((([0-9]|[0-5][0-9])(-([0-9]|[0-5][0-9]))?,)*([0-9]|[0-5][0-9])(-([0-9]|[0-5][0-9]))?)|(([\\*]|[0-9]|[0-5][0-9])/([0-9]|[0-5][0-9]))|([\\?])|([\\*]))[\\s](((([0-9]|[0-1][0-9]|[2][0-3])(-([0-9]|[0-1][0-9]|[2][0-3]))?,)*([0-9]|[0-1][0-9]|[2][0-3])(-([0-9]|[0-1][0-9]|[2][0-3]))?)|(([\\*]|[0-9]|[0-1][0-9]|[2][0-3])/([0-9]|[0-1][0-9]|[2][0-3]))|([\\?])|([\\*]))[\\s](((([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1])(-([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1]))?,)*([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1])(-([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1]))?(C)?)|(([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1])/([1-9]|[0][1-9]|[1-2][0-9]|[3][0-1])(C)?)|(L(-[0-9])?)|(L(-[1-2][0-9])?)|(L(-[3][0-1])?)|(LW)|([1-9]W)|([1-3][0-9]W)|([\\?])|([\\*]))[\\s](((([1-9]|0[1-9]|1[0-2])(-([1-9]|0[1-9]|1[0-2]))?,)*([1-9]|0[1-9]|1[0-2])(-([1-9]|0[1-9]|1[0-2]))?)|(([1-9]|0[1-9]|1[0-2])/([1-9]|0[1-9]|1[0-2]))|(((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?,)*(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)|((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)/(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))|([\\?])|([\\*]))[\\s]((([1-7](-([1-7]))?,)*([1-7])(-([1-7]))?)|([1-7]/([1-7]))|(((MON|TUE|WED|THU|FRI|SAT|SUN)(-(MON|TUE|WED|THU|FRI|SAT|SUN))?,)*(MON|TUE|WED|THU|FRI|SAT|SUN)(-(MON|TUE|WED|THU|FRI|SAT|SUN))?(C)?)|((MON|TUE|WED|THU|FRI|SAT|SUN)/(MON|TUE|WED|THU|FRI|SAT|SUN)(C)?)|(([1-7]|(MON|TUE|WED|THU|FRI|SAT|SUN))?(L|LW)?)|(([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN)#([1-7])?)|([\\?])|([\\*]))([\\s]?(([\\*])?|(19[7-9][0-9])|(20[0-9][0-9]))?|"
+ " (((19[7-9][0-9])|(20[0-9][0-9]))/((19[7-9][0-9])|(20[0-9][0-9])))?|"
+ " ((((19[7-9][0-9])|(20[0-9][0-9]))(-((19[7-9][0-9])|(20[0-9][0-9])))?,)*((19[7-9][0-9])|(20[0-9][0-9]))(-((19[7-9][0-9])|(20[0-9][0-9])))?)?)")
@JsonProperty("frequency")
public String frequency;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public class PropertiesEntity {
@ConfigProperty(name = "quarkus.rest-client.github.url")
String restClientGitHubUrl;

@ConfigProperty(name = "rest-client.github.page-size")
Integer restClientGitHubPageSize;

@ConfigProperty(name = "rest-client.github.max-page")
Integer restClientGitHubMaxPage;

@ConfigProperty(name = "rest-client.github.repo-visibility")
String restClientGitHubRepoVisibility;

@ConfigProperty(name = "github.location.notation")
String gitHubLocationNotation;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.repoachiever.exception;

import java.io.IOException;
import java.util.Arrays;
import java.util.Formatter;

/**
* Represents exception used when configuration file cron expression validation
* process fails.
*/
public class ConfigCronExpressionValidationException extends IOException {
public ConfigCronExpressionValidationException() {
this("");
}

public ConfigCronExpressionValidationException(Object... message) {
super(
new Formatter()
.format("Config file cron expression is not valid: %s", Arrays.stream(message).toArray())
.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
Expand All @@ -24,12 +25,13 @@ public interface IGitHubClientService {
Response getPermissionScopes(@HeaderParam(HttpHeaders.AUTHORIZATION) String token);

@GET
@Path("/repos/{owner}/{name}}")
@Path("/user/repos")
@Produces(MediaType.APPLICATION_JSON)
Response getRepository(
Response getRepositories(
@HeaderParam(HttpHeaders.AUTHORIZATION) String token,
@PathParam("owner") String owner,
@PathParam("name") String name);
@QueryParam("per_page") Integer perPage,
@QueryParam("page") Integer page,
@QueryParam("visibility") String visibility);

@GET
@Path("/repos/{owner}/{name}/branches/{branch}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ public void destroy(ContentWithdrawal contentWithdrawal) throws ClusterWithdrawa
logger.info(
String.format("Removing RepoAchiever Cluster allocation: '%s'", clusterAllocation.getName()));

System.out.println(clusterAllocation.getPid());

try {
clusterService.destroy(clusterAllocation.getPid());
} catch (ClusterDestructionFailureException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.repoachiever.entity.common.ConfigEntity;
import com.repoachiever.entity.common.PropertiesEntity;
import com.repoachiever.exception.ConfigCronExpressionValidationException;
import com.repoachiever.exception.ConfigFileClosureFailureException;
import com.repoachiever.exception.ConfigFileNotFoundException;
import com.repoachiever.exception.ConfigFileReadingFailureException;
Expand All @@ -28,11 +29,14 @@
import java.util.stream.Collectors;

import lombok.Getter;

import org.apache.logging.log4j.core.util.CronExpression;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Service used to perform RepoAchiever API Server configuration processing operation.
* Service used to perform RepoAchiever API Server configuration processing
* operation.
*/
@Startup
@ApplicationScoped
Expand All @@ -44,16 +48,19 @@ public class ConfigService {
private ConfigEntity config;

/**
* Reads configuration from the opened configuration file using mapping with a configuration entity.
* Reads configuration from the opened configuration file using mapping with a
* configuration entity.
*
* @throws ConfigFileNotFoundException if configuration file is not found.
* @throws ConfigValidationException if configuration file operation failed.
* @throws ConfigFileReadingFailureException if configuration file reading operation failed.
* @throws ConfigFileClosureFailureException if configuration file closure operation failed.
* @throws ConfigFileNotFoundException if configuration file is not found.
* @throws ConfigValidationException if configuration file operation
* failed.
* @throws ConfigFileReadingFailureException if configuration file reading
* operation failed.
* @throws ConfigFileClosureFailureException if configuration file closure
* operation failed.
*/
@PostConstruct
private void configure() throws
ConfigFileNotFoundException,
private void configure() throws ConfigFileNotFoundException,
ConfigValidationException,
ConfigFileReadingFailureException,
ConfigFileClosureFailureException {
Expand All @@ -66,11 +73,10 @@ private void configure() throws
throw new ConfigFileNotFoundException(e.getMessage());
}

ObjectMapper mapper =
new ObjectMapper(new YAMLFactory())
.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
ObjectMapper mapper = new ObjectMapper(new YAMLFactory())
.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ObjectReader reader = mapper.reader().forType(new TypeReference<ConfigEntity>() {
});
Expand All @@ -89,8 +95,7 @@ private void configure() throws
try (ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory()) {
Validator validator = validatorFactory.getValidator();

Set<ConstraintViolation<ConfigEntity>> validationResult =
validator.validate(config);
Set<ConstraintViolation<ConfigEntity>> validationResult = validator.validate(config);

if (!validationResult.isEmpty()) {
throw new ConfigValidationException(
Expand All @@ -99,6 +104,12 @@ private void configure() throws
.collect(Collectors.joining(", ")));
}
}

if (!CronExpression.isValidExpression(
config.getResource().getWorker().getFrequency())) {
throw new ConfigValidationException(
new ConfigCronExpressionValidationException().getMessage());
}
} finally {
try {
file.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -44,7 +45,9 @@ public GitHubLocationNotationDto parseLocationGitHubNotation(String location) {

matcher.find();

if (matcher.groupCount() == 4) {
String optionalMatch = matcher.group(4);

if (matcher.groupCount() == 4 && Objects.nonNull(optionalMatch)) {
return GitHubLocationNotationDto.of(
matcher.group(1),
matcher.group(2),
Expand Down
Loading

0 comments on commit db205a2

Please sign in to comment.