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

Try resolve commit from run first #27

Closed
wants to merge 1 commit into from

Conversation

XiongKezhi
Copy link
Contributor

@XiongKezhi XiongKezhi commented Aug 16, 2020

@XiongKezhi XiongKezhi added the bug Something isn't working label Aug 16, 2020
@XiongKezhi XiongKezhi requested a review from a team August 16, 2020 15:24
@XiongKezhi XiongKezhi self-assigned this Aug 16, 2020
@XiongKezhi XiongKezhi linked an issue Aug 16, 2020 that may be closed by this pull request

private String resolveCommit() {
if (run == null) {
return StringUtils.EMPTY;
Copy link
Member

Choose a reason for hiding this comment

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

returning an empty string is usually a codesmell, just return null if you can't find it, imo

Suggested change
return StringUtils.EMPTY;
return null;

Copy link
Member

Choose a reason for hiding this comment

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

Then we need to guard all methods that invoke the getSha.

Copy link
Member

Choose a reason for hiding this comment

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

This method is only called internally from one place?

return resolveCommit(revision.get());
}
else {
return StringUtils.EMPTY;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return StringUtils.EMPTY;
return null;

Copy link
Member

@uhafner uhafner left a comment

Choose a reason for hiding this comment

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

Maybe it makes sense to also have a look at
#26
before we merge this change.

In my PR I found several paths where the context will throw an exception. Shouldn't we check before we create a publisher if such an exception will occur (e.g., if there is no SHA?).

@@ -75,7 +76,13 @@
* @return the commit sha of the run or null
Copy link
Member

Choose a reason for hiding this comment

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

If null is allowed (which I think is a bad choice) then we must mark the method with Nullable

}

private String resolveCommit() {
if (run == null) {
Copy link
Member

Choose a reason for hiding this comment

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

In my refactored version run is not a field anymore and thus cannot be null. Rather than setting run to null we should immediately initialize all fields in the constructor. Then we do not have any null checks for run anymore.

I'm not sure if I did understand the GitHub REST API correctly: is it valid to call it without a SHA? If not then we should not create a ChecksPublisher. This is the way I did it with Freestyle jobs and pipelines.

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 reason we introduce the nullable run here is that when the job is still in the queue, the run is not available, so we can't get the url of the run (see #13 (comment)) and will return the url of the job view instead.

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 didn't find a better way to avoid nullable run, but maybe we can add another boolean field isLastBuild when constructing the context to indicate whether the run is the last build? So when isLastBuild == true, we get run by job.getLastBuild(), when isLastBuild == false, we use the run that was passed in the constructor.

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 saw your refactoring on this problem, simple but great! Ignore the previous two comments :)

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'm not sure if I did understand the GitHub REST API correctly: is it valid to call it without a SHA? If not then we should not create a ChecksPublisher. This is the way I did it with Freestyle jobs and pipelines.

The SHA is required for a check, without it, the check cannot be created successfully.


private String resolveCommit() {
if (run == null) {
return StringUtils.EMPTY;
Copy link
Member

Choose a reason for hiding this comment

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

Then we need to guard all methods that invoke the getSha.

}
else {
throw new IllegalStateException("Unsupported revision type: " + revision.get().getClass().getName());
throw new IllegalStateException("Unsupported revision type: " + revision.getClass().getName());
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we catch that error before we create the publisher and return then a NullPublisher?

@XiongKezhi
Copy link
Contributor Author

Since this PR diverged so much with #26, I think we can close this first and reopen a new PR on this fixing after we merged that? @timja @uhafner

@XiongKezhi XiongKezhi closed this Aug 24, 2020
@XiongKezhi XiongKezhi deleted the resolve-commit-from-build branch August 24, 2020 08:23
@XiongKezhi
Copy link
Contributor Author

Closed due to it has diverged too much with the master branch after #26. Reimplemented in #34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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