Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.derick.notificationbot;
package derrick.Notificationbot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/derrick/logging/Logger
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package derrick.logging;

public interface Logger {
void info(String message);
void error(String message, Throwable t);
}
14 changes: 14 additions & 0 deletions src/main/java/derrick/logging/LoggerImpl
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove log clutter

t.printStackTrace(System.err);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package derrick.processor;

public class BuildFailureEventProcessor {

}
5 changes: 4 additions & 1 deletion src/main/java/derrick/processor/EventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ 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
*/
boolean supports(String eventType);

/**
* Processes the given event payload.
*
* @param payload The event payload as a String (typically JSON)
*/
void processEvent(String payload);
}
}
`
53 changes: 53 additions & 0 deletions src/main/java/derrick/processor/PullRequestEventProcessor
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/derrick/pullrequest/PullRequestService
Original file line number Diff line number Diff line change
@@ -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);
}
34 changes: 34 additions & 0 deletions src/main/java/derrick/pullrequest/PullRequestServiceImpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package derrick.service.impl;

import derrick.service.PullRequestService;

public class GitHubPullRequestServiceImpl implements PullRequestService {
@Override
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incomplete impl making the ci fail

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;
}
}
Loading