Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51984

cleanup if statements in snippet generator

    XMLWordPrintable

Details

    Description

      in relation to JENKINS-51813, and the improvement of code, the PipelineSnippetGenerator code use some tests. But also, maybe even more important than the tests is to make the code more readable. 

      this if statement in particular:
      https://github.com/jenkinsci/simple-pull-request-job-plugin/blob/4705792fa0fae8f047a7824b40e46c0ef314adcc/src/main/java/io/jenkins/plugins/sprp/PipelineSnippetGenerator.java#L143

      if(stage.getFailure() != null
                      || stage.getSuccess() != null
                      || stage.getAlways() != null
                      || (stage.getName().equals("Build") &&
                              (archiveArtifacts != null || buildResultPaths != null || findbugs != null))
                      || stage.getName().equals("Tests") && (testResultPaths != null || gitConfig.getGitUrl() != null))
      

      is hard to follow.

      These articles don't directly solve that example but should be reviewed on the different techniques that can be applied to make the code more readable.
      http://www.christianschenk.org/blog/ideas-clean-if-statements/
      https://dzone.com/articles/code-smells-if-statements

      Attachments

        Activity

          Structure of PipelineSnippetGenerator.getStage() method has been changed and the long and confusing if statement has been removed.

          gautamabhishek46 Abhishek Gautam added a comment - Structure of PipelineSnippetGenerator.getStage() method has been changed and the long and confusing if statement has been removed.

          People

            gautamabhishek46 Abhishek Gautam
            jknurek J Knurek
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: