auto-staging/tower

View on GitHub

Showing 22 of 32 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func GetSingleEnvironmentStatusInformationController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    obj := types.EnvironmentStatus{}
    branch, err := url.PathUnescape(request.PathParameters["branch"])
    if err != nil {
        config.Logger.Log(err, map[string]string{"module": "controller/GetSingleEnvironmentStatusInformationController", "operation": "pathUnescape"}, 0)
Severity: Major
Found in controller/status.go and 1 other location - About 3 hrs to fix
controller/environments.go on lines 72..95

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 279.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function AddEnvironmentForRepository has 101 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func AddEnvironmentForRepository(environment types.EnvironmentPost, name string) (types.Environment, error) {
    svc := getDynamoDbClient()

    creation := time.Now().UTC()

Severity: Major
Found in model/environments.go - About 3 hrs to fix

    Function UpdateEnvironment has 84 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func UpdateEnvironment(environment *types.EnvironmentPut, name string, branch string) (types.Environment, error) {
        svc := getDynamoDbClient()
    
        updateStruct := types.EnvironmentUpdate{
            InfrastructureRepoURL: environment.InfrastructureRepoURL,
    Severity: Major
    Found in model/environments.go - About 2 hrs to fix

      Function Handler has 22 return statements (exceeds 4 allowed).
      Open

      func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
      
          if request.Resource == "/configuration" && request.HTTPMethod == http.MethodGet {
              return controller.GetConfigurationController(request)
          }
      Severity: Major
      Found in main.go - About 2 hrs to fix

        Function Handler has 64 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
        
            if request.Resource == "/configuration" && request.HTTPMethod == http.MethodGet {
                return controller.GetConfigurationController(request)
            }
        Severity: Minor
        Found in main.go - About 1 hr to fix

          Function GitHubWebhookCreateController has 11 return statements (exceeds 4 allowed).
          Open

          func GitHubWebhookCreateController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
              if !verifyHMAC(request.Body, request.Headers["X-Hub-Signature"]) {
                  return events.APIGatewayProxyResponse{Body: "{ \"message\" : \"HMAC validation failed\" }", StatusCode: 400}, nil
              }
          
          
          Severity: Major
          Found in controller/webhooks-github.go - About 1 hr to fix

            Function TriggerEnvironemtStatusChangeController has 10 return statements (exceeds 4 allowed).
            Open

            func TriggerEnvironemtStatusChangeController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                trigger := types.TriggerSchedulePost{}
                err := json.Unmarshal([]byte(request.Body), &trigger)
                if err != nil {
                    return types.InvalidRequestBodyResponse, nil
            Severity: Major
            Found in controller/triggers.go - About 1 hr to fix

              Function PutSinglEnvironmentForRepositoryController has 9 return statements (exceeds 4 allowed).
              Open

              func PutSinglEnvironmentForRepositoryController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                  status := types.EnvironmentStatus{}
                  branch, err := url.PathUnescape(request.PathParameters["branch"])
                  if err != nil {
                      config.Logger.Log(err, map[string]string{"module": "controller/PutSinglEnvironmentForRepositoryController", "operation": "pathUnescape"}, 0)
              Severity: Major
              Found in controller/environments.go - About 55 mins to fix

                Function UpdateEnvironment has 8 return statements (exceeds 4 allowed).
                Open

                func UpdateEnvironment(environment *types.EnvironmentPut, name string, branch string) (types.Environment, error) {
                    svc := getDynamoDbClient()
                
                    updateStruct := types.EnvironmentUpdate{
                        InfrastructureRepoURL: environment.InfrastructureRepoURL,
                Severity: Major
                Found in model/environments.go - About 50 mins to fix

                  Function GitHubWebhookDeleteController has 8 return statements (exceeds 4 allowed).
                  Open

                  func GitHubWebhookDeleteController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                      if !verifyHMAC(request.Body, request.Headers["X-Hub-Signature"]) {
                          return events.APIGatewayProxyResponse{Body: "{ \"message\" : \"HMAC validation failed\" }", StatusCode: 400}, nil
                      }
                  
                  
                  Severity: Major
                  Found in controller/webhooks-github.go - About 50 mins to fix

                    Function AddEnvironmentForRepository has 8 return statements (exceeds 4 allowed).
                    Open

                    func AddEnvironmentForRepository(environment types.EnvironmentPost, name string) (types.Environment, error) {
                        svc := getDynamoDbClient()
                    
                        creation := time.Now().UTC()
                    
                    
                    Severity: Major
                    Found in model/environments.go - About 50 mins to fix

                      Function AddEnvironmentForRepositoryController has 7 return statements (exceeds 4 allowed).
                      Open

                      func AddEnvironmentForRepositoryController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                          env := types.EnvironmentPost{}
                          err := json.Unmarshal([]byte(request.Body), &env)
                          if err != nil {
                              return types.InvalidRequestBodyResponse, nil
                      Severity: Major
                      Found in controller/environments.go - About 45 mins to fix

                        Function AddRepositoryController has 6 return statements (exceeds 4 allowed).
                        Open

                        func AddRepositoryController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                            repo := types.Repository{}
                            err := json.Unmarshal([]byte(request.Body), &repo)
                            if err != nil {
                                return types.InvalidRequestBodyResponse, nil
                        Severity: Major
                        Found in controller/repositories.go - About 40 mins to fix

                          Function DeleteSingleEnvironmentController has 6 return statements (exceeds 4 allowed).
                          Open

                          func DeleteSingleEnvironmentController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                              status := types.EnvironmentStatus{}
                              branch, err := url.PathUnescape(request.PathParameters["branch"])
                              if err != nil {
                                  config.Logger.Log(err, map[string]string{"module": "controller/DeleteSingleEnvironmentController", "operation": "pathUnescape"}, 0)
                          Severity: Major
                          Found in controller/environments.go - About 40 mins to fix

                            Function PutSingleRepositoryController has 6 return statements (exceeds 4 allowed).
                            Open

                            func PutSingleRepositoryController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                                repository := types.Repository{}
                                err := json.Unmarshal([]byte(request.Body), &repository)
                                if err != nil {
                                    config.Logger.Log(err, map[string]string{"module": "controller/PutSingleRepositoryController", "operation": "unmarshal"}, 4)
                            Severity: Major
                            Found in controller/repositories.go - About 40 mins to fix

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if status.Status != "running" && status.Status != "stopped" && status.Status != "initiating failed" && status.Status != "destroying failed" {
                                      config.Logger.Log(errors.New("Can't delete environment in status = "+status.Status), map[string]string{"module": "controller/GitHubWebhookDeleteController", "operation": "statusCheck"}, 0)
                                      return types.InvalidEnvironmentStatusResponse, nil
                                  }
                              Severity: Minor
                              Found in controller/webhooks-github.go and 1 other location - About 40 mins to fix
                              controller/environments.go on lines 164..167

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 108.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if status.Status != "running" && status.Status != "stopped" && status.Status != "initiating failed" && status.Status != "destroying failed" {
                                      config.Logger.Log(errors.New("Can't delete environment in status = "+status.Status), map[string]string{"module": "controller/DeleteSingleEnvironmentController", "operation": "statusCheck"}, 0)
                                      return types.InvalidEnvironmentStatusResponse, nil
                                  }
                              Severity: Minor
                              Found in controller/environments.go and 1 other location - About 40 mins to fix
                              controller/webhooks-github.go on lines 116..119

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 108.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Function GetSingleEnvironmentStatusInformationController has 5 return statements (exceeds 4 allowed).
                              Open

                              func GetSingleEnvironmentStatusInformationController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                                  obj := types.EnvironmentStatus{}
                                  branch, err := url.PathUnescape(request.PathParameters["branch"])
                                  if err != nil {
                                      config.Logger.Log(err, map[string]string{"module": "controller/GetSingleEnvironmentStatusInformationController", "operation": "pathUnescape"}, 0)
                              Severity: Major
                              Found in controller/status.go - About 35 mins to fix

                                Function GetSingleEnvironmentForRepositoryController has 5 return statements (exceeds 4 allowed).
                                Open

                                func GetSingleEnvironmentForRepositoryController(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
                                    obj := types.Environment{}
                                    branch, err := url.PathUnescape(request.PathParameters["branch"])
                                    if err != nil {
                                        config.Logger.Log(err, map[string]string{"module": "controller/GetSingleEnvironmentForRepositoryController", "operation": "pathUnescape"}, 0)
                                Severity: Major
                                Found in controller/environments.go - About 35 mins to fix

                                  Function DeleteSingleEnvironment has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func DeleteSingleEnvironment(name string, branch string) error {
                                      // Invoke Builder Lambda to delete schedules
                                      event := types.BuilderEvent{
                                          Operation:  "DELETE_SCHEDULE",
                                          Branch:     branch,
                                  Severity: Major
                                  Found in model/environments.go - About 35 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language