Skip to content

Allow null message in SlackMessage #31288

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

Closed
wants to merge 2 commits into from
Closed

Conversation

albendz
Copy link
Contributor

@albendz albendz commented Jun 13, 2018

Adding constructors to the slack message class to support more flexibility in null parameters. Additionally provided setters for use-cases where this can be added before message template is created.

#30071

Read and executed all template tasks for contribution. Signed CLA but maybe submitted too soon for check to pass.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@hub-cap
Copy link
Contributor

hub-cap commented Jun 13, 2018

@elasticmachine test this please

@hub-cap
Copy link
Contributor

hub-cap commented Jun 13, 2018

@albendz ty for the contribution. ill be pulling this down today to check it out.

@hub-cap
Copy link
Contributor

hub-cap commented Jun 13, 2018

A few comments so far. Your branch is a bit old, and this can very easily cause our CI to fail. We move fast :) We typically will push the merge commit to your remote, but I noticed that you were also requesting a PR from your master branch, and not some other branch that would be named anything you wish. I don't like to push to other people's master branch, just because I wouldn't want someone doing it to mine! It is too late for changing the branch and keeping this PR open. I think we should leave it as is, and next time you push, go ahead and do it from a aptly named branch.

You can easily merge into your master by fetching the elastic repo's changes, and just issuing a git merge upstream/master, where upstream is whatever you have named the elastic organization. I like upstream, but lesser things than naming remotes have provoked pitchforks :P This should cause CI to become happy again, and ill gladly request another round of CI testing once you update.

Copy link
Contributor

@hub-cap hub-cap left a comment

Choose a reason for hiding this comment

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

I will be testing these against our real slack install as well, so we I can verify what happens when both attachments and text are null. Again, TYVM for the contribution!!!

final String text;
final Attachment[] attachments;
String text;
Attachment[] attachments;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for making these non final? Our objects are typically final. And assigning null to these still counts as making sure they are final. It is very atypical for us to assign setters to objects like this to set these values after construction of the object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can correct this. There's no reason for them not to be final.

public void setText(String text) { this.text = text;}

public void setAttachments(Attachment[] attachments) { this.attachments = attachments;}

Copy link
Contributor

Choose a reason for hiding this comment

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

see previous comment about final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix.

@@ -602,6 +602,11 @@ public void testUrlPathIsFiltered() throws Exception {
}
}

public void canHaveNullTextAndAttachment() throws Exception {
SlackMessage slackMessage = new SlackMessage("from", new String[] {"to"}, "icon");
assertThat(slackMessage.getText(), is(null));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing a compile error for me, pls use assertNull(object) so it compiles clean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix.

@hub-cap
Copy link
Contributor

hub-cap commented Jun 13, 2018

One other thing I realized is that the issue itself is saying "if we have an attachment, do not require the text from the message itself". This would be better if the constructor could not pass in both attachments and text as null, but one that lets text be null if you pass an attachment in.

edit

I did a test where I removed both text and attachment, and got the following back:

"body" : "missing_text_or_fallback_or_attachments"

So this definitely wont work with both being null.

@albendz
Copy link
Contributor Author

albendz commented Jun 13, 2018

@hub-cap I'll change this so there are finals again, will make sure it's attachments OR text and not null for both. I'll update my fork as well.

@albendz
Copy link
Contributor Author

albendz commented Jun 22, 2018

@hub-cap Sorry about being so slow on this - It takes me a very long time to run the build and test. Is there a way to speed this up without losing test coverage? Are there particular hardware requirements that might make it faster to run this project?

@albendz
Copy link
Contributor Author

albendz commented Jun 22, 2018

I have created a new branch here (https://github.com/albendz/elasticsearch/tree/slack_message_empty_text). Would you like me to create a new pull request?

@@ -602,6 +602,11 @@ public void testUrlPathIsFiltered() throws Exception {
}
}

public void canHaveNullTextAndAttachment() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will not get executed as a test if the method does not begin with test

@hub-cap
Copy link
Contributor

hub-cap commented Jun 25, 2018

if you prefer a new pull request, that is ok. Just be sure to reference this pull request when you open it (and close this one too!). Also, be sure to take @spinscale comment to make sure your test is run.

@albendz
Copy link
Contributor Author

albendz commented Jun 27, 2018

New Pull Request: #31596

@albendz albendz closed this Jun 27, 2018
@hub-cap
Copy link
Contributor

hub-cap commented Jun 27, 2018

There is no reason to be sorry @albendz! This stuff takes a long time :) Hours for the full check build to be run!! Sometimes it makes sense to run only the pieces that you are testing, but that requires some gradle knowledge about what you are testing, and definitely running it on newer hardware is best. Most of the engineers have newer macbook pro's or linux machines, and many of the elastic engineers run full checks on a desktop or cloud machine because it can destroy your entire laptop productivity!

I personally have a bunch of second hand dual proc server grade hardware that I run the checks on, with boatloads of ram :)

hub-cap pushed a commit that referenced this pull request Jul 10, 2018
Slack accepts an empty text or attachments, but not both. This commit
ensures that both are not empty when creating a watch.

Closes #30071

Replacing old pull request: #31288
hub-cap pushed a commit that referenced this pull request Jul 11, 2018
Slack accepts an empty text or attachments, but not both. This commit
ensures that both are not empty when creating a watch.

Closes #30071

Replacing old pull request: #31288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants