Skip to content

Commit

Permalink
Disregard comments from the bot itself
Browse files Browse the repository at this point in the history
  • Loading branch information
grdryn committed Apr 5, 2023
1 parent ee93538 commit a23ecf8
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
package org.bf2.arch.bot;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.Optional;
import java.util.Set;

import io.quarkiverse.githubapp.runtime.github.GitHubService;
import io.quarkus.scheduler.Scheduled;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.kohsuke.github.GHDirection;
import org.kohsuke.github.GHIssue;
Expand All @@ -34,6 +34,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.quarkiverse.githubapp.ConfigFile;
import io.quarkiverse.githubapp.GitHubConfigFileProvider;
import io.quarkiverse.githubapp.runtime.github.GitHubService;
import io.quarkus.scheduler.Scheduled;

@ApplicationScoped
public class StalledDiscussionFlow {

Expand All @@ -52,16 +57,20 @@ public class StalledDiscussionFlow {
private Date lastRan = new Date(0);

GitHub client;
//ArchBotConfig config;
ArchBotConfig config;

@Inject
void init(GitHubService service) {
void init(GitHubService service, GitHubConfigFileProvider configFileProvider) throws IOException {
if (!enabled) {
LOG.debug("Ignoring init: disabled due to {}=false", ENABLE);
} else if (installationId != null) {
// TODO parameterise this installationId
client = service.getInstallationClient(installationId);
// TODO load the config

Optional<ArchBotConfig> oconfig = configFileProvider.fetchConfigFile(client.getRepository(repositoryPath),
Util.CONFIG_REPO_PATH, ConfigFile.Source.DEFAULT, ArchBotConfig.class);
config = oconfig.orElseThrow();
LOG.info("CONFIGG: {}", config);
} else {
throw new RuntimeException("installation id is requied");
}
Expand Down Expand Up @@ -112,14 +121,8 @@ public void checkForStalledDiscussions() throws IOException {
.order(GHDirection.ASC)
.list();
LOG.info("Top-level query found {} PRs", results.getTotalCount());
int processed = 0;
for (GHIssue issue : results) {
// if () {
// lastRan = new Date();
// break;
// }
processed++;
try {
try {
GHPullRequest pullRequest = Util.findPullRequest(issue);
if (pullRequest == null) {
LOG.info("Issue#{} is not a PR, ignoring", issue.getNumber());
Expand All @@ -132,14 +135,15 @@ public void checkForStalledDiscussions() throws IOException {
// https://docs.github.com/en/rest/pulls/comments#list-review-comments-in-a-repository
// but the client doesn't expose them
Date lastCommentDate;
LOG.info("COMMENTS COUNT: {}", pullRequest.listReviewComments().toList().size());
var mostRecent = pullRequest.listReviewComments().toList().stream()
// .filter(pr -> {
// try {
// return !Util.isThisBot(config, pr.getUser());
// } catch (IOException e) {
// return true;
// }
// })
.filter(pr -> {
try {
return !Util.isThisBot(config, pr.getUser());
} catch (IOException e) {
return true;
}
})
.map(comment -> {
try {
LOG.info("Comment: {}", comment.getBody());
Expand Down

0 comments on commit a23ecf8

Please sign in to comment.