diff --git a/src/main/java/derrick/Notificationbot/NotificationBotApplication.java b/src/main/java/derrick/Notificationbot/NotificationBotApplication.java index 4db9941..596bc2f 100644 --- a/src/main/java/derrick/Notificationbot/NotificationBotApplication.java +++ b/src/main/java/derrick/Notificationbot/NotificationBotApplication.java @@ -1,4 +1,5 @@ -package com.derick.notificationbot; +package derrick.Notificationbot; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/derrick/Notificationbot/rest/HelloController.java b/src/main/java/derrick/Notificationbot/rest/HelloController.java index d560201..c756fdd 100644 --- a/src/main/java/derrick/Notificationbot/rest/HelloController.java +++ b/src/main/java/derrick/Notificationbot/rest/HelloController.java @@ -1,4 +1,4 @@ -package com.derick.notificationbot; +package derrick.Notificationbot.rest; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/src/main/java/derrick/logging/Logger b/src/main/java/derrick/logging/Logger new file mode 100644 index 0000000..0450f6a --- /dev/null +++ b/src/main/java/derrick/logging/Logger @@ -0,0 +1,6 @@ +package derrick.logging; + +public interface Logger { + void info(String message); + void error(String message, Throwable t); +} diff --git a/src/main/java/derrick/logging/LoggerImpl b/src/main/java/derrick/logging/LoggerImpl new file mode 100644 index 0000000..8cc5c5b --- /dev/null +++ b/src/main/java/derrick/logging/LoggerImpl @@ -0,0 +1,14 @@ +package derrick.logging.impl; + +import derrick.logging.Logger; + +public class ConsoleLogger implements Logger { + public void info(String message) { + System.out.println("[INFO] " + message); // Can replace later with structured logging + } + + public void error(String message, Throwable t) { + System.err.println("[ERROR] " + message); + t.printStackTrace(System.err); + } +} diff --git a/src/main/java/derrick/processor/BuildFailureEventProcessor.java b/src/main/java/derrick/processor/BuildFailureEventProcessor.java new file mode 100644 index 0000000..451e9d6 --- /dev/null +++ b/src/main/java/derrick/processor/BuildFailureEventProcessor.java @@ -0,0 +1,5 @@ +package derrick.processor; + +public class BuildFailureEventProcessor { + +} diff --git a/src/main/java/derrick/processor/EventProcessor.java b/src/main/java/derrick/processor/EventProcessor.java index 1ac9658..9735318 100644 --- a/src/main/java/derrick/processor/EventProcessor.java +++ b/src/main/java/derrick/processor/EventProcessor.java @@ -7,6 +7,7 @@ public interface EventProcessor { /** * Checks if this processor supports the given event type. + * * @param eventType The event type (e.g. pull_request, build_failure) * @return true if supported, false otherwise */ @@ -14,7 +15,9 @@ public interface EventProcessor { /** * Processes the given event payload. + * * @param payload The event payload as a String (typically JSON) */ void processEvent(String payload); -} \ No newline at end of file +} +` diff --git a/src/main/java/derrick/processor/PullRequestEventProcessor b/src/main/java/derrick/processor/PullRequestEventProcessor new file mode 100644 index 0000000..b94aad3 --- /dev/null +++ b/src/main/java/derrick/processor/PullRequestEventProcessor @@ -0,0 +1,53 @@ +package derrick.processor; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import derrick.service.PullRequestService; +import derrick.util.Logger; + +public class PullRequestEventProcessor implements EventProcessor { + + private static final String SUPPORTED_EVENT = "pull_request"; + + private final ObjectMapper objectMapper; + private final PullRequestService pullRequestService; + private final Logger logger; + + public PullRequestEventProcessor(PullRequestService pullRequestService, Logger logger) { + this.objectMapper = new ObjectMapper(); + this.pullRequestService = pullRequestService; + this.logger = logger; + } + + @Override + public boolean supports(String eventType) { + return SUPPORTED_EVENT.equalsIgnoreCase(eventType); + } + + @Override + public void processEvent(String payload) { + try { + JsonNode root = objectMapper.readTree(payload); + JsonNode actionNode = root.path("action"); + JsonNode pullRequestNode = root.path("pull_request"); + + if (actionNode.isMissingNode() || pullRequestNode.isMissingNode()) { + logger.warn("Missing pull request action or data in payload."); + return; + } + + String action = actionNode.asText(); + String prTitle = pullRequestNode.path("title").asText(); + String prUrl = pullRequestNode.path("html_url").asText(); + String author = pullRequestNode.path("user").path("login").asText(); + + pullRequestService.handlePullRequest(action, prTitle, prUrl, author); + + logger.info(String.format("Processed pull request event: action=%s, title=%s, author=%s", + action, prTitle, author)); + + } catch (Exception e) { + logger.error("Failed to process pull request event", e); + } + } +} diff --git a/src/main/java/derrick/pullrequest/PullRequestService b/src/main/java/derrick/pullrequest/PullRequestService new file mode 100644 index 0000000..ba8ebae --- /dev/null +++ b/src/main/java/derrick/pullrequest/PullRequestService @@ -0,0 +1,8 @@ +package derrick.service; + +public interface PullRequestService { + void commentOnPullRequest(String payload); + void validatePullRequest(String payload); + void mergePullRequest(String payload); + String fetchPullRequestInfo(String pullRequestId); +} \ No newline at end of file diff --git a/src/main/java/derrick/pullrequest/PullRequestServiceImpl b/src/main/java/derrick/pullrequest/PullRequestServiceImpl new file mode 100644 index 0000000..bbf7287 --- /dev/null +++ b/src/main/java/derrick/pullrequest/PullRequestServiceImpl @@ -0,0 +1,34 @@ +package derrick.service.impl; + +import derrick.service.PullRequestService; + +public class GitHubPullRequestServiceImpl implements PullRequestService { + @Override + public void commentOnPullRequest(String payload) { + // Implementation for commenting on a pull request + // This could involve using GitHub's API to post a comment + // based on the provided payload. + } + + @Override + public void validatePullRequest(String payload) { + // Implementation for validating a pull request + // This could involve checking the status of the pull request + // or ensuring it meets certain criteria. + } + + @Override + public void mergePullRequest(String payload) { + // Implementation for merging a pull request + // This could involve using GitHub's API to merge the pull request + // based on the provided payload. + } + + @Override + public String fetchPullRequestInfo(String pullRequestId) { + // Implementation for fetching pull request information + // This could involve using GitHub's API to retrieve details + // about the specified pull request. + return null; + } +}