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

Added config for excluding specific issues #11

Merged
merged 1 commit into from
Nov 23, 2024
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
@@ -1,9 +1,11 @@
package com.openelements.issues.config;

import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

public record RepositoryProperty(@NonNull String org, @NonNull String repo) {
public record RepositoryProperty(@NonNull String org, @NonNull String repo, @Nullable List<String> excludeIdentifiers) {

public RepositoryProperty {
Objects.requireNonNull(org, "org must not be null");
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/openelements/issues/services/GitHubCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -47,10 +48,10 @@ public GitHubCache(@NonNull final IssueServiceProperties properties, final GitHu
log.info("Updating cache");
final List<RepositoryProperty> repos = properties.getRepositories();
repos.forEach(repo -> updateContributors(repo.org(), repo.repo()));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), GOOD_FIRST_ISSUE_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), GOOD_FIRST_ISSUE_CANDIDATE_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), HACKTOBERFEST_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), HELP_WANTED_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), repo.excludeIdentifiers(), GOOD_FIRST_ISSUE_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), repo.excludeIdentifiers(), GOOD_FIRST_ISSUE_CANDIDATE_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(),repo.excludeIdentifiers(), HACKTOBERFEST_LABEL));
repos.forEach(repo -> updateIssues(repo.org(), repo.repo(), repo.excludeIdentifiers(), HELP_WANTED_LABEL));
log.info("Cache updated. Found {} contributors and {} issues", getContributors().size(), getAllIssues().size());
} catch (final Exception e) {
log.error("Failed to update cache", e);
Expand All @@ -70,11 +71,11 @@ private void updateContributors(@NonNull final String org, @NonNull final String
}
}

private void updateIssues(@NonNull final String org, @NonNull final String repo, @NonNull final String label) {
private void updateIssues(@NonNull final String org, @NonNull final String repo, @Nullable List<String> excludedIdentifiers, @NonNull final String label) {
try {
log.info("Updating issues cache for repo '{}/{}' with label '{}'", org, repo, label);
final Repository repository = gitHubClient.getRepository(org, repo);
final List<Issue> issues = gitHubClient.getIssues(repository, label);
final List<Issue> issues = gitHubClient.getIssues(repository, label, excludedIdentifiers);
log.info("Found {} issues for repo '{}/{}' with label '{}'", issues.size(), org, repo, label);
this.issuesCache.put(hash(org, repo, label), issues);
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -95,7 +96,7 @@ public Repository getRepository(@NonNull final String org, @NonNull final String
return new Repository(org, repo, imageUrl, languageTags);
}

public List<Issue> getIssues(@NonNull final Repository repository, @NonNull final String label) {
public List<Issue> getIssues(@NonNull final Repository repository, @NonNull final String label, @Nullable List<String> excludedIdentifiers) {
Objects.requireNonNull(repository, "repository must not be null");
Objects.requireNonNull(label, "label must not be null");
final List<Issue> issues = new ArrayList<>();
Expand Down Expand Up @@ -161,7 +162,9 @@ public List<Issue> getIssues(@NonNull final Repository repository, @NonNull fina


final Issue issue = new Issue(title, Integer.valueOf(number).toString(), repository, url, isAssigned, isClosed, labels);
issues.add(issue);
if (excludedIdentifiers == null || !excludedIdentifiers.contains(issue.identifier())) {
issues.add(issue);
}
});
return Collections.unmodifiableList(issues);
}
Expand Down
Loading