Exit sputnik with error code if checks fail#205
Exit sputnik with error code if checks fail#205marquiswang wants to merge 1 commit intoTouK:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #205 +/- ##
===========================================
- Coverage 72.52% 71.72% -0.8%
- Complexity 592 608 +16
===========================================
Files 142 147 +5
Lines 1889 1956 +67
Branches 121 129 +8
===========================================
+ Hits 1370 1403 +33
- Misses 462 490 +28
- Partials 57 63 +6
Continue to review full report at Codecov.
|
| StashFacadeBuilder stashFacadeBuilder = new StashFacadeBuilder(); | ||
| GithubFacadeBuilder githubFacadeBuilder = new GithubFacadeBuilder(); | ||
| SaasFacadeBuilder saasFacadeBuilder = new SaasFacadeBuilder(); | ||
| LocalFacadeBuilder localFacadeBuilder = new LocalFacadeBuilder(); |
There was a problem hiding this comment.
[Checkstyle] ERROR: Variable 'localFacadeBuilder' must be private and have accessor methods.
| import pl.touk.sputnik.review.Review; | ||
| import pl.touk.sputnik.review.ReviewFile; | ||
|
|
||
| import java.util.ArrayList; |
There was a problem hiding this comment.
[Checkstyle] ERROR: Unused import - java.util.ArrayList.
SpOOnman
left a comment
There was a problem hiding this comment.
I like your idea. What do you think of a Score object? Can it be better than enum?
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class LocalFacadeBuilder { |
There was a problem hiding this comment.
Please rebase with sputnik:master so these diffs will go away.
| String scoreStrategyName = scoreStrategyName(); | ||
| if (!ScoreStrategy.isValidScoreStrategy(scoreStrategyName)) { | ||
| log.warn("Score strategy {} not found, using default ScoreAlwaysPass", scoreStrategyName); | ||
| } | ||
|
|
||
| Score score = ScoreStrategy.of(scoreStrategyName).score(review); | ||
| review.setScore(score); | ||
| log.info("{} violations found, {} errors. Adding score {}", | ||
| review.getTotalViolationCount(), | ||
| review.getViolationCount().get(Severity.ERROR), | ||
| score); | ||
|
|
There was a problem hiding this comment.
This looks like a class or a visitor to me. What do you think?
| } | ||
|
|
||
| @NotNull | ||
| private String scoreStrategyName() { |
There was a problem hiding this comment.
I think this code does not belong to Engine. It should be moved elsewhere.
| @@ -0,0 +1,9 @@ | |||
| package pl.touk.sputnik.engine.score; | |||
|
|
|||
| public enum Score { | |||
There was a problem hiding this comment.
I think we miss opportunity here. There is a degradation of how much information we have. I'm not sure how much information this object should contain for now, but I feel this is too little.
There was a problem hiding this comment.
My thought is that old code returned a singleton map of label and score. However, the label and numerical score were never affected by the review processors - it was just configuration that was passed through. The only actual information that is necessary is the pass condition.
In fact, the label and numerical score is unused by all of the ReviewPublishers except for the Gerrit one. This felt more generic.
There was a problem hiding this comment.
You are right about previous implementation. I just thought we can pass an object here with enum inside and some other information in future.
| } | ||
|
|
||
| @NotNull | ||
| private ScoreStrategy getScoreStrategy(String aScoreStrategy, String aS) { |
There was a problem hiding this comment.
aScoreStrategy is not used here and aS is too short for a parameter name.
There was a problem hiding this comment.
How embarrassing. I'll fix this.
| }; | ||
|
|
||
|
|
||
| private static final String NOSCORE = "NOSCORE"; |
There was a problem hiding this comment.
There is a code duplication here. It's the same code as in ScoreStrategies.
|
|
||
| import java.util.Set; | ||
|
|
||
| public enum ScoreStrategy { |
There was a problem hiding this comment.
I am not happy with this refactoring. This is a business login implementation within enum methods. You've moved builder into a map. I prefer it the way it was before.
There was a problem hiding this comment.
The intention was to use implement a strategy pattern with enums, since there's no state so there only needs to be one instance of each one. I can revert this to ScoreStrategy being an interface with 4 implementations if you prefer. You no longer need a builder because there's nothing to build.
The advantage of this is that you can still do logging. Yeah that's a good advantage. I will do that.
| } | ||
|
|
||
| @NotNull | ||
| private GerritScoreLabeler scoreLabeler(Configuration configuration) { |
There was a problem hiding this comment.
I think this fits more to ReviewInputBuilder.
|
I've made a change in master branch that fixed one but so I guess you must rebase again. |
b3bf26d to
0f22161
Compare
Robot comments show up in the Findings tab, instead of in the comments. This makes it much easier to differentiate from them a reviewer's comments. The API requires a "runId" for the comment. I've chosen to just send a random UUID for now, but eventually we could wire in something like a build number or something.
This allows scripts/tools to take the return result into account.
Furthermore, Extensions of sputnik like the sputnik-maven-plugin can use
a return value of the Engine to communicate the result of a run and do
something like fail a build.
Implement this by adding a Score object (with the review label and the
score value as fields) and return that in Engine.run().
If a failing score value (< 0) is returned, then call System.exit with
the score as the error status.