-
Notifications
You must be signed in to change notification settings - Fork 38
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
Validate GitHub scm source #34
Conversation
PluginLogger logger = createLogger(getListener(listener)); | ||
Optional<ChecksPublisher> createPublisher(final Run<?, ?> run, final String runURL, final TaskListener listener) | ||
throws UnsupportedEncodingException { | ||
ByteArrayOutputStream cause = new ByteArrayOutputStream(); |
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.
doesn't this need closing? i.e. add to try with resources?
final GitHubChecksContext gitHubSCMSourceContext) { | ||
if (gitHubSCMSourceContext.isValid(logger)) { | ||
return Optional.of(new GitHubChecksPublisher(gitHubSCMSourceContext, getListener(listener))); | ||
@VisibleForTesting |
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.
agree with the check above about duplication can it be improved so we don't have 3 very similar methods?
src/main/java/io/jenkins/plugins/checks/github/GitHubChecksPublisher.java
Show resolved
Hide resolved
return createPublisher(run, DisplayURLProvider.get().getRunURL(run), listener); | ||
} | ||
catch (UnsupportedEncodingException e) { | ||
LOGGER.log(Level.WARNING, "Could not create logger.", e); |
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.
Is the LOGGER
still required? We can use the PluginLogger
that prints to the console log.
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, we can, just I don't know which log the users normally use, the system log or console log?
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 never look into the system log. I think if something goes wrong due to a wrong configuration it makes sense to be part of the console log. What do you think, @timja?
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 can't really imagine why this would ever fail, I think it shouldn't be a checked exception, and then this goes away
try { | ||
return createPublisher(run, DisplayURLProvider.get().getRunURL(run), listener); | ||
} | ||
catch (UnsupportedEncodingException e) { |
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.
Would it make sense to use a safe default if the URL is broken?
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 UnsupportedEncodingException
is thrown by the constructor of PrintStream
, not the url.
Optional<ChecksPublisher> createPublisher(final Run<?, ?> run, final String runURL, final TaskListener listener) | ||
throws UnsupportedEncodingException { | ||
ByteArrayOutputStream cause = new ByteArrayOutputStream(); | ||
try (PrintStream ps = new PrintStream(cause, true, StandardCharsets.UTF_8.name())) { |
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 are you creating a new PrintStream
? Can't you use the TaskListener
directly? See line 118.
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.
Because when users are using GitHubSCMSource
project, some logs like "no credentials available" for validating the GitSCMContext
are useless and maybe annoying for them IMO, so I tried to just log these "causes" when no suitable publisher is found.
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 either place the GitHubSCM first (this has the same effect for GitSCM users) or we can use the FilteredLog
for both context types and print the log only in case that both return nothing.
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'm finding such a logger, I'll use FilteredLog
.
|
||
@Nullable | ||
private String resolveHeadSha() { | ||
if (runAvailable) { |
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.
Rather than using an if else
here and adding a new field runAvailable
it would be nicer if you would assign the SHA directly in the corresponding Job
and Run
constructors.
Optional<ChecksPublisher> createPublisher(final Job<?, ?> job, final String jobURL, final TaskListener listener) { | ||
PluginLogger logger = createLogger(getListener(listener)); | ||
Optional<ChecksPublisher> createPublisher(final Run<?, ?> run, final String runURL, final TaskListener listener) | ||
throws UnsupportedEncodingException { |
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 expect consumers to do here?
This doesn't seem like it would ever happen.
Better to remove it from the API and handle it internaly to the method I think
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 thrown by the constructor of PrintStream
. Now I'll refactor and use the FilteredLog
implemented by Ulli in his plugin util, then we don't have to construct those streams and this will be removed.
Codecov Report
@@ Coverage Diff @@
## master #34 +/- ##
============================================
+ Coverage 75.33% 77.33% +2.00%
- Complexity 94 96 +2
============================================
Files 7 7
Lines 300 300
Branches 32 33 +1
============================================
+ Hits 226 232 +6
+ Misses 52 48 -4
+ Partials 22 20 -2
Continue to review full report at Codecov.
|
When creating publisher, check whether all
ChecksContext
parameters are available usingisValid
method before returning theGitHubChecksPublisher
; if some parameters are not, returnOptional.empty()
, thus aNullPublisher
will be used.