-
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
Don't store actions on jobs #99
Conversation
881b235
to
2b3f687
Compare
2b3f687
to
cf24011
Compare
Codecov Report
@@ Coverage Diff @@
## master #99 +/- ##
============================================
+ Coverage 82.55% 82.56% +0.01%
- Complexity 145 149 +4
============================================
Files 13 13
Lines 430 436 +6
Branches 43 43
============================================
+ Hits 355 360 +5
- Misses 56 57 +1
Partials 19 19
Continue to review full report at Codecov.
|
@@ -45,7 +48,8 @@ | |||
*/ | |||
GitHubSCMSourceChecksContext(final Job<?, ?> job, final String jobURL, final SCMFacade scmFacade) { | |||
super(job, jobURL, scmFacade); | |||
sha = resolveHeadSha(job); | |||
this.run = null; |
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.
This PMD warning is annoying 😤
Since we don't have a null object pattern for the run, I can't find a way to solve this other than shooting the message.
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 could make run a Optional<Run<?, ?>>
, but I gather that is frowned upon too?
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, right! I always thought possessing an optional inside a class makes another warning, can't remember where I saw this...
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.
Well IntelliJ doesn’t like it, and IntelliJ is right about everything 😉
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.
Well, I think the warning makes sense here. We introduced two constructors to avoid the problem of assigning null
to the run. If you keep it this way you can remove the constructor as well
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 guess we could have static fromRun
and fromJob
methods...
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 would you prefer something like:
static GitHubSCMSourceChecksContext fromRun(final Run<?, ?> run, final String runURL, final SCMFacade scmFacade) {
return new GitHubSCMSourceChecksContext(run.getParent(), run, runURL, scmFacade);
}
static GitHubSCMSourceChecksContext fromJob(final Job<?, ?> job, final String runURL, final SCMFacade scmFacade) {
return new GitHubSCMSourceChecksContext(job, null, runURL, scmFacade);
}
/**
* Creates a {@link GitHubSCMSourceChecksContext} according to the run. All attributes are computed during this period.
*
* @param job
* a GitHub Branch Source project
* @param run
* a run of a GitHub Branch Source project
* @param runURL
* the URL to the Jenkins run
* @param scmFacade
* a facade for Jenkins SCM
*/
private GitHubSCMSourceChecksContext(final Job<?, ?> job, @CheckForNull final Run<?, ?> run, final String runURL, final SCMFacade scmFacade) {
super(job, runURL, scmFacade);
this.run = run;
this.sha = Optional.ofNullable(run).map(this::resolveHeadSha).orElse(resolveHeadSha(job));
}
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.
That moves (and duplicates) the logic for creating the context from a run into the calling code, which I don't think looks as nice.
it's ok 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.
I think we don't have to have the static methods, after all, the context is only used inside this package; they just add up the complexity.
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 advantage behind having this way (preserved from having two constructors) is that it greatly reduces the chances of creating a GitHubSCMSourceChecksContext
where the run does not belong to the job. I appreciate, as you say, that it's only used within the package but it still feels like a smell to have to duplicate the run.getParent(), run
logic throughout the test code.
Hmm, odd that it hasn't failed the run? |
Because there's a default threshold for PMD inherited in our pipeline step. |
that doesn't mean we should merge it with a known warning, it just means someone else will end up needing to fix it later |
There's something odd going on with failsafe - it's reporting the newly parametrized edit: ah, it appears to be a known issue scheduled for fixing in M6. |
@@ -38,6 +38,11 @@ | |||
this.run = run; | |||
} | |||
|
|||
@Override | |||
protected Optional<Run<?, ?>> getRun() { |
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.
Where is this new method consumed? Maybe we should better use the tell don't ask pattern.
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's used in getId
, getAction
and addActionIfMissing
on GitHubChecksContext
.
I did initially consider moving the Run
member up to the parent GitHubChecksContext
, but marking it as nullable would mean a lot of unnecessary null checks in GitSCMChecksContext
, where it's known to never be null.
@@ -45,7 +48,8 @@ | |||
*/ | |||
GitHubSCMSourceChecksContext(final Job<?, ?> job, final String jobURL, final SCMFacade scmFacade) { | |||
super(job, jobURL, scmFacade); | |||
sha = resolveHeadSha(job); | |||
this.run = null; |
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.
In the beginning of the project we had one constructor for this class that sets all not used values to null
, so if it makes sense we can combine the two constructors.
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.
LGTM now.
Maybe I need to revisit the design of context sometime, it looks like the run
is the norm (which should be held in the base class) and the job
is an exception which is only used in our queue listener. @uhafner do you think so?
No description provided.