forked from wildfly/wildfly-github-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriagePullRequestProcessor.java
61 lines (50 loc) · 2.25 KB
/
TriagePullRequestProcessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package io.xstefank.wildfly.bot;
import io.quarkiverse.githubapp.ConfigFile;
import io.quarkiverse.githubapp.event.PullRequest;
import io.xstefank.wildfly.bot.config.WildFlyBotConfig;
import io.xstefank.wildfly.bot.model.RuntimeConstants;
import io.xstefank.wildfly.bot.model.WildFlyConfigFile;
import io.xstefank.wildfly.bot.model.WildFlyConfigFile.WildFlyRule;
import io.xstefank.wildfly.bot.util.GithubProcessor;
import io.xstefank.wildfly.bot.util.Matcher;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GitHub;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RequestScoped
public class TriagePullRequestProcessor {
private static final Logger LOG = Logger.getLogger(TriagePullRequestProcessor.class);
@Inject
WildFlyBotConfig wildFlyBotConfig;
@Inject
GithubProcessor githubProcessor;
void onPullRequestOpened(@PullRequest.Opened GHEventPayload.PullRequest pullRequestPayload,
@ConfigFile(RuntimeConstants.CONFIG_FILE_NAME) WildFlyConfigFile wildflyBotConfigFile,
GitHub gitHub) throws IOException {
if (wildflyBotConfigFile == null) {
LOG.error("No configuration file available.");
return;
}
GHPullRequest pullRequest = pullRequestPayload.getPullRequest();
List<String> mentions = new ArrayList<>();
if (wildflyBotConfigFile.wildfly.rules != null) {
for (WildFlyRule rule : wildflyBotConfigFile.wildfly.rules) {
if (Matcher.matches(pullRequest, rule)) {
LOG.infof("Pull Request %s was matched with a rule with the id: %s.", pullRequest.getTitle(),
rule.id != null ? rule.id : "N/A");
for (String nick : rule.notify) {
if (!nick.equals(pullRequest.getUser().getLogin()) && !mentions.contains(nick)) {
mentions.add(nick);
}
}
}
}
}
githubProcessor.processMentions(pullRequest, gitHub, mentions);
}
}