From c2f68344f844499992ff5ec3db2429ca5bf54e0f Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Thu, 2 Apr 2026 14:12:50 +0200 Subject: [PATCH 1/4] [ASDP-714] move to single process pull request --- pom.xml | 47 ++-- .../set/pull/processor/AbstractProcessor.java | 138 ++-------- .../org/jboss/set/pull/processor/Action.java | 6 +- .../set/pull/processor/ActionContext.java | 33 +-- .../jboss/set/pull/processor/Evaluator.java | 4 +- .../set/pull/processor/EvaluatorContext.java | 11 +- .../org/jboss/set/pull/processor/Main.java | 151 +++-------- .../jboss/set/pull/processor/Processor.java | 9 +- .../set/pull/processor/ProcessorConfig.java | 91 +++++-- .../pull/processor/ProcessorException.java | 4 + .../set/pull/processor/ProcessorPhase.java | 34 --- .../set/pull/processor/PullProcessor.java | 214 +++++++++++++++ .../processor/StreamComponentDefinition.java | 6 +- .../set/pull/processor/StreamDefinition.java | 6 +- .../set/pull/processor/data/Attribute.java | 15 ++ .../set/pull/processor/data/Attributes.java | 17 ++ .../processor/data/CodeBaseLabelItem.java | 2 +- .../pull/processor/data/EvaluatorData.java | 37 +-- .../set/pull/processor/data/IssueData.java | 2 +- .../set/pull/processor/data/LabelData.java | 2 +- .../processor/data/PullRequestReference.java | 2 +- .../processor/impl/action/ReportAction.java | 20 +- .../impl/action/SetLabelsAction.java | 253 ++++++++---------- .../AbstractIssuesLinkEvaluator.java | 92 +++++++ .../evaluator/AbstractLabelEvaluator.java | 9 +- .../evaluator/CurrentIssuesLinkEvaluator.java | 28 ++ .../evaluator/DevStreamLabelEvaluator.java | 13 +- .../IssueACKFlagsLabelEvaluator.java | 21 +- .../evaluator/IssuePresentLabelEvaluator.java | 19 +- .../impl/evaluator/LinkedIssuesEvaluator.java | 123 --------- .../evaluator/LinkedPullRequestEvaluator.java | 49 ++-- .../evaluator/RelatedIssuesLinkEvaluator.java | 26 ++ .../impl/evaluator/TriviaEvaluator.java | 47 ---- .../UpstreamIssuesLinkEvaluator.java | 28 ++ .../UpstreamPullRequestLabelEvaluator.java | 67 ++--- .../evaluator/util/StreamDefinitionUtil.java | 39 +-- .../impl/process/OpenPRProcessor.java | 67 +---- .../org.jboss.set.pull.processor.Evaluator | 5 +- 38 files changed, 826 insertions(+), 911 deletions(-) delete mode 100644 src/main/java/org/jboss/set/pull/processor/ProcessorPhase.java create mode 100644 src/main/java/org/jboss/set/pull/processor/PullProcessor.java create mode 100644 src/main/java/org/jboss/set/pull/processor/data/Attribute.java create mode 100644 src/main/java/org/jboss/set/pull/processor/data/Attributes.java create mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/AbstractIssuesLinkEvaluator.java create mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/CurrentIssuesLinkEvaluator.java delete mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/LinkedIssuesEvaluator.java create mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/RelatedIssuesLinkEvaluator.java delete mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/TriviaEvaluator.java create mode 100644 src/main/java/org/jboss/set/pull/processor/impl/evaluator/UpstreamIssuesLinkEvaluator.java diff --git a/pom.xml b/pom.xml index eae7111..05606e5 100644 --- a/pom.xml +++ b/pom.xml @@ -17,18 +17,15 @@ UTF-8 - 17 - 17 - + 21 2.15 - 1.1.6.Final 1.0.8.Final - 0.7.22.Final + 1.0.0.Final 2.3.23 0.7.0 - 1.9.5 + 2.0.17 @@ -39,6 +36,16 @@ + + org.slf4j + slf4j-api + ${version.org.slf4j} + + + org.slf4j + slf4j-simple + ${version.org.slf4j} + org.jboss.set jboss-aphrodite-common @@ -74,22 +81,11 @@ jboss-aphrodite-simplecontainer ${version.org.jboss.set.aphrodite} - - org.freemarker - freemarker - ${version.org.freemarker.freemarker} - net.sourceforge.argparse4j argparse4j ${version.net.sourceforge.argparse4j} - - org.mockito - mockito-core - ${version.mockito} - test - @@ -124,6 +120,23 @@ + + org.apache.maven.plugins + maven-dependency-plugin + + + verify-dependencies + + analyze-only + + verify + + true + true + + + + org.apache.maven.plugins maven-shade-plugin diff --git a/src/main/java/org/jboss/set/pull/processor/AbstractProcessor.java b/src/main/java/org/jboss/set/pull/processor/AbstractProcessor.java index e5c8721..ab043ea 100644 --- a/src/main/java/org/jboss/set/pull/processor/AbstractProcessor.java +++ b/src/main/java/org/jboss/set/pull/processor/AbstractProcessor.java @@ -21,17 +21,13 @@ */ package org.jboss.set.pull.processor; -import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; import org.jboss.set.aphrodite.domain.PullRequest; import org.jboss.set.pull.processor.data.EvaluatorData; import org.jboss.set.pull.processor.data.PullRequestReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Abstract class. Base for processors. Provide basic code to allow simpler processor dev. @@ -39,130 +35,46 @@ * @author baranowb * */ -@SuppressWarnings("static-access") public abstract class AbstractProcessor implements Processor { - protected static final Logger LOGGER = Logger.getLogger(AbstractProcessor.class.getPackage().getName()); + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractProcessor.class); protected ProcessorConfig processorConfig; - // protected Collection permitedBranches; - protected final String simpleName; - - public AbstractProcessor() { - super(); - this.simpleName = getClass().getSimpleName(); - } public void init(final ProcessorConfig processorConfig) { assert processorConfig != null; this.processorConfig = processorConfig; } - /** - * Returh phase for which implementation will work. This is used to pick proper evaluators and actions - * - * @return - */ - public abstract ProcessorPhase getPhase(); - - /** - * Processor can fetch PRs based on any criteria it sees fit and by any means. {@link AbstractProcessor#fetchPullRequests} - * will call it and perform some filtering. - * - * @return - */ - protected abstract List fetchPullRequestsRaw(); - - /** - * Provide basic filtering of existing PRs and matching codebase to one present in jboss streams. - */ - private List fetchPullRequests() { - // NOTE1: check if we dont leak PRs this way? - // NOTE2: do we even care if we leak them? - return fetchPullRequestsRaw().stream().filter(pr -> { - try { - if (pr.getComponentDefinition().isFound() && pr.getComponentDefinition().getStreamComponent().getCodebase() - .equals(pr.getPullRequest().getCodebase())) - return true; - else - return false; - } catch (Exception e) { - // TODO: XXX hanle it properly - log(Level.SEVERE, "Failed at: " + pr, e); - return false; - } - }).collect(Collectors.toList()); + @Override + public void process(PullRequestReference pullRequestReference) throws ProcessorException { + LOGGER.info("processing pull request {}", pullRequestReference); + executeActions(executeEvaluators(pullRequestReference)); } - public void process() throws ProcessorException { + public EvaluatorData executeEvaluators(PullRequestReference pullRequestReference) throws ProcessorException { + PullRequest pullRequest = pullRequestReference.getPullRequest(); try { - final List processedPullRequests = new ArrayList<>(); - final List pullRequests = fetchPullRequests(); - log(Level.INFO, " processing: " + pullRequests.size() + " PRs"); - List> results = this.processorConfig.getExecutorService() - .invokeAll(pullRequests.stream() - .map(e -> new PullRequestEvaluatorTask(e.getPullRequest(), e.getComponentDefinition())) - .collect(Collectors.toList())); - - for (Future result : results) { - try { - processedPullRequests.add(result.get()); - } catch (Exception ex) { - log(Level.SEVERE, "ouch !", ex); - } - } - - log(Level.INFO, "executing actions:"); - List actions = this.processorConfig.getActions(); - ActionContext actionContext = new ActionContext(this.processorConfig); - for (Action action : actions) { - log(Level.INFO, "...." + action.getClass().getName()); - // This means that every processor will have its own set of actions - // ie. report write will be per processor - action.execute(actionContext, processedPullRequests); + LOGGER.info("processing : {}", pullRequestReference.getPullRequest().getURI()); + EvaluatorContext context = new EvaluatorContext(processorConfig.getAphrodite(), pullRequest, pullRequestReference.getComponentDefinition()); + EvaluatorData data = new EvaluatorData(); + for (Evaluator rule : processorConfig.getEvaluators()) { + LOGGER.info("repository {} applying evaluator {} to {}", pullRequest.getRepository().getURI(), rule.name(), pullRequestReference); + rule.eval(context, data); } - } catch (InterruptedException ex) { - throw new ProcessorException("processor execution failed", ex); + return data; + } catch (Throwable th) { + LOGGER.error("failed to {}", pullRequest.getURI(), th); + throw new ProcessorException(th); } } - protected void log(final Level level, final String msg) { - this.LOGGER.log(level, this.simpleName + " " + msg); - } - - protected void log(final Level level, final String msg, final Throwable t) { - this.LOGGER.log(level, this.simpleName + " " + msg, t); - } - - private class PullRequestEvaluatorTask implements Callable { - - private final PullRequest pullRequest; - private final StreamComponentDefinition streamComponentDefinition; - - public PullRequestEvaluatorTask(final PullRequest e, final StreamComponentDefinition streamComponentDefinition) { - this.pullRequest = e; - this.streamComponentDefinition = streamComponentDefinition; - } - - @Override - public EvaluatorData call() throws Exception { - try { - log(Level.FINE, "processing " + this.pullRequest.getURL().toString()); - - EvaluatorContext context = new EvaluatorContext(processorConfig.getAphrodite(), this.pullRequest, - this.streamComponentDefinition, getPhase()); - EvaluatorData data = new EvaluatorData(); - for (Evaluator rule : processorConfig.getEvaluators()) { - LOGGER.fine("repository " + pullRequest.getRepository().getURL() + "applying evaluator " + rule.name() - + " to " + this.pullRequest.getId()); - rule.eval(context, data); - } - return data; - } catch (Throwable th) { - log(Level.SEVERE, "failed to " + this.pullRequest.getURL(), th); - throw new Exception(th); - } + private void executeActions(EvaluatorData evaluatorData) { + List actions = this.processorConfig.getActions(); + ActionContext actionContext = new ActionContext(this.processorConfig); + for (Action action : actions) { + action.execute(actionContext, evaluatorData); } - } + } diff --git a/src/main/java/org/jboss/set/pull/processor/Action.java b/src/main/java/org/jboss/set/pull/processor/Action.java index 6ed795f..6d15a2d 100644 --- a/src/main/java/org/jboss/set/pull/processor/Action.java +++ b/src/main/java/org/jboss/set/pull/processor/Action.java @@ -21,8 +21,6 @@ */ package org.jboss.set.pull.processor; -import java.util.List; - import org.jboss.set.pull.processor.data.EvaluatorData; /** @@ -33,8 +31,6 @@ */ public interface Action { - void execute(ActionContext actionContext, List data); - - boolean support(ProcessorPhase processorPhase); + void execute(ActionContext actionContext, EvaluatorData data); } diff --git a/src/main/java/org/jboss/set/pull/processor/ActionContext.java b/src/main/java/org/jboss/set/pull/processor/ActionContext.java index d59c888..0f2332a 100644 --- a/src/main/java/org/jboss/set/pull/processor/ActionContext.java +++ b/src/main/java/org/jboss/set/pull/processor/ActionContext.java @@ -22,10 +22,8 @@ package org.jboss.set.pull.processor; import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; +import java.net.URI; import java.util.List; -import java.util.concurrent.ExecutorService; import org.jboss.set.aphrodite.Aphrodite; import org.jboss.set.aphrodite.domain.PullRequest; @@ -62,32 +60,17 @@ public List getDefinedStreams() { return this.processorConfig.getStreamDefinition(); } - public ExecutorService getExecutors() { - return this.processorConfig.getExecutorService(); - } - - public boolean isWritePermitedOn(final PullRequest pullRequest) { + public boolean isWritePermitedOn(PullRequest pullRequest) { // match repo and branch vs permited write repo and branch, to see if we // should perform any write ops. - final String pullRequestBranch = pullRequest.getCodebase().getName(); - final URL repoURL = pullRequest.getRepository().getURL(); // repo will have bit without pull/\\d+ + final String pullRequestBranch = pullRequest.getCodebase().getBranch(); + final URI repoURL = pullRequest.getRepository().getURI(); // repo will have bit without pull/\\d+ for (StreamDefinition streamDefinition : this.processorConfig.getWritePermitedStreamDefinition()) { - if (!streamDefinition.isFound()) { - continue; - } for (StreamComponentDefinition streamComponentDefinition : streamDefinition.getStreamComponents()) { - if (!streamComponentDefinition.isFound()) { - continue; - } - try { - if (repoURL.toURI().equals(streamComponentDefinition.getStreamComponent().getRepositoryURL()) - && pullRequestBranch - .equals(streamComponentDefinition.getStreamComponent().getCodebase().getName())) { - return true; - } - } catch (URISyntaxException e) { - // TODO: XXX this should not happen, add proper log/info output for CI console - e.printStackTrace(); + if (repoURL.equals(streamComponentDefinition.getStreamComponent().getRepositoryURI()) + && pullRequestBranch + .equals(streamComponentDefinition.getStreamComponent().getCodebase().getBranch())) { + return true; } } } diff --git a/src/main/java/org/jboss/set/pull/processor/Evaluator.java b/src/main/java/org/jboss/set/pull/processor/Evaluator.java index 903f658..a776d46 100644 --- a/src/main/java/org/jboss/set/pull/processor/Evaluator.java +++ b/src/main/java/org/jboss/set/pull/processor/Evaluator.java @@ -29,8 +29,6 @@ default String name() { return this.getClass().getSimpleName(); } - void eval(EvaluatorContext context, EvaluatorData data) throws InterruptedException; - - boolean support(ProcessorPhase processorPhase); + void eval(EvaluatorContext context, EvaluatorData data) throws Exception; } diff --git a/src/main/java/org/jboss/set/pull/processor/EvaluatorContext.java b/src/main/java/org/jboss/set/pull/processor/EvaluatorContext.java index 90c46f8..0f538da 100644 --- a/src/main/java/org/jboss/set/pull/processor/EvaluatorContext.java +++ b/src/main/java/org/jboss/set/pull/processor/EvaluatorContext.java @@ -32,14 +32,10 @@ public class EvaluatorContext { private final StreamComponentDefinition streamComponentDefinition; - private final ProcessorPhase processorPhase; - - public EvaluatorContext(final Aphrodite aphrodite, final PullRequest pullrequest, - final StreamComponentDefinition streamComponentDefinition, final ProcessorPhase processorPhase) { + public EvaluatorContext(Aphrodite aphrodite, PullRequest pullrequest, StreamComponentDefinition streamComponentDefinition) { this.aphrodite = aphrodite; this.pullRequest = pullrequest; this.streamComponentDefinition = streamComponentDefinition; - this.processorPhase = processorPhase; } public Aphrodite getAphrodite() { @@ -51,14 +47,11 @@ public PullRequest getPullRequest() { } public String getBranch() { - return this.pullRequest.getCodebase().getName(); + return this.pullRequest.getCodebase().getBranch(); } public StreamComponentDefinition getStreamComponentDefinition() { return streamComponentDefinition; } - public ProcessorPhase getProcessorPhase() { - return this.processorPhase; - } } diff --git a/src/main/java/org/jboss/set/pull/processor/Main.java b/src/main/java/org/jboss/set/pull/processor/Main.java index f8bba92..d7d356c 100644 --- a/src/main/java/org/jboss/set/pull/processor/Main.java +++ b/src/main/java/org/jboss/set/pull/processor/Main.java @@ -22,18 +22,9 @@ package org.jboss.set.pull.processor; import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.logging.Logger; -import java.util.stream.Collectors; +import java.util.List;import org.jboss.set.aphrodite.Aphrodite; -import org.jboss.set.aphrodite.Aphrodite; -import org.jboss.set.aphrodite.domain.spi.PullRequestHome; -import org.jboss.set.aphrodite.repository.services.github.GithubPullRequestHomeService; -import org.jboss.set.aphrodite.simplecontainer.SimpleContainer; -import org.jboss.set.pull.processor.impl.evaluator.util.StreamDefinitionUtil; +import static java.util.stream.Collectors.toList; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; @@ -41,121 +32,43 @@ import net.sourceforge.argparse4j.inf.Namespace; public class Main { - private static final Logger logger = Logger.getLogger(Main.class.getPackage().getName()); - private static final SimpleContainer simpleContainer = (SimpleContainer) SimpleContainer.instance(); - - public void start(List parsedStreams, List writePermittedStreams, String reportFile, - boolean performReviewAction, Boolean performWriteOperations) throws Exception { - logger.info("initializing...."); - try (Aphrodite aphrodite = Aphrodite.instance(); - // The Jira rate limit currently imposed is 1 call per 2 seconds per node per user. The current design violate above limitation. - // Unfortunately I have to make this single thread to make sure evaluators don't break rate limit. - ClosableHackForExecutor executor = new ClosableHackForExecutor(Executors.newFixedThreadPool(1));) { - - simpleContainer.register(Aphrodite.class.getSimpleName(), aphrodite); - GithubPullRequestHomeService GithubPullRequestHomeService = new GithubPullRequestHomeService(aphrodite); - simpleContainer.register(PullRequestHome.class.getSimpleName(), GithubPullRequestHomeService); - - if (parsedStreams.isEmpty()) { - // this shouldnt happen - logger.info("No streams specified, can't work like that, make up your mind"); - return; - } else { - // XXX: this is a bit scechy, but should do for first iteration - StreamDefinitionUtil.matchStreams(aphrodite, parsedStreams); - } - - if (writePermittedStreams != null && !writePermittedStreams.isEmpty()) { - StreamDefinitionUtil.matchStreams(aphrodite, writePermittedStreams); - } - - logger.info("loading evaluators:"); - ServiceLoader evaluatorsServiceLoader = ServiceLoader.load(Evaluator.class); - final List evaluatorServices = new ArrayList(); - - for (Evaluator evaluator : evaluatorsServiceLoader) { - evaluatorServices.add(evaluator); - logger.info("...." + evaluator.getClass().getSimpleName()); - } - - logger.info("loading actions:"); - ServiceLoader actionServiceLoader = ServiceLoader.load(Action.class); - final List actionServices = new ArrayList(); - for (Action action : actionServiceLoader) { - actionServices.add(action); - logger.info("...." + action.getClass().getSimpleName()); - } - - ServiceLoader processors = ServiceLoader.load(Processor.class); - logger.info("configuring processors:"); - // yeah, two loops, could be done in one go, but KISS is life. - for (Processor processor : processors) { - logger.info("...." + processor.getClass().getName()); - final ProcessorPhase processorPhase = processor.getPhase(); - // find actions and evaluators that can be run by processor - final List filteredActions = actionServices.stream().filter(a -> a.support(processorPhase)) - .collect(Collectors.toList()); - final List filteredEvaluators = evaluatorServices.stream().filter(a -> a.support(processorPhase)) - .collect(Collectors.toList()); - final ProcessorConfig processorConfig = new ProcessorConfig(filteredEvaluators, filteredActions, parsedStreams, - writePermittedStreams, aphrodite, executor.executorService, reportFile, performReviewAction, performWriteOperations); - processor.init(processorConfig); - } - - logger.info("executing processors: "); - for (Processor processor : processors) { - logger.info("...." + processor.getClass().getName()); - processor.process(); - } - } finally { - logger.info("finalizing."); - } - } - - private static class ClosableHackForExecutor implements AutoCloseable { - private ExecutorService executorService; - - public ClosableHackForExecutor(ExecutorService executorService) { - this.executorService = executorService; - } - - @Override - public void close() throws Exception { - if (this.executorService != null && !this.executorService.isShutdown()) { - this.executorService.shutdown(); - } - } - } public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("pull processor"); - parser.addArgument("-s", "--streams").nargs("*").required(true).help( - "Specify streams to be processed. Format of entry: stream[component,component],stream[component,component]"); - parser.addArgument("-p", "--permitted").nargs("*").required(false).help( - "Specify streams/components that are eligible for write. Format of entry: stream[component,component],stream[component,component]"); - parser.addArgument("-f", "--file").required(true).help("File where save the feed report"); - parser.addArgument("-r", "--review").setDefault(Boolean.FALSE).type(Boolean.class) - .help("Determine if pull request review action is performed."); - parser.addArgument("-w", "--write").setDefault(Boolean.FALSE).type(Boolean.class) - .help("Determine if processors should perform write operation on resources or run locally only. "); - // parser.addArgument("-as", "--allowed-streams").nargs("*").required(true).help("jira allowed to be tagged in the - // repos"); - Namespace ns = null; - try { - ns = parser.parseArgs(args); + try (Aphrodite aphrodite = Aphrodite.instance();){ + parser.addArgument("-s", "--streams").nargs("*").required(true).help( + "Specify streams to be processed. Format of entry: stream[component,component],stream[component,component]"); + parser.addArgument("-p", "--permitted").nargs("*").required(false).help( + "Specify streams/components that are eligible for write. Format of entry: stream[component,component],stream[component,component]"); + parser.addArgument("-f", "--file").required(true).help("File where save the feed report"); + parser.addArgument("-r", "--review").setDefault(Boolean.FALSE).type(Boolean.class) + .help("Determine if pull request review action is performed."); + parser.addArgument("-w", "--write").setDefault(Boolean.FALSE).type(Boolean.class) + .help("Determine if processors should perform write operation on resources or run locally only. "); + + Namespace ns = parser.parseArgs(args); // stream[component,component],stream[component,component] - List streams = ns.getList("streams"); - List parsedStreams = streams.stream().map(e -> new StreamDefinition(e)) - .collect(Collectors.toList()); - streams = ns.getList("permitted"); - List writePermittedStreams = null; - if (streams != null) - writePermittedStreams = streams.stream().map(e -> new StreamDefinition(e)).collect(Collectors.toList()); + List streams = ns. getList("streams").stream().map(StreamDefinition::new).collect(toList()); + List permitted = ns. getList("permitted"); + List writePermittedStreams = new ArrayList<>(); + if (permitted != null) { + writePermittedStreams.addAll(permitted.stream().map(StreamDefinition::new).collect(toList())); + } else { + writePermittedStreams.addAll(streams); + } String reportFile = ns.getString("file"); boolean performReviewAction = ns.getBoolean("review"); Boolean performWriteOperations = ns.getBoolean("write"); - // List allowedStreams = ns.getList("allowed_streams"); - new Main().start(parsedStreams, writePermittedStreams, reportFile, performReviewAction, performWriteOperations); + + PullProcessor pullProcessor = PullProcessor.newPullProcessorBuilder() + .withAphrodite(aphrodite) + .withStreams(streams) + .withPermitted(writePermittedStreams) + .withReportFile(reportFile) + .withPerformReviewAction(performReviewAction) + .withPerformWriteAction(performWriteOperations) + .build(); + pullProcessor.start(); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); diff --git a/src/main/java/org/jboss/set/pull/processor/Processor.java b/src/main/java/org/jboss/set/pull/processor/Processor.java index 245586a..dbacab6 100644 --- a/src/main/java/org/jboss/set/pull/processor/Processor.java +++ b/src/main/java/org/jboss/set/pull/processor/Processor.java @@ -21,6 +21,8 @@ */ package org.jboss.set.pull.processor; +import org.jboss.set.pull.processor.data.PullRequestReference; + /** * Pull request processor derived from Jason's pull-player. It checks all the open PRs whether they are merge-able and schedule * a merge job on Hudson for them. A merge-able PR must be approved by a comment "review ok" and must comply to @@ -32,10 +34,11 @@ */ public interface Processor { - ProcessorPhase getPhase(); - void init(ProcessorConfig config) throws Exception; - void process() throws ProcessorException; + void process(PullRequestReference pullRequestReferneces) throws ProcessorException; + default String getName() { + return this.getClass().getSimpleName(); + } } diff --git a/src/main/java/org/jboss/set/pull/processor/ProcessorConfig.java b/src/main/java/org/jboss/set/pull/processor/ProcessorConfig.java index 57672ce..6c03ee3 100644 --- a/src/main/java/org/jboss/set/pull/processor/ProcessorConfig.java +++ b/src/main/java/org/jboss/set/pull/processor/ProcessorConfig.java @@ -24,7 +24,6 @@ import java.io.File; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutorService; import org.jboss.set.aphrodite.Aphrodite; @@ -44,8 +43,6 @@ public class ProcessorConfig { private Aphrodite aphrodite; - private ExecutorService executorService; - // stream defs that were cross checked between user input and streams.json // still it contain both valid and invalid versions. private List streamDefinition; @@ -57,25 +54,19 @@ public class ProcessorConfig { private File reportFile; private boolean review = false; + private boolean write = false; - public ProcessorConfig(final List evaluators, final List actions, - final List streamDefinition, final List writePermitedStreamDefinition, - final Aphrodite aphrodite, final ExecutorService executorService, final String reportFile, final boolean review, final boolean write) { + public ProcessorConfig(ProcessorConfigBuilder builder) { super(); - this.evaluators = evaluators; - this.actions = actions; - this.aphrodite = aphrodite; - this.executorService = executorService; - this.streamDefinition = Collections.unmodifiableList(streamDefinition); - if (writePermitedStreamDefinition != null) { - this.writePermitedStreamDefinition = Collections.unmodifiableList(writePermitedStreamDefinition); - } else { - this.writePermitedStreamDefinition = this.streamDefinition; - } - this.reportFile = new File(reportFile); - this.review = review; - this.write = write; + this.evaluators = builder.evaluators; + this.actions = builder.actions; + this.aphrodite = builder.aphrodite; + this.streamDefinition = Collections.unmodifiableList(builder.parsedStreams); + this.writePermitedStreamDefinition = builder.writePermittedStreams; + this.review = builder.performReviewAction; + this.write = builder.performWriteOperations; + this.reportFile = new File(builder.reportFile); } public List getEvaluators() { @@ -90,10 +81,6 @@ public Aphrodite getAphrodite() { return aphrodite; } - public ExecutorService getExecutorService() { - return executorService; - } - public List getStreamDefinition() { return streamDefinition; } @@ -114,4 +101,62 @@ public boolean isWrite() { return write; } + public static ProcessorConfigBuilder newProcessConfigBuilder() { + return new ProcessorConfigBuilder(); + } + + public static class ProcessorConfigBuilder { + List parsedStreams; + List writePermittedStreams; + String reportFile; + boolean performReviewAction; + Boolean performWriteOperations; + List evaluators; + List actions; + Aphrodite aphrodite; + + public ProcessorConfigBuilder parsedStreams(List parsedStreams) { + this.parsedStreams = parsedStreams; + return this; + } + + public ProcessorConfigBuilder actions(List actions) { + this.actions = actions; + return this; + } + + public ProcessorConfigBuilder evaluators(List evaluators) { + this.evaluators = evaluators; + return this; + } + + public ProcessorConfigBuilder writePermittedStreams(List writePermittedStreams) { + this.writePermittedStreams = writePermittedStreams; + return this; + } + + public ProcessorConfigBuilder reportFile(String reportFile) { + this.reportFile = reportFile; + return this; + } + + public ProcessorConfigBuilder aphrodite(Aphrodite aphrodite) { + this.aphrodite = aphrodite; + return this; + } + + public ProcessorConfigBuilder performReviewAction(boolean performReviewAction) { + this.performReviewAction = performReviewAction; + return this; + } + + public ProcessorConfigBuilder performWriteOperations(boolean performWriteOperations) { + this.performWriteOperations = performWriteOperations; + return this; + } + + public ProcessorConfig build() { + return new ProcessorConfig(this); + } + } } diff --git a/src/main/java/org/jboss/set/pull/processor/ProcessorException.java b/src/main/java/org/jboss/set/pull/processor/ProcessorException.java index 45bef5d..c69458c 100644 --- a/src/main/java/org/jboss/set/pull/processor/ProcessorException.java +++ b/src/main/java/org/jboss/set/pull/processor/ProcessorException.java @@ -25,6 +25,10 @@ public class ProcessorException extends Exception { private static final long serialVersionUID = 1L; + public ProcessorException(Throwable ex) { + super(ex); + } + public ProcessorException(String message, Throwable ex) { super(message, ex); } diff --git a/src/main/java/org/jboss/set/pull/processor/ProcessorPhase.java b/src/main/java/org/jboss/set/pull/processor/ProcessorPhase.java deleted file mode 100644 index f16c638..0000000 --- a/src/main/java/org/jboss/set/pull/processor/ProcessorPhase.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2017, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.set.pull.processor; - -/** - * Determine type of PR/phase that processor and its actors will go through. - * - * @author baranowb - * - */ -public enum ProcessorPhase { - // TODO: XXX most likely this can be equal to PR state, but with some hacks? - // TODO: XXX follow up on above or possibly use int ID likish thing, so processor can define it by itself? - OPEN, EVENTS_CLOSED_UPGRADE; -} diff --git a/src/main/java/org/jboss/set/pull/processor/PullProcessor.java b/src/main/java/org/jboss/set/pull/processor/PullProcessor.java new file mode 100644 index 0000000..9bc8bd6 --- /dev/null +++ b/src/main/java/org/jboss/set/pull/processor/PullProcessor.java @@ -0,0 +1,214 @@ +package org.jboss.set.pull.processor; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.ServiceLoader; +import java.util.stream.Collectors; + +import org.jboss.set.aphrodite.Aphrodite; +import org.jboss.set.aphrodite.container.Container; +import org.jboss.set.aphrodite.domain.Codebase; +import org.jboss.set.aphrodite.domain.PullRequest; +import org.jboss.set.aphrodite.domain.PullRequestState; +import org.jboss.set.aphrodite.domain.Repository; +import org.jboss.set.aphrodite.domain.spi.PullRequestHome; +import org.jboss.set.aphrodite.repository.services.github.GithubPullRequestHomeService; +import org.jboss.set.aphrodite.spi.NotFoundException; +import org.jboss.set.pull.processor.data.PullRequestReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.jboss.set.pull.processor.impl.evaluator.util.StreamDefinitionUtil.matchStreams; + +public class PullProcessor { + private static final Logger LOG = LoggerFactory.getLogger(PullProcessor.class); + + private List parsedStreams; + private List writePermittedStreams; + private boolean performWriteAction; + private boolean performReviewAction; + private String reportFile; + private Aphrodite aphrodite; + private List processors; + + private PullProcessor(PullProcessorBuilder builder) { + this.parsedStreams = builder.parsedStreams; + this.writePermittedStreams = builder.writePermittedStreams; + this.performReviewAction = builder.performReviewAction; + this.performWriteAction = builder.performWriteAction; + this.reportFile = builder.reportFile; + this.aphrodite = builder.aphrodite; + this.processors = init(); + } + + private List init() { + try { + Container container = Container.instance(); + LOG.info("initializing...."); + + container.register(Aphrodite.class.getSimpleName(), aphrodite); + GithubPullRequestHomeService GithubPullRequestHomeService = new GithubPullRequestHomeService(aphrodite); + container.register(PullRequestHome.class.getSimpleName(), GithubPullRequestHomeService); + + ServiceLoader evaluatorsServiceLoader = ServiceLoader.load(Evaluator.class); + List evaluatorServices = new ArrayList(); + + LOG.info("Loading evaluator"); + for (Evaluator evaluator : evaluatorsServiceLoader) { + evaluatorServices.add(evaluator); + LOG.info("Loading evaluator: {}", evaluator.getClass().getSimpleName()); + } + + LOG.info("Loading actions"); + ServiceLoader actionServiceLoader = ServiceLoader.load(Action.class); + List actionServices = new ArrayList(); + for (Action action : actionServiceLoader) { + actionServices.add(action); + LOG.info("Loading action: {}", action.getClass().getSimpleName()); + } + + ProcessorConfig processorConfig = ProcessorConfig.newProcessConfigBuilder() + .aphrodite(aphrodite) + .evaluators(evaluatorServices) + .actions(actionServices) + .parsedStreams(parsedStreams) + .writePermittedStreams(writePermittedStreams) + .performWriteOperations(performWriteAction) + .performReviewAction(performReviewAction) + .reportFile(reportFile) + .build(); + + ServiceLoader processorsServices = ServiceLoader.load(Processor.class); + LOG.info("Loading processor."); + List processors = new ArrayList<>(); + for (Processor processor : processorsServices) { + LOG.info("Loading processor: {}", processor.getClass().getName()); + processor.init(processorConfig); + processors.add(processor); + } + return processors; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void start() { +// fetchPullRequestReferences().forEach(this::process); + fetchSingle().forEach(this::process); + } + + private List fetchSingle() { + try { + String prURI = "https://github.com/wildfly/wildfly/pull/19827"; + String streamDefinitionName = "wildfly"; + String componentDefinitionName = "wildfly-wildlfy"; + PullRequest pullRequest = aphrodite.getPullRequest(URI.create(prURI)); + StreamDefinition streamDefinition = new StreamDefinition(streamDefinitionName); + streamDefinition.setStream(aphrodite.getStream(streamDefinitionName)); + StreamComponentDefinition componentDefinition = new StreamComponentDefinition(componentDefinitionName, streamDefinition); + componentDefinition.setStreamComponent(aphrodite.getStream(streamDefinitionName).getComponent(componentDefinitionName)); + PullRequestReference reference = new PullRequestReference(pullRequest, componentDefinition); + return List.of(reference); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void process(PullRequestReference pullRequestReferences) { + for (Processor processor : processors) { + try { + LOG.info("Executing processors: {} for pull request {}", processor.getClass().getName(), pullRequestReferences); + processor.process(pullRequestReferences); + } catch (ProcessorException e) { + LOG.error("Executing processors", e); + } + } + } + + private List fetchPullRequestReferences() { + List pullRequests = new ArrayList<>(); + for (StreamDefinition streamDefinition : this.parsedStreams) { + for (StreamComponentDefinition streamComponentDefinition : streamDefinition.getStreamComponents()) { + try { + Repository repository = aphrodite.getRepository(streamComponentDefinition.getStreamComponent().getRepositoryURI()); + if (repository == null) { + LOG.warn("Did not find repository: {}", streamComponentDefinition.getStreamComponent().getRepositoryURI()); + continue; + } + + List componentPullRequests = aphrodite.getPullRequestsByState(repository, PullRequestState.OPEN); + // translate it into refs, add to ret val + pullRequests.addAll(componentPullRequests.stream().map(p -> { + return new PullRequestReference(p, streamComponentDefinition); + }).collect(Collectors.toList())); + + } catch (NotFoundException e) { + LOG.warn("Did not find repo", e); + } + } + } + return pullRequests.stream().filter(this::validPullRequest).toList(); + } + + private boolean validPullRequest(PullRequestReference pr) { + try { + StreamComponentDefinition scd = pr.getComponentDefinition(); + Codebase definition = scd.getStreamComponent().getCodebase(); + return pr.getPullRequest().getCodebase().isIn(definition); + } catch (Exception e) { + LOG.error("Failed at: {}", pr, e); + return false; + } + } + + public static PullProcessorBuilder newPullProcessorBuilder() { + return new PullProcessorBuilder(); + } + + public static class PullProcessorBuilder { + public Aphrodite aphrodite; + private List parsedStreams; + private List writePermittedStreams; + private boolean performWriteAction; + private boolean performReviewAction; + private String reportFile; + + public PullProcessorBuilder withAphrodite(Aphrodite aphrodite) { + this.aphrodite = aphrodite; + return this; + } + + public PullProcessorBuilder withStreams(List parsedStreams) { + this.parsedStreams = parsedStreams; + return this; + } + + public PullProcessorBuilder withPermitted(List writePermittedStreams) { + this.writePermittedStreams = writePermittedStreams; + return this; + } + + public PullProcessorBuilder withReportFile(String reportFile) { + this.reportFile = reportFile; + return this; + } + + public PullProcessorBuilder withPerformReviewAction(boolean performReviewAction) { + this.performReviewAction = performReviewAction; + return this; + } + + public PullProcessorBuilder withPerformWriteAction(Boolean performWriteAction) { + this.performWriteAction = performWriteAction; + return this; + } + + public PullProcessor build() throws NotFoundException { + matchStreams(aphrodite, parsedStreams); + matchStreams(aphrodite, writePermittedStreams); + return new PullProcessor(this); + } + } + +} diff --git a/src/main/java/org/jboss/set/pull/processor/StreamComponentDefinition.java b/src/main/java/org/jboss/set/pull/processor/StreamComponentDefinition.java index 8ead08d..4a20d22 100644 --- a/src/main/java/org/jboss/set/pull/processor/StreamComponentDefinition.java +++ b/src/main/java/org/jboss/set/pull/processor/StreamComponentDefinition.java @@ -39,10 +39,6 @@ public String getName() { return name; } - public boolean isFound() { - return this.streamComponent != null; - } - public StreamComponent getStreamComponent() { return streamComponent; } @@ -57,7 +53,7 @@ public StreamDefinition getStreamDefinition() { @Override public String toString() { - return "StreamComponentDefinition [name=" + name + ", found=" + isFound() + "]"; + return "StreamComponentDefinition [name=" + name + "]"; } } diff --git a/src/main/java/org/jboss/set/pull/processor/StreamDefinition.java b/src/main/java/org/jboss/set/pull/processor/StreamDefinition.java index cd8da1d..d4a4d34 100644 --- a/src/main/java/org/jboss/set/pull/processor/StreamDefinition.java +++ b/src/main/java/org/jboss/set/pull/processor/StreamDefinition.java @@ -70,10 +70,6 @@ public List getStreamComponents() { return streamComponents; } - public boolean isFound() { - return this.stream != null; - } - public Stream getStream() { return stream; } @@ -84,7 +80,7 @@ public void setStream(Stream stream) { @Override public String toString() { - return "StreamDefinition [name=" + name + ", found=" + isFound() + ", streamComponents=" + streamComponents + "]"; + return "StreamDefinition [name=" + name + ", streamComponents=" + streamComponents + "]"; } } \ No newline at end of file diff --git a/src/main/java/org/jboss/set/pull/processor/data/Attribute.java b/src/main/java/org/jboss/set/pull/processor/data/Attribute.java new file mode 100644 index 0000000..18d07e4 --- /dev/null +++ b/src/main/java/org/jboss/set/pull/processor/data/Attribute.java @@ -0,0 +1,15 @@ +package org.jboss.set.pull.processor.data; + +public final class Attribute { + + private String name; + + public Attribute(String name) { + this.name = name; + } + + public String name() { + return name; + } + +} \ No newline at end of file diff --git a/src/main/java/org/jboss/set/pull/processor/data/Attributes.java b/src/main/java/org/jboss/set/pull/processor/data/Attributes.java new file mode 100644 index 0000000..1d20099 --- /dev/null +++ b/src/main/java/org/jboss/set/pull/processor/data/Attributes.java @@ -0,0 +1,17 @@ +package org.jboss.set.pull.processor.data; + +import java.util.List; + +public final class Attributes { + public static final Attribute WRITE_PERMISSION = new Attribute<>("write"); + + public static final Attribute ISSUE_CURRENT = new Attribute<>("issue_current"); + public static final Attribute ISSUE_UPSTREAM = new Attribute<>("issue_upstream"); + public static final Attribute> ISSUES_RELATED = new Attribute<>("issues_related"); + + public static final Attribute LABELS_CURRENT = new Attribute<>("labels_current"); + public static final Attribute LABELS_UPSTREAM = new Attribute<>("labels_upstream"); + + public static final Attribute PULL_REQUEST_CURRENT = new Attribute<>("pr_current"); + public static final Attribute PULL_REQUEST_UPSTREAM = new Attribute<>("pr_upstream"); +} \ No newline at end of file diff --git a/src/main/java/org/jboss/set/pull/processor/data/CodeBaseLabelItem.java b/src/main/java/org/jboss/set/pull/processor/data/CodeBaseLabelItem.java index b1da9d2..65c0d93 100644 --- a/src/main/java/org/jboss/set/pull/processor/data/CodeBaseLabelItem.java +++ b/src/main/java/org/jboss/set/pull/processor/data/CodeBaseLabelItem.java @@ -10,7 +10,7 @@ public CodeBaseLabelItem(Codebase label, LabelAction action, LabelSeverity sever @Override public String getLabel() { - return super.label.getName(); + return super.label.getBranch(); } } diff --git a/src/main/java/org/jboss/set/pull/processor/data/EvaluatorData.java b/src/main/java/org/jboss/set/pull/processor/data/EvaluatorData.java index b17b780..a31403e 100644 --- a/src/main/java/org/jboss/set/pull/processor/data/EvaluatorData.java +++ b/src/main/java/org/jboss/set/pull/processor/data/EvaluatorData.java @@ -21,6 +21,7 @@ */ package org.jboss.set.pull.processor.data; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,18 +30,22 @@ public class EvaluatorData { private Map data; - public EvaluatorData(Map data) { - this.data = data; + public EvaluatorData() { + this(new HashMap<>()); } - public EvaluatorData() { - this.data = new HashMap<>(); + public EvaluatorData(Map data) { + this.data = data; } public Map getData() { return data; } + public boolean hasAttribute(Attribute attr) { + return data.containsKey(attr.name()); + } + public T getAttributeValue(Attribute attr) { return (T) data.get(attr.name()); } @@ -49,28 +54,8 @@ public void setAttributeValue(Attribute attr, T value) { data.put(attr.name(), value); } - public static final class Attribute { - - private String name; - - public Attribute(String name) { - this.name = name; - } - - public String name() { - return name; - } - + public List getAttributes() { + return new ArrayList<>(data.keySet()); } - public static final class Attributes { - public static final Attribute WRITE_PERMISSION = new Attribute<>("write"); - public static final Attribute ISSUE_CURRENT = new Attribute<>("issue_current"); - public static final Attribute ISSUE_UPSTREAM = new Attribute<>("issue_upstream"); - public static final Attribute> ISSUES_RELATED = new Attribute<>("issues_related"); - public static final Attribute PULL_REQUEST_CURRENT = new Attribute<>("pr_current"); - public static final Attribute PULL_REQUEST_UPSTREAM = new Attribute<>("pr_upstream"); - public static final Attribute LABELS_CURRENT = new Attribute<>("labels_current"); - public static final Attribute LABELS_UPSTREAM = new Attribute<>("labels_upstream"); - } } \ No newline at end of file diff --git a/src/main/java/org/jboss/set/pull/processor/data/IssueData.java b/src/main/java/org/jboss/set/pull/processor/data/IssueData.java index e2694ec..f1a832e 100644 --- a/src/main/java/org/jboss/set/pull/processor/data/IssueData.java +++ b/src/main/java/org/jboss/set/pull/processor/data/IssueData.java @@ -110,7 +110,7 @@ public Issue getIssue() { @Override public String toString() { - return "IssueData [issue=" + (issue != null ? issue.getURL() : "NA") + ", streamsAckedInIssue=" + streamsAckedInIssue + return "IssueData [issue=" + (issue != null ? issue.getURI() : "NA") + ", streamsAckedInIssue=" + streamsAckedInIssue + ", required=" + required + ", devAckStatus=" + devAckStatus + ", qeAckStatus=" + qeAckStatus + ", pmAckStatus=" + pmAckStatus + "]"; } diff --git a/src/main/java/org/jboss/set/pull/processor/data/LabelData.java b/src/main/java/org/jboss/set/pull/processor/data/LabelData.java index 97e14b9..ebc7d64 100644 --- a/src/main/java/org/jboss/set/pull/processor/data/LabelData.java +++ b/src/main/java/org/jboss/set/pull/processor/data/LabelData.java @@ -33,7 +33,7 @@ public class LabelData { private Set> labels = new TreeSet<>(new Comparator>() { @Override - public int compare(LabelItem o1, LabelItem o2) { + public int compare(LabelItem o1, LabelItem o2) { if (o1 == null) { return -1; } diff --git a/src/main/java/org/jboss/set/pull/processor/data/PullRequestReference.java b/src/main/java/org/jboss/set/pull/processor/data/PullRequestReference.java index ee45d0f..2566dac 100644 --- a/src/main/java/org/jboss/set/pull/processor/data/PullRequestReference.java +++ b/src/main/java/org/jboss/set/pull/processor/data/PullRequestReference.java @@ -56,7 +56,7 @@ public void setComponentDefinition(StreamComponentDefinition componentDefinition @Override public String toString() { - return "PullRequestReference [pullRequest=" + pullRequest + ", componentDefinition=" + componentDefinition + "]"; + return "PullRequestReference [pullRequest=" + pullRequest.getURI() + ", stream=" + componentDefinition.getStreamDefinition().getName() + ", component="+ componentDefinition.getName() + "]"; } } diff --git a/src/main/java/org/jboss/set/pull/processor/impl/action/ReportAction.java b/src/main/java/org/jboss/set/pull/processor/impl/action/ReportAction.java index 9d515ff..8593deb 100644 --- a/src/main/java/org/jboss/set/pull/processor/impl/action/ReportAction.java +++ b/src/main/java/org/jboss/set/pull/processor/impl/action/ReportAction.java @@ -7,14 +7,13 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.jboss.set.pull.processor.Action; import org.jboss.set.pull.processor.ActionContext; -import org.jboss.set.pull.processor.ProcessorPhase; import org.jboss.set.pull.processor.data.EvaluatorData; import org.jboss.set.pull.processor.data.ReportItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Action which produces report if proper flag has been set. @@ -25,11 +24,11 @@ */ public class ReportAction implements Action { - private static final Logger LOG = Logger.getLogger(ReportAction.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(ReportAction.class.getName()); private static final List reportItems = new ArrayList(); @Override - public void execute(ActionContext actionContext, List data) { + public void execute(ActionContext actionContext, EvaluatorData data) { final File reportFile = actionContext.getReportFile(); writeReport(reportFile); } @@ -43,7 +42,7 @@ public static synchronized void addItemToReport(ReportItem ri) { * @param reportItems */ private void writeReport(File reportFile) { - LOG.log(Level.INFO, "Start writing report to file : " + reportFile); + LOG.info("Start writing report to file: {}", reportFile); try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(reportFile)))) { writer.write("\n" + "\n" + @@ -80,16 +79,11 @@ private void writeReport(File reportFile) { "\n" + "\n" + ""); + LOG.info("Finish writing report to file: {}", reportFile); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOG.error("Error during action reporting", e); } - LOG.log(Level.INFO, "Finish writing report to file : " + reportFile); - } - @Override - public boolean support(ProcessorPhase processorPhase) { - return ProcessorPhase.OPEN == processorPhase; } } diff --git a/src/main/java/org/jboss/set/pull/processor/impl/action/SetLabelsAction.java b/src/main/java/org/jboss/set/pull/processor/impl/action/SetLabelsAction.java index 756f359..4e9ddf5 100644 --- a/src/main/java/org/jboss/set/pull/processor/impl/action/SetLabelsAction.java +++ b/src/main/java/org/jboss/set/pull/processor/impl/action/SetLabelsAction.java @@ -21,22 +21,21 @@ */ package org.jboss.set.pull.processor.impl.action; -import java.net.URL; +import java.net.URI; import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.TreeSet; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; +import javax.naming.NameNotFoundException; + import org.jboss.set.aphrodite.domain.Label; import org.jboss.set.aphrodite.domain.PullRequest; import org.jboss.set.aphrodite.spi.NotFoundException; import org.jboss.set.pull.processor.Action; import org.jboss.set.pull.processor.ActionContext; -import org.jboss.set.pull.processor.ProcessorPhase; +import org.jboss.set.pull.processor.data.Attributes; import org.jboss.set.pull.processor.data.EvaluatorData; import org.jboss.set.pull.processor.data.IssueData; import org.jboss.set.pull.processor.data.LabelData; @@ -45,164 +44,138 @@ import org.jboss.set.pull.processor.data.LabelItem.LabelSeverity; import org.jboss.set.pull.processor.data.PullRequestData; import org.jboss.set.pull.processor.data.ReportItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SetLabelsAction implements Action { - private static final Logger LOG = Logger.getLogger(SetLabelsAction.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(SetLabelsAction.class); private static final String Request_Changes_Comment = "According to [pull-request-review-criteria-for-merge](https://source.redhat.com/groups/public/jboss-sustaining-engineering-team/jboss_sustaining_engineering_team_wiki/pull_request_review_criteria_for_merge) document,this pull request does not satisfy all review criteria for merge. Please check the associated pull request labels to revise."; @Override - public void execute(final ActionContext actionContext, final List data) { - try { - actionContext.getExecutors().invokeAll( - data.stream().map(e -> new EvaluatorProcessingTask(actionContext, e)).collect(Collectors.toList())); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } + public void execute(ActionContext actionContext, EvaluatorData data) { +// try { +// setLabels(actionContext, data); +// } catch(Exception e) { +// LOG.error("Error !", e); +// } } - @Override - public boolean support(ProcessorPhase processorPhase) { - if (processorPhase == ProcessorPhase.OPEN) {// true only for OPEN, in close we just post process? - return true; - } else { - return false; + private void setLabels(ActionContext actionContext, EvaluatorData data) throws Exception { + // TODO: XXX cross check REMOVE list vs CURRENT list to avoid mute removal + final PullRequestData pullRequestData = data.getAttributeValue(Attributes.PULL_REQUEST_CURRENT); + final IssueData issueData = data.getAttributeValue(Attributes.ISSUE_CURRENT); + final LabelData labelsData = data.getAttributeValue(Attributes.LABELS_CURRENT); + final PullRequestData upstreamPullRequestData = data.getAttributeValue(Attributes.PULL_REQUEST_UPSTREAM); + final IssueData upstreamIssueData = data.getAttributeValue(Attributes.ISSUE_UPSTREAM); + final LabelData upstreamLabelsData = data.getAttributeValue(Attributes.LABELS_UPSTREAM); + final Set