-
Notifications
You must be signed in to change notification settings - Fork 28
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
Allow for moving truncation into the implementing API #68
Conversation
not ideal as in the junit plugin we link to the test report
would be surprised if we could get something that would work without it being overly complicated |
That does mean the junit plugin assumes that the checks api implementation supports markdown. That seems likely to be the case, but who knows. We could make things considerably more structured - have something like a |
I don't think we should validate the message here because the overflow should be a problem that the implementations should take care of IMO. Since when they are implementing this API according to a specific platform, they should refer to the official documents (e.g. Github documents for checks API) to do the validations. Maybe in the status publisher, it is ok to check the max size because it is a consumer that tries to make every work, but adding too much validation here makes the API complicated IMO. |
I think thats maybe why I'd like to see some kind of TruncatedStringBuilder exposed from the checks publisher so we end up with something like: new ChecksOutput.Builder()
.withSummary(publisher.getTruncatedStringBuilder()
.withReadMoreUrl(url)
.addText(...)
.addText(...)
.build()) Then its up to the implementers to provide an implmentation of TruncatedStringBuilder that sets the correct limits, and converts the 'read more' url into the appropriate formatting. (for clarity, what I've written there is not what I think the latest commit does!) |
Would the read more URL different from the details URL? |
return withText(new TruncatedString.Builder().addText(text).build()); | ||
} | ||
|
||
public ChecksOutputBuilder withText(final TruncatedString text) { |
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.
adding the truncated string builder in line 66 make sense since it makes things convenient for implementations, but since we already have details URL, I'm not sure the see more link would be necessary for consumers, if not, the truncated string build is unnecessary as well IMO.
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.
the see more link was just a helpful extra added in junit it could probably be skipped but truncating is needed afaict
Good point. I'm not sure it would be. But possibly difficult to get to. |
the problem with implementations doing it is you would get broken markdown and truncating at a sane point would be difficult
I don't think so |
Actually the worry about read more being in markdown is pointless as consumers are already assuming markdown as the format for long text fields. I guess if other implementations don’t support markdown they can handle that themselves. |
So, condensing the above I think we have:
Does that sound reasonable? I will work out some code roughly to that effect. |
Codecov Report
@@ Coverage Diff @@
## master #68 +/- ##
============================================
+ Coverage 86.51% 87.18% +0.66%
- Complexity 78 86 +8
============================================
Files 14 15 +1
Lines 408 476 +68
Branches 17 24 +7
============================================
+ Hits 353 415 +62
- Misses 49 54 +5
- Partials 6 7 +1
Continue to review full report at Codecov.
|
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.
looks good to me (although light on tests), I assume another PR coming to github checks to implement the end to end?
Yep. I'll pull over (and extend) the tests from #66 |
*/ | ||
@CheckForNull | ||
public String build() { | ||
return chunks.isEmpty() ? null : String.join("", chunks); |
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 do you think of the statement:
the end of the build log is more interesting than the beginning, there should be more fine grained control over the truncation?
This is more relevant to #66
or should we just say YAGNI and improve it later if required?
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.
Sounds reasonable, and certainly easy enough to implement.
I also think there’s cause to say “allow newine truncation”, so that if you know you’re just putting plain text in (e.g. a large build log) as a single chunk, you can do a new line truncation. Combine that with reverse truncation and you have everything I think.
Ok this may now be hugely over-engineered, but I think it works. The tests hopefully give an idea of what it can do. |
seems sane any reason it's in draft? |
I’ll rebase #66 on top of it to validate it first, if a rebase is ok - otherwise I’ll spin a new branch to test it. I’ll also get a PR open for github checks. |
I'm glad I tried using it on #66- definitely have some changes to make. |
|
||
@ArchTest | ||
static final ArchRule NO_PUBLIC_TEST_CLASSES = PluginArchitectureRules.NO_PUBLIC_TEST_CLASSES; | ||
// Todo: this seems to prevent paramteized non-integration tests. |
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.
So I know that I'm using a Junit4 style test here, but that's because the parametrized options for Junit5 seem to require a huge amount of repetitive boilerplate for this kind of use-case.
It seems easy enough to fix this rule upstream to permit Junit4 style tests:
/** Junit 5 test classes should not be public. */
public static final ArchRule NO_PUBLIC_TEST_CLASSES =
noClasses().that().haveSimpleNameEndingWith("Test")
.and().haveSimpleNameNotContaining("_jmh")
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
+ .and().areNotAnnotatedWith(RunWith.class)
.and().haveSimpleNameNotEndingWith("ITest")
.should().bePublic();
if that's deemed acceptable?
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.
@uhafner I'd appreciate your input on this, as you're down as the author of these rules.
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'm fine with using JUnit 4 in this module. It would be simpler if you would just inline the rule here and adapt it accordingly (or remove it completely).
src/main/java/io/jenkins/plugins/checks/api/TruncatedString.java
Outdated
Show resolved
Hide resolved
public String build(final int maxSize) { | ||
List<String> parts = getChunks(); | ||
if (truncateStart) { | ||
Collections.reverse(parts); |
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.
The logic here is a little bit hard to understand at a start (I even left a comment first asking why we want a reversed output), since it requires you to understand the implementation of the joiner first and the join method in reverse acknowledges this special case. So, although the joiner is just an embedded class, adding another field (e.g. reverse
) and set it identical to truncateStart
makes it easier to understand IMO.
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.
Yes, I agree that it's a bit manky. I think part of the problem is that we reverse it in two different places. I think I should be able to refactor it so that the Joiner
just retuns a plain list of strings and we do the reversal at the end - so the joiner doesn't need to know about reverse; although I'm not sure if that can be done without also moving the truncation text to the start. Would that make more sense? I think it might... so should
1. Some
2. Very
3. Long
4. Output
5. Here
Truncated to three lines would come out in reverse come out as
4. Output
5. Here
Output truncated!
or
Output truncated!
4. Output
5. Here
I'm thinking possibly the latter.
…ner from TruncatedString
As usual, not claiming this is the right way to do it, but I think it is a way to do it. We can then update the github-checks-plugin to call
getSummary(65536, " see [Jenkins](url)")
when creating itsOutput
. It does mean that consumers can't set the 'see more' text, but it means that the GHChecks plugin can confidently use markdown.Of course one of the other options is to add something to the GitHub Checks plugin that can intelligently truncate markdown. But I've no idea what sort of libraries are already out there to help with that. That would also prevent the user from being able to control chunk size.