Skip to content

Commit

Permalink
feat: Refactor database handling for analyzer logic (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jan 5, 2024
1 parent 1146e13 commit 43efc59
Show file tree
Hide file tree
Showing 34 changed files with 376 additions and 1,059 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package io.github.martinwitt.laughing_train.domain.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class GitHubCommit implements Serializable {

private String commitHash;
private List<AnalyzerStatus> analyzerStatuses;

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

/**
* @param commitHash
* @param analyzerStatuses
*/
public GitHubCommit(String commitHash, List<AnalyzerStatus> analyzerStatuses) {
public GitHubCommit(String commitHash) {
this.commitHash = commitHash;
this.analyzerStatuses = analyzerStatuses;
}

/**
Expand All @@ -39,34 +29,21 @@ public void setCommitHash(String commitHash) {
this.commitHash = commitHash;
}

/**
* @return the analyzerStatuses
*/
public List<AnalyzerStatus> getAnalyzerStatuses() {
return analyzerStatuses;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GitHubCommit that = (GitHubCommit) o;
return Objects.equals(commitHash, that.commitHash);
}

/**
* @param analyzerStatuses the analyzerStatuses to set
*/
public void setAnalyzerStatuses(List<AnalyzerStatus> analyzerStatuses) {
this.analyzerStatuses = analyzerStatuses;
@Override
public int hashCode() {
return Objects.hash(commitHash);
}

public void addAnalyzerStatus(AnalyzerStatus analyzerStatus) {
analyzerStatuses.stream()
.filter(v -> v.getCommitHash().equals(analyzerStatus.getCommitHash()))
.filter(v -> v.getAnalyzerName().equals(analyzerStatus.getAnalyzerName()))
.findFirst()
.ifPresentOrElse(
v -> {
analyzerStatuses.remove(v);
analyzerStatuses.add(analyzerStatus);
},
() -> analyzerStatuses.add(analyzerStatus));
if (analyzerStatuses.size() > 10) {
analyzerStatuses.sort(Comparator.comparing(v -> LocalDateTime.parse(v.getLocalDateTime())));
analyzerStatuses.removeFirst();
}
@Override
public String toString() {
return "GitHubCommit{" + "commitHash='" + commitHash + '\'' + '}';
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,19 @@ public void addCommitHash(GitHubCommit commit) {
commits.add(commit);
}

/**
* (non-Javadoc)
*
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return Objects.hash(projectName, projectUrl);
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RemoteProject that = (RemoteProject) obj;
return Objects.equals(projectName, that.projectName)
&& Objects.equals(projectUrl, that.projectUrl)
&& Objects.equals(commits, that.commits);
}

/**
* (non-Javadoc)
*
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof RemoteProject project) {
return Objects.equals(projectName, project.projectName)
&& Objects.equals(projectUrl, project.projectUrl);
}
return false;
public int hashCode() {
return Objects.hash(projectName, projectUrl, commits);
}

public RemoteProject withProjectUrl(String projectUrl) {
Expand Down
23 changes: 1 addition & 22 deletions frontend/src/ProjectData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ export const fetchProjectQuery = gql`
projectName
projectUrl
commits {
analyzerStatuses {
analyzerName
commitHash
localDateTime
numberOfIssues
status
}
commitHash
}
}
}
`;
export const recentAnalyzerRuns = gql`
query recentAnalyzerRuns {
recentAnalyzerRuns(size: 30) {
recentRuns(size: 30) {
analyzerName
commitHash
numberOfIssues
Expand Down Expand Up @@ -105,17 +98,3 @@ export function filterDuplicateBadSmells(params: BadSmell[]) {
);
}

export const getGitHubCommitsQuery = gql`
query getGitHubCommitsForProject($projectName: String!) {
getGitHubCommitsForProject(projectName: $projectName) {
analyzerStatuses {
analyzerName
commitHash
localDateTime
numberOfIssues
status
}
commitHash
}
}
`;
30 changes: 0 additions & 30 deletions frontend/src/component/ProjectList.tsx

This file was deleted.

Loading

0 comments on commit 43efc59

Please sign in to comment.