-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement Simple Event polling and create profile based testing #200
Conversation
7aec6ee
to
106cd6b
Compare
* https://docs.github.com/en/rest/using-the-rest-api/github-event-types?apiVersion=2022-11-28 | ||
* and Events sent by GitHub SSE https://docs.github.com/en/webhooks/webhook-events-and-payloads | ||
*/ | ||
private static final Map<GHEvent, Tuple2<String, Boolean>> typeToEventMap = Map.of( |
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.
maybe it would be better from maintainability and readability point of view to not use Tuple2
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.
what would you like to see used instead?
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.
Custom named wrapper.
@FunctionalInterface | ||
public interface GitHubEventEmitter<T extends Throwable> { | ||
|
||
void fire() throws T; |
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.
Why do we need this since fire() method in EventPollingProcessor is scheduled?
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.
For the testing framework, so we can manually fire the events once everything is mocked.
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.
If it's just for testing, maybe think if you can reuse automatic polling to stay more closely aligned with the original code.
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.
I think this single interface makes it much easier for testing, as otherwise how could we discover the correct beans?
@FunctionalInterface | ||
public interface GitHubEventPreprocessor { | ||
GitHubEventPreprocessor INSTANCE = new DefaultGitHubEventPreprocessor(); | ||
ObjectMapper objectMapper = new ObjectMapper(); |
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.
We should reuse objectmapper if possible.
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.
it is static by default this way - in the interface. It's for this reason in the interface, so implementing classes can use it, such as PushEventPreprocessor does.
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.
maybe then don't use fields in interfaces
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.
I believe this is a common practice, for reusing common objects or for providing default static implementation
src/test/java/org/wildfly/bot/utils/testing/model/GitHubEventPayload.java
Show resolved
Hide resolved
PullRequestGitHubEventPayload::new); | ||
|
||
pullRequestJson = TestModel | ||
.setPullRequestJsonBuilderBuild(pullRequestJsonBuilder -> pullRequestJsonBuilder.action(SYNCHRONIZE)); |
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.
setPullRequestJson
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.
Sure, but note, it's rather the builder we provide there.
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.
and you called it BuilderBuild? setPRJSonBuilder then
TestModel.given(mocks -> WildflyGitHubBotTesting.mockRepo(mocks, wildflyConfigFile, pullRequestJson)) | ||
.sseEventOptions(eventSenderOptions -> eventSenderOptions.payloadFromString(pullRequestJson.jsonString()) | ||
.event(GHEvent.PULL_REQUEST)) | ||
.pollingEventOptions(eventSenderOptions -> eventSenderOptions.eventFromPayload(pullRequestJson.jsonString())) |
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.
maybe we don't need to repeat it if it's same for sse and polling?
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.
Sure, I can add some default methods. I was just worried to not hide too many details from the user, such that there would be too much unnecessary "magic" happening in the testing framework.
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.
magic is what we do to make the end user code easier
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.
This has been already done previously, please see here. Let me know, if it fits the needs
() -> SsePullRequestPayload.builder(TestConstants.VALID_PR_TEMPLATE_JSON), | ||
PullRequestGitHubEventPayload::new); | ||
|
||
pullRequestJson = TestModel.getPullRequestJson(); |
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.
Just when I see this side to side, do you think that this new API is easier?
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.
Sure, I will provide more default methods. Also, after this PR I would like to open issue, about prettyfying the old school builder. I don't think for example we need to provide TestConstants.VALID_PR_TEMPLATE_JSON
all the time, etc. Similar to what I did with PullRequestGitHubEventPayload
.
ff7fe48
to
2a5c507
Compare
2a5c507
to
63d72ae
Compare
.then().github(mocks -> { | ||
|
||
TestModel.given( | ||
mocks -> WildflyGitHubBotTesting.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext)) |
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.
We can probably simplify this later. Not in this PR.
.sseEventOptions(eventSenderOptions -> eventSenderOptions.payloadFromString(pullRequestReviewJson.jsonString()) | ||
.event(GHEvent.PULL_REQUEST_REVIEW)) | ||
.pollingEventOptions( | ||
eventSenderOptions -> eventSenderOptions.eventFromPayload(pullRequestReviewJson.jsonString())) |
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.
This could be simplified now right?
GitHubEventEmitter
- new interface for firing events, our event polling processor)Future work: