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

Don't store actions on jobs #99

Merged
merged 5 commits into from
Dec 29, 2020
Merged

Conversation

mrginglymus
Copy link
Contributor

No description provided.

@mrginglymus mrginglymus marked this pull request as ready for review December 27, 2020 15:46
@mrginglymus mrginglymus requested a review from a team as a code owner December 27, 2020 15:46
@codecov
Copy link

codecov bot commented Dec 27, 2020

Codecov Report

Merging #99 (735772d) into master (f9c6e96) will increase coverage by 0.01%.
The diff coverage is 93.75%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
...ins/plugins/checks/github/GitSCMChecksContext.java 62.00% <0.00%> (-1.27%) 16.00 <0.00> (ø)
...ins/plugins/checks/github/GitHubChecksContext.java 100.00% <100.00%> (ø) 20.00 <5.00> (+2.00)
...ns/checks/github/GitHubChecksPublisherFactory.java 100.00% <100.00%> (ø) 7.00 <1.00> (ø)
...ns/checks/github/GitHubSCMSourceChecksContext.java 100.00% <100.00%> (ø) 22.00 <4.00> (+2.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 f9c6e96...735772d. Read the comment docs.

@@ -45,7 +48,8 @@
*/
GitHubSCMSourceChecksContext(final Job<?, ?> job, final String jobURL, final SCMFacade scmFacade) {
super(job, jobURL, scmFacade);
sha = resolveHeadSha(job);
this.run = null;
Copy link
Contributor

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.

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 could make run a Optional<Run<?, ?>>, but I gather that is frowned upon too?

Copy link
Contributor

@XiongKezhi XiongKezhi Dec 27, 2020

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...

Copy link
Contributor Author

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 😉

Copy link
Member

@uhafner uhafner Dec 27, 2020

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

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 guess we could have static fromRun and fromJob methods...

Copy link
Contributor Author

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));
    }

Copy link
Contributor

@XiongKezhi XiongKezhi Dec 28, 2020

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

Copy link
Contributor

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.

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 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.

@mrginglymus
Copy link
Contributor Author

Hmm, odd that it hasn't failed the run?

@XiongKezhi
Copy link
Contributor

Hmm, odd that it hasn't failed the run?

Because there's a default threshold for PMD inherited in our pipeline step.

@timja
Copy link
Member

timja commented Dec 28, 2020

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

@mrginglymus
Copy link
Contributor Author

mrginglymus commented Dec 28, 2020

There's something odd going on with failsafe - it's reporting the newly parametrized GitHubChecksPublisherITest without a package (so it now appears in (root)), nor with any of the parameters in the testcase name (so you can't tell which ones failed).

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

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.

Copy link
Contributor Author

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

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.

Copy link
Contributor

@XiongKezhi XiongKezhi left a 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?

@XiongKezhi XiongKezhi merged commit ee26572 into jenkinsci:master Dec 29, 2020
@XiongKezhi XiongKezhi added the bug Something isn't working label Dec 29, 2020
@mrginglymus mrginglymus deleted the freestyle branch December 29, 2020 16:40
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.

4 participants