Skip to content
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

Merged
merged 12 commits into from
Aug 25, 2020
Merged

Validate GitHub scm source #34

merged 12 commits into from
Aug 25, 2020

Conversation

XiongKezhi
Copy link
Contributor

When creating publisher, check whether all ChecksContext parameters are available using isValid method before returning the GitHubChecksPublisher; if some parameters are not, return Optional.empty(), thus a NullPublisher will be used.

@XiongKezhi XiongKezhi requested a review from a team August 23, 2020 18:20
PluginLogger logger = createLogger(getListener(listener));
Optional<ChecksPublisher> createPublisher(final Run<?, ?> run, final String runURL, final TaskListener listener)
throws UnsupportedEncodingException {
ByteArrayOutputStream cause = new ByteArrayOutputStream();
Copy link
Member

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
Copy link
Member

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?

@XiongKezhi XiongKezhi requested a review from uhafner August 24, 2020 07:43
@XiongKezhi XiongKezhi linked an issue Aug 24, 2020 that may be closed by this pull request
@XiongKezhi XiongKezhi mentioned this pull request Aug 24, 2020
2 tasks
return createPublisher(run, DisplayURLProvider.get().getRunURL(run), listener);
}
catch (UnsupportedEncodingException e) {
LOGGER.log(Level.WARNING, "Could not create logger.", e);
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@uhafner uhafner Aug 24, 2020

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?

Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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())) {
Copy link
Member

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.

Copy link
Contributor Author

@XiongKezhi XiongKezhi Aug 24, 2020

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.

Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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 {
Copy link
Member

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

Copy link
Contributor Author

@XiongKezhi XiongKezhi Aug 24, 2020

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
Copy link

codecov bot commented Aug 24, 2020

Codecov Report

Merging #34 into master will increase coverage by 2.00%.
The diff coverage is 88.60%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...va/io/jenkins/plugins/checks/github/SCMFacade.java 54.00% <0.00%> (-7.37%) 15.00 <0.00> (ø)
...ins/plugins/checks/github/GitSCMChecksContext.java 65.21% <66.66%> (+11.72%) 16.00 <6.00> (+2.00)
...ins/plugins/checks/github/GitHubChecksContext.java 100.00% <100.00%> (ø) 13.00 <6.00> (-1.00)
...s/plugins/checks/github/GitHubChecksPublisher.java 96.77% <100.00%> (+5.86%) 5.00 <1.00> (ø)
...ns/checks/github/GitHubChecksPublisherFactory.java 100.00% <100.00%> (+9.52%) 7.00 <6.00> (-4.00) ⬆️
...ns/checks/github/GitHubSCMSourceChecksContext.java 100.00% <100.00%> (+10.52%) 20.00 <17.00> (+5.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37de36b...92ce6e0. Read the comment docs.

@XiongKezhi XiongKezhi merged commit a0c5db0 into master Aug 25, 2020
@XiongKezhi XiongKezhi deleted the validate-github-scm-source branch August 25, 2020 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitHub Check does not get updated/dismissed after rebuild
3 participants