Thanks for the reply danielwester
Below is the sample code for PullRequestReopenedEvent type events.
public PullRequestReopenedEventListener(ExecutorService executorService, RepositoryService repositoryService,
PluginSettingsFactory pluginSettingsFactory,
PullRequestService pullRequestService, Logs logs) {
this.logger = logs.getLogger(this.getClass().getName());
this.executorService = executorService;
this.repositoryService = repositoryService;
this.pluginSettings = pluginSettingsFactory.createGlobalSettings();
this.pullRequestService = pullRequestService;
}
@EventListener
public void onEvent(final PullRequestReopenedEvent event) {
logger.info("Pull Request Reopened Event");
store(event);
}
private void store(final PullRequestReopenedEvent event) {
executorService.execute(new Runnable() {
@Override
public void run() {
submitEventForExecution(event);
}
});
}
private void submitEventForExecution(final PullRequestReopenedEvent event) {
try {
BaseEventListener baseEventListener = new BaseEventListener(repositoryService, pluginSettings, logger, event);
// get the details maps(repo, title, branch, state.... etc) from Pull Request event details
Map<String, String> itemsMap = baseEventListener.getRequiredItemsMapFromPlugin();
if (itemsMap.get("agilestudioEnabler").equals("on") &&
itemsMap.get("agilestudioTitleValEnabler").equals("on")) {
// validating the Pull Request Title. **AgileStudioOperation** is the custom class to do validation.
AgileStudioOperation agileStudioOperation = new AgileStudioOperation();
Map<String, Object> agResultMap = agileStudioOperation.isTitleHaveValidAgilestudioItem(
itemsMap.get("agilestudioPRURL"), itemsMap.get("prTitle"), itemsMap.get("prToBranch"));
logger.info("agResultMap: " + agResultMap);
if (Boolean.valueOf(agResultMap.get("status").toString())) {
return;
}
// validation failed. Declining the PR with a comment
if (itemsMap.get("prState") != "DECLINED") {
PullRequestDeclineRequest.Builder pullRequestDeclineRequestBuilder = new PullRequestDeclineRequest.Builder(
Integer.parseInt(itemsMap.get("toRepoID").trim()),
Long.parseLong(itemsMap.get("prID").trim()),
Integer.parseInt(itemsMap.get("prVersion").trim()));
PullRequestDeclineRequest declineRequest = pullRequestDeclineRequestBuilder.comment(
"##### __*" + agResultMap.get("reason").toString() + "*__").build();
pullRequestService.decline(declineRequest);
logger.info("Declined the Pull Request");
}
}
} catch (Exception e) {
logger.error("Error in submitting the event for execution" + e);
logger.error("Exception: ", e);
throw e;
}
Likewise, I am doing for PullRequestMergedEvent, PullRequestUpdatedEvent and PullRequestOpenRequestedEvent events also.