-
Notifications
You must be signed in to change notification settings - Fork 0
add event processor and logger implementations #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/main/java/derrick/Notificationbot/NotificationBotApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/derrick/Notificationbot/rest/HelloController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| t.printStackTrace(System.err); | ||
| } | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
src/main/java/derrick/processor/BuildFailureEventProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package derrick.processor; | ||
|
|
||
| public class BuildFailureEventProcessor { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove log clutter