horizoncd/horizon

View on GitHub
core/controller/pipelinerun/controller.go

Summary

Maintainability
F
3 days
Test Coverage
D
66%

Showing 15 of 15 total issues

File controller.go has 768 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright © 2023 Horizoncd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Severity: Major
Found in core/controller/pipelinerun/controller.go - About 1 day to fix

    controller has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type controller struct {
    prMgr *prmanager.PRManager
    appMgr appmanager.Manager
    clusterMgr clustermanager.Manager
    envMgr envmanager.Manager
    Severity: Minor
    Found in core/controller/pipelinerun/controller.go - About 2 hrs to fix

      Method controller.executeRollback has 88 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *controller) executeRollback(ctx context.Context, application *appmodels.Application,
      cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun) error {
      // 1. get pipelinerun to rollback
      if pr.RollbackFrom == nil {
      return perror.Wrapf(herrors.ErrParamInvalid, "pipelinerun to rollback is empty")
      Severity: Major
      Found in core/controller/pipelinerun/controller.go - About 2 hrs to fix

        Method controller.executeDeploy has 67 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *controller) executeDeploy(ctx context.Context, application *appmodels.Application,
        cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun, currentUser user.User) error {
        // 1. generate a JWT token for tekton callback
        callbackToken, err := c.tokenSvc.CreateJWTToken(strconv.Itoa(int(currentUser.GetID())),
        c.tokenConfig.CallbackTokenExpireIn, tokensvc.WithPipelinerunID(pr.ID))
        Severity: Minor
        Found in core/controller/pipelinerun/controller.go - About 1 hr to fix

          Method controller.executeRollback has 17 return statements (exceeds 4 allowed).
          Open

          func (c *controller) executeRollback(ctx context.Context, application *appmodels.Application,
          cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun) error {
          // 1. get pipelinerun to rollback
          if pr.RollbackFrom == nil {
          return perror.Wrapf(herrors.ErrParamInvalid, "pipelinerun to rollback is empty")
          Severity: Major
          Found in core/controller/pipelinerun/controller.go - About 1 hr to fix

            Method controller.ListPRMessages has 58 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *controller) ListPRMessages(ctx context.Context,
            pipelineRunID uint, query *q.Query) (int, []*PRMessage, error) {
            const op = "pipelinerun controller: list pr messages"
            defer wlog.Start(ctx, op).StopPrint()
             
             
            Severity: Minor
            Found in core/controller/pipelinerun/controller.go - About 1 hr to fix

              Method controller.GetDiff has 55 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (c *controller) GetDiff(ctx context.Context, pipelinerunID uint) (_ *GetDiffResponse, err error) {
              const op = "pipelinerun controller: get pipelinerun diff"
              defer wlog.Start(ctx, op).StopPrint()
               
              // 1. get pipeline
              Severity: Minor
              Found in core/controller/pipelinerun/controller.go - About 1 hr to fix

                Method controller.executeDeploy has 9 return statements (exceeds 4 allowed).
                Open

                func (c *controller) executeDeploy(ctx context.Context, application *appmodels.Application,
                cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun, currentUser user.User) error {
                // 1. generate a JWT token for tekton callback
                callbackToken, err := c.tokenSvc.CreateJWTToken(strconv.Itoa(int(currentUser.GetID())),
                c.tokenConfig.CallbackTokenExpireIn, tokensvc.WithPipelinerunID(pr.ID))
                Severity: Major
                Found in core/controller/pipelinerun/controller.go - About 55 mins to fix

                  Method controller.executeRestart has 7 return statements (exceeds 4 allowed).
                  Open

                  func (c *controller) executeRestart(ctx context.Context, application *appmodels.Application,
                  cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun) error {
                  // 1. update pr status to running
                  if err := c.prMgr.PipelineRun.UpdateStatusByID(ctx, pr.ID, prmodels.StatusRunning); err != nil {
                  return perror.Wrapf(err, "failed to update pr status, pr = %d, status = %s",
                  Severity: Major
                  Found in core/controller/pipelinerun/controller.go - About 45 mins to fix

                    Method controller.GetDiff has 7 return statements (exceeds 4 allowed).
                    Open

                    func (c *controller) GetDiff(ctx context.Context, pipelinerunID uint) (_ *GetDiffResponse, err error) {
                    const op = "pipelinerun controller: get pipelinerun diff"
                    defer wlog.Start(ctx, op).StopPrint()
                     
                    // 1. get pipeline
                    Severity: Major
                    Found in core/controller/pipelinerun/controller.go - About 45 mins to fix

                      Method controller.calculatePrSuccessStatus has 6 return statements (exceeds 4 allowed).
                      Open

                      func (c *controller) calculatePrSuccessStatus(ctx context.Context,
                      pipelinerun *prmodels.Pipelinerun) (prmodels.PipelineStatus, error) {
                      cluster, err := c.clusterMgr.GetByIDIncludeSoftDelete(ctx, pipelinerun.ClusterID)
                      if err != nil {
                      return prmodels.StatusPending, err
                      Severity: Major
                      Found in core/controller/pipelinerun/controller.go - About 40 mins to fix

                        Method controller.StopPipelinerun has 6 return statements (exceeds 4 allowed).
                        Open

                        func (c *controller) StopPipelinerun(ctx context.Context, pipelinerunID uint) (err error) {
                        const op = "pipelinerun controller: stop pipelinerun"
                        defer wlog.Start(ctx, op).StopPrint()
                         
                        pipelinerun, err := c.prMgr.PipelineRun.GetByID(ctx, pipelinerunID)
                        Severity: Major
                        Found in core/controller/pipelinerun/controller.go - About 40 mins to fix

                          Method controller.StopPipelinerunForCluster has 6 return statements (exceeds 4 allowed).
                          Open

                          func (c *controller) StopPipelinerunForCluster(ctx context.Context, clusterID uint) (err error) {
                          const op = "pipelinerun controller: stop pipelinerun"
                          defer wlog.Start(ctx, op).StopPrint()
                           
                          if err != nil {
                          Severity: Major
                          Found in core/controller/pipelinerun/controller.go - About 40 mins to fix

                            Method controller.executeDeploy has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            func (c *controller) executeDeploy(ctx context.Context, application *appmodels.Application,
                            cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun, currentUser user.User) error {
                            Severity: Minor
                            Found in core/controller/pipelinerun/controller.go - About 35 mins to fix

                              Method controller.updatePrStatus has 5 return statements (exceeds 4 allowed).
                              Open

                              func (c *controller) updatePrStatus(ctx context.Context, checkrun *prmodels.CheckRun) error {
                              pipelinerun, err := c.prMgr.PipelineRun.GetByID(ctx, checkrun.PipelineRunID)
                              if err != nil {
                              return err
                              }
                              Severity: Major
                              Found in core/controller/pipelinerun/controller.go - About 35 mins to fix

                                There are no issues that match your filters.

                                Category
                                Status