| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-simple</artifactId> | ||
| <version>1.7.2</version> | ||
| <scope>test</scope> |
There was a problem hiding this comment.
to avoid this message on test execution:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
It is out of scope, but not sure if this deserves separate PR.
Sorry, something went wrong.
| * and payloads</a> | ||
| */ | ||
| @SuppressWarnings("UnusedDeclaration") | ||
| public abstract class GHEventPayload { |
There was a problem hiding this comment.
Pay attention: class made non-abstract. Reasoning: it allow to instantiate common event object:
GitHub.offline()
.parseEventPayload(new StringReader(payload), GHEventPayload.class)Why this may be needed: if you want to validate the X-Hub-Signature before handling the payload, you may need common information like repository to resolve the secret.
Possible workaround in case if the class is still abstract: make an empty subclass (in your local project, but in org.kohsuke.github package) and instantiate it.
Possible incompatibility: not expected.
Sorry, something went wrong.
|
|
||
| // https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-object-common-properties | ||
| // Webhook payload object common properties: action, sender, repository, organization, installation | ||
| private String action; |
There was a problem hiding this comment.
as declared in #947 moved from subclasses. Field may be null depending on the event type
Sorry, something went wrong.
| if (sender != null) { | ||
| sender.wrapUp(root); | ||
| } | ||
| if (repository != null) { |
There was a problem hiding this comment.
aggregated from overriden wrapUp methods and a getter with side effect (see below) because of fields lift
Sorry, something went wrong.
| * @return the repository | ||
| */ | ||
| public GHRepository getRepository() { | ||
| repository.root = root; |
There was a problem hiding this comment.
replaced with wrapUp on the super-class
Sorry, something went wrong.
| // Webhook payload object common properties: action, sender, repository, organization, installation | ||
| private String action; | ||
| private GHUser sender; | ||
| GHRepository repository; |
There was a problem hiding this comment.
some fields are package visible, because subclasses work with them directly. Considerable: make private, replace with accessors
Sorry, something went wrong.
There was a problem hiding this comment.
@seregamorph
Yes, please make these private.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| public static class PullRequestReview extends GHEventPayload { | ||
| private String action; | ||
| private GHPullRequestReview review; | ||
| private GHPullRequest pull_request; |
There was a problem hiding this comment.
note: snake_case replaced with camelCase, mapper is set up to force snake_case, so it was redundant
Sorry, something went wrong.
| super.wrapUp(root); | ||
| if (repository != null) | ||
| repository.wrap(root); | ||
| if (organization != null) { |
There was a problem hiding this comment.
moved to superclass
Sorry, something went wrong.
| assertThat(event.getPullRequest().getAdditions(), is(137)); | ||
| assertThat(event.getPullRequest().getDeletions(), is(81)); | ||
| assertThat(event.getPullRequest().getChangedFiles(), is(22)); | ||
| assertThat(event.getPullRequest().getLabels().iterator().next().getName(), is("Ready for Review")); |
There was a problem hiding this comment.
test for already addressed #943
Sorry, something went wrong.
| @@ -0,0 +1,149 @@ | |||
| { | |||
| "zen": "Design for failure.", | |||
There was a problem hiding this comment.
the payload got from real requests (only some usernames were changed)
Sorry, something went wrong.
There was a problem hiding this comment.
Excellent! Theres some additional cleanup needed, but other than that this is looking great!
Thanks for contributing!
Sorry, something went wrong.
| // Webhook payload object common properties: action, sender, repository, organization, installation | ||
| private String action; | ||
| private GHUser sender; | ||
| GHRepository repository; |
There was a problem hiding this comment.
@seregamorph
Yes, please make these private.
Sorry, something went wrong.
| } | ||
|
|
||
| /** | ||
| * Most webhook payloads contain an action property that contains the specific activity that triggered the event. |
There was a problem hiding this comment.
| * Most webhook payloads contain an action property that contains the specific activity that triggered the event. | |
| * Gets the action for the trigged event. | |
| * | |
| * Most but not all webhook payloads contain an action property that contains the specific activity that triggered the event. |
Sorry, something went wrong.
There was a problem hiding this comment.
done (typo in suggestion fixed)
Sorry, something went wrong.
| void wrapUp(GitHub root) { | ||
| super.wrapUp(root); | ||
| repository.wrap(root); |
There was a problem hiding this comment.
The super handles the repository.wrap(), right?
| void wrapUp(GitHub root) { | |
| super.wrapUp(root); | |
| repository.wrap(root); | |
| void wrapUp(GitHub root) { | |
| super.wrapUp(root); |
Sorry, something went wrong.
There was a problem hiding this comment.
done. the inherited method removed (contains only a call to super)
Sorry, something went wrong.
| "Expected check_run payload, but got something else. Maybe we've got another type of event?"); | ||
| GHRepository repository = getRepository(); | ||
| if (repository != null) { | ||
| repository.wrap(root); |
There was a problem hiding this comment.
inherited
Sorry, something went wrong.
| throw new IllegalStateException( | ||
| "Expected check_suite payload, but got something else. Maybe we've got another type of event?"); | ||
| else | ||
| installation.wrapUp(root); |
There was a problem hiding this comment.
inherited
Sorry, something went wrong.
| */ | ||
| public GHRepository getRepository() { | ||
| return repository; | ||
| pullRequest.root = root; |
There was a problem hiding this comment.
BTW this logic kept, but this line looks redundant (see wrapUp)
Sorry, something went wrong.
| } | ||
|
|
||
| @Override | ||
| void wrapUp(GitHub root) { |
There was a problem hiding this comment.
fully inherited - hence removed
Sorry, something went wrong.
| } | ||
| if (repository != null) { | ||
| repository.root = root; | ||
| repository.wrap(root); |
There was a problem hiding this comment.
note: repository.root = root; replaced with repository.wrap(root);, a more complex. This way we can inherit this action in subclasses and remove repository.wrap(root); line from them.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
** Address issue #947: move common fields to base class GHEventPayload **
Reference: Webhook payload object common properties
Before submitting a PR:
We love getting PRs, but we hate asking people for the same basic changes every time.
When creating a PR: