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

feat: switch mongodb to mariadb #1240

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AnalyzerStatus() {
// for JPA
}

AnalyzerStatus(
public AnalyzerStatus(
String analyzerName,
Status status,
int numberOfIssues,
Expand All @@ -38,7 +38,7 @@ public static AnalyzerStatus failure(String analyzerName, int numberOfIssues, St
analyzerName, Status.FAILURE, numberOfIssues, commitHash, LocalDateTime.now());
}

enum Status {
public enum Status {
SUCCESS,
FAILURE
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.martinwitt.laughing_train.domain.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class GitHubCommit implements Serializable {
Expand All @@ -9,6 +11,7 @@ public class GitHubCommit implements Serializable {
private List<AnalyzerStatus> analyzerStatuses;

public GitHubCommit() {
analyzerStatuses = new ArrayList<>();
// for JPA
}

Expand Down Expand Up @@ -59,8 +62,10 @@ public void addAnalyzerStatus(AnalyzerStatus analyzerStatus) {
analyzerStatuses.remove(v);
analyzerStatuses.add(analyzerStatus);
},
() -> {
analyzerStatuses.add(analyzerStatus);
});
() -> analyzerStatuses.add(analyzerStatus));
if (analyzerStatuses.size() > 10) {
analyzerStatuses.sort(Comparator.comparing(AnalyzerStatus::getLocalDateTime));
analyzerStatuses.removeFirst();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public List<GitHubCommit> getCommits() {
}

public boolean addCommitHash(GitHubCommit commit) {
addCommitHash(commit.getCommitHash());
return commits.add(commit);
}

Expand Down
10 changes: 6 additions & 4 deletions github-bot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ plugins {
}

dependencies {
implementation 'io.quarkiverse.jgit:quarkus-jgit:3.0.5'
implementation 'io.quarkiverse.jgit:quarkus-jgit:3.0.5'
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkiverse.githubapi:quarkus-github-api:1.316.0'
implementation 'io.quarkus:quarkus-arc'
implementation "io.quarkus:quarkus-scheduler"
implementation 'io.quarkus:quarkus-smallrye-health'
implementation project(path: ':spoon-analyzer')
testImplementation 'io.quarkus:quarkus-junit5'
implementation project(path: ':spoon-analyzer')
testImplementation 'io.quarkus:quarkus-junit5'
implementation project(":code-transformation")
implementation 'io.quarkus:quarkus-mongodb-panache:3.5.1'
annotationProcessor("io.quarkus:quarkus-panache-common")
implementation("io.quarkus:quarkus-smallrye-graphql")
implementation("io.quarkus:quarkus-smallrye-graphql-client")
Expand All @@ -28,6 +27,9 @@ dependencies {
implementation "io.quarkiverse.loggingmanager:quarkus-logging-manager:3.0.2"
testImplementation 'org.mockito:mockito-core:5.7.0'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.3'
annotationProcessor("io.quarkus:quarkus-panache-common")
implementation("io.quarkus:quarkus-hibernate-orm-panache")
implementation("io.quarkus:quarkus-jdbc-mariadb")
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.github.martinwitt.laughing_train.api.graphql.endpoints;

import com.google.common.flogger.FluentLogger;
import io.github.martinwitt.laughing_train.api.graphql.dto.ProjectConfigGraphQLDto;
import io.github.martinwitt.laughing_train.api.graphql.dto.ProjectConfigGraphQLDtoInput;
import io.github.martinwitt.laughing_train.api.graphql.dto.ProjectGraphQLDto;
import io.github.martinwitt.laughing_train.domain.entity.GitHubCommit;
import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig;
import io.github.martinwitt.laughing_train.domain.entity.RemoteProject;
import io.github.martinwitt.laughing_train.mining.QodanaPeriodicMiner;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectConfigRepository;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.github.martinwitt.laughing_train.services.ProjectConfigService;
import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
import java.util.List;
Expand All @@ -25,12 +22,8 @@ public class ProjectGraphQL {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();

@Inject ProjectConfigService projectConfigService;

@Inject ProjectRepository projectRepository;

@Inject ProjectConfigRepository projectConfigRepository;

@Inject QodanaPeriodicMiner periodicMiner;

@Query("getProjects")
Expand Down Expand Up @@ -97,34 +90,6 @@ public String login(@DefaultValue("defaultValue") String notNeeded) {
return "login successful";
}

@Query("getProjectConfig")
@Description("Gets the project config for a project")
public ProjectConfigGraphQLDto getProjectConfig(String projectUrl) {
return projectConfigRepository.findByProjectUrl(projectUrl).stream()
.findFirst()
.map(ProjectConfigGraphQLDto::new)
.orElseThrow();
}

@Mutation
@Authenticated
@Description("Sets the project config for a project")
public ProjectConfigGraphQLDto setProjectConfig(ProjectConfigGraphQLDtoInput projectConfig) {
var existingConfig =
projectConfigRepository.findByProjectUrl(projectConfig.getProjectUrl()).stream()
.findFirst();
if (existingConfig.isPresent()) {
var config = createConfigFromInput(projectConfig);
projectConfigRepository.deleteByProjectUrl(projectConfig.getProjectUrl());
projectConfigRepository.create(config);
return new ProjectConfigGraphQLDto(config);
} else {
var config = createConfigFromInput(projectConfig);
projectConfigRepository.create(config);
return new ProjectConfigGraphQLDto(config);
}
}

private ProjectConfig createConfigFromInput(ProjectConfigGraphQLDtoInput projectConfig) {
var config = ProjectConfig.ofProjectUrl(projectConfig.getProjectUrl());
config.setSourceFolder(config.getSourceFolder());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.github.martinwitt.laughing_train.mining;

import com.google.common.flogger.FluentLogger;
import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig;
import io.github.martinwitt.laughing_train.domain.entity.RemoteProject;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectConfigRepository;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.quarkus.logging.Log;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -28,14 +26,11 @@ public class SearchProjectService {
private final Random random = new Random();
List<String> orgs;
ProjectRepository projectRepository;
ProjectConfigRepository projectConfigRepository;

public SearchProjectService(
ProjectRepository projectRepository,
ProjectConfigRepository projectConfigRepository,
@ConfigProperty(name = "mining.github.search.orgs") List<String> orgs) {
this.projectRepository = projectRepository;
this.projectConfigRepository = projectConfigRepository;
this.orgs = orgs;
}

Expand Down Expand Up @@ -91,10 +86,6 @@ private RemoteProject persistProject(RemoteProject project) {

private void persistProjectConfigIfMissing(RemoteProject project) {
String projectUrl = project.getProjectUrl();
var projectConfig = projectConfigRepository.findByProjectUrl(projectUrl);
if (projectConfig.isEmpty()) {
projectConfigRepository.create(ProjectConfig.ofProjectUrl(projectUrl));
}
}

private @Nullable GHRepository findRandomRepositoryOnGithub() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@

public class BadSmell implements AnalyzerResult {

private String analyzer;
private String identifier;
private String ruleID;
private String filePath;
private String message;
private String messageMarkdown;
private String snippet;
private String projectName;
private String projectUrl;
private String commitHash;
private Position position;
private final String analyzer;
private final String identifier;
private final String ruleID;
private final String filePath;
private final String message;
private final String messageMarkdown;
private final String snippet;
private final String projectName;
private final String projectUrl;
private final String commitHash;
private final Position position;

public BadSmell(AnalyzerResult result, String projectName, String projectUrl, String commitHash) {
this.position = result.position();
this.ruleID = result.ruleID().id();
this.filePath = result.filePath();
this.message = result.message();
this.messageMarkdown = result.messageMarkdown();
this.snippet = result.snippet();
position = result.position();
ruleID = result.ruleID().id();
filePath = result.filePath();
message = result.message();
messageMarkdown = result.messageMarkdown();
snippet = result.snippet();
this.projectName = projectName;
this.projectUrl = projectUrl;
this.commitHash = commitHash;
this.identifier = generateIdentifier(result, projectName, commitHash);
this.analyzer = result.getAnalyzer();
identifier = generateIdentifier(result, projectName, commitHash);
analyzer = result.getAnalyzer();
}

public static String generateIdentifier(
Expand Down Expand Up @@ -164,8 +164,4 @@ private static String positionToString(Position position) {
position.charOffset(),
position.charLength());
}

public BadSmell withProjectUrl(String projectUrl) {
return new BadSmell(this, projectName, projectUrl, commitHash);
}
}
Loading
Loading