horizoncd/horizon

View on GitHub

Showing 676 of 677 total issues

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

func (a *API) ClusterPipelinerunStatus(c *gin.Context) {
op := "cluster: cluster pipelinerun status"
clusterIDStr := c.Param(common.ParamClusterID)
clusterID, err := strconv.ParseUint(clusterIDStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/cluster/apis_operation.go and 2 other locations - About 3 hrs to fix
core/http/api/v2/cluster/apis_operation.go on lines 137..157
core/http/api/v2/cluster/apis_operation.go on lines 159..179

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

func (a *API) ClusterStatus(c *gin.Context) {
op := "cluster: cluster status"
clusterIDStr := c.Param(common.ParamClusterID)
clusterID, err := strconv.ParseUint(clusterIDStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/cluster/apis_operation.go and 2 other locations - About 3 hrs to fix
core/http/api/v2/cluster/apis_operation.go on lines 137..157
core/http/api/v2/cluster/apis_operation.go on lines 181..201

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

func (a *API) GetStep(c *gin.Context) {
op := "cluster: get step"
clusterIDStr := c.Param(common.ParamClusterID)
clusterID, err := strconv.ParseUint(clusterIDStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/cluster/apis_operation.go and 2 other locations - About 3 hrs to fix
core/http/api/v2/cluster/apis_operation.go on lines 159..179
core/http/api/v2/cluster/apis_operation.go on lines 181..201

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

func (a *API) DeleteByID(c *gin.Context) {
idStr := c.Param(_environmentRegionIDParam)
id, err := strconv.ParseUint(idStr, 10, 0)
if err != nil {
response.AbortWithRPCError(c, rpcerror.ParamError.WithErrMsg(fmt.Sprintf("invalid id: %s, err: %s",
Severity: Major
Found in core/http/api/v2/environmentregion/apis.go and 1 other location - About 3 hrs to fix
core/http/api/v2/environmentregion/apis.go on lines 78..100

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

func (a *API) SetDefault(c *gin.Context) {
idStr := c.Param(_environmentRegionIDParam)
id, err := strconv.ParseUint(idStr, 10, 0)
if err != nil {
response.AbortWithRPCError(c, rpcerror.ParamError.WithErrMsg(fmt.Sprintf("invalid id: %s, err: %s",
Severity: Major
Found in core/http/api/v2/environmentregion/apis.go and 1 other location - About 3 hrs to fix
core/http/api/v2/environmentregion/apis.go on lines 102..124

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

func (c *controller) RefreshToken(ctx context.Context,
req *RefreshTokenReq) (*AccessTokenResponse, error) {
accessTokenGenerator, err := c.getAccessTokenGenerator(ctx, req.ClientID)
if err != nil {
return nil, err
Severity: Major
Found in core/controller/oauth/controller.go and 1 other location - About 3 hrs to fix
core/controller/oauth/controller.go on lines 135..161

Function Middleware has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
Open

func Middleware(param *param.Param, applicationRegionCtl applicationregion.Controller,
mgr *managerparam.Manager, skippers ...middleware.Skipper) gin.HandlerFunc {
return middleware.New(func(c *gin.Context) {
// for request to create cluster, set default region to scope if not provided
if _createClusterURLPattern.MatchString(c.Request.URL.Path) &&
Severity: Minor
Found in core/middleware/scope/scope.go - About 3 hrs to fix

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

func (c *controller) GenAccessToken(ctx context.Context, req *AccessTokenReq) (*AccessTokenResponse, error) {
accessTokenGenerator, err := c.getAccessTokenGenerator(ctx, req.ClientID)
if err != nil {
return nil, err
}
Severity: Major
Found in core/controller/oauth/controller.go and 1 other location - About 3 hrs to fix
core/controller/oauth/controller.go on lines 163..190

Method clusterGitopsRepo.UpdateCluster has 102 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (g *clusterGitopsRepo) UpdateCluster(ctx context.Context, params *UpdateClusterParams) error {
const op = "cluster git repo: update cluster"
defer wlog.Start(ctx, op).StopPrint()
 
currentUser, err := common.UserFromContext(ctx)
Severity: Major
Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 3 hrs to fix

    Method dao.List has 101 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (d *dao) List(ctx context.Context, query *q.Query, userID uint,
    withRegion bool, appIDs ...uint) (int, []*models.ClusterWithRegion, error) {
    var (
    clusters []*models.ClusterWithRegion
    total int64
    Severity: Major
    Found in pkg/cluster/dao/dao.go - About 3 hrs to fix

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

      type DAO interface {
      // CreateEnvironment create a environment
      CreateEnvironment(ctx context.Context, environment *models.Environment) (*models.Environment, error)
      // ListAllEnvironment list all environments
      ListAllEnvironment(ctx context.Context) ([]*models.Environment, error)
      Severity: Major
      Found in pkg/environment/dao/dao.go and 1 other location - About 3 hrs to fix
      pkg/environment/manager/manager.go on lines 33..46

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

      type Manager interface {
      // CreateEnvironment create a environment
      CreateEnvironment(ctx context.Context, environment *models.Environment) (*models.Environment, error)
      // ListAllEnvironment list all environments
      ListAllEnvironment(ctx context.Context) ([]*models.Environment, error)
      Severity: Major
      Found in pkg/environment/manager/manager.go and 1 other location - About 3 hrs to fix
      pkg/environment/dao/dao.go on lines 29..42

      File apis.go has 542 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: Minor
      Found in core/http/api/v2/template/apis.go - About 3 hrs to fix

        Method ArgoServer.GetApplicationTree has 100 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (argoServer *ArgoServer) GetApplicationTree(w http.ResponseWriter, r *http.Request) {
        if strings.Contains(r.URL.Path, "notfound") {
        w.WriteHeader(http.StatusNotFound)
        return
        }
        Severity: Major
        Found in pkg/argocd/mock/mock.go - About 3 hrs to fix

          helper has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          type helper struct {
          client *gitlab.Client
          httpURL string
          }
          Severity: Minor
          Found in lib/gitlab/gitlab.go - About 3 hrs to fix

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

            func (a *API) GetByID(c *gin.Context) {
            regionIDStr := c.Param(_regionIDParam)
            regionID, err := strconv.ParseUint(regionIDStr, 10, 0)
            if err != nil {
            response.AbortWithRPCError(c, rpcerror.ParamError.WithErrMsg(fmt.Sprintf("invalid regionID: %s, err: %s",
            Severity: Major
            Found in core/http/api/v2/region/apis.go and 1 other location - About 3 hrs to fix
            core/http/api/v2/registry/apis.go on lines 123..143

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

            func (a *API) GetByID(c *gin.Context) {
            idStr := c.Param(_registryIDParam)
            id, err := strconv.ParseUint(idStr, 10, 0)
            if err != nil {
            response.AbortWithRPCError(c, rpcerror.ParamError.WithErrMsg(fmt.Sprintf("invalid id: %s, err: %s",
            Severity: Major
            Found in core/http/api/v2/registry/apis.go and 1 other location - About 3 hrs to fix
            core/http/api/v2/region/apis.go on lines 130..150

            Function parsePod has 99 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func parsePod(ctx context.Context, clusterInfo *ClusterState,
            pod *corev1.Pod, events []*corev1.Event) (err error) {
            const deploymentPodTemplateHash = "pod-template-hash"
            const rolloutPodTemplateHash = "rollouts-pod-template-hash"
             
             
            Severity: Major
            Found in pkg/cd/util.go - About 2 hrs to fix

              Method controller.CreateCluster has 99 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (c *controller) CreateCluster(ctx context.Context, applicationID uint, environment,
              region string, r *CreateClusterRequest, mergePatch bool) (_ *GetClusterResponse, err error) {
              const op = "cluster controller: create cluster"
              defer wlog.Start(ctx, op).StopPrint()
               
               
              Severity: Major
              Found in core/controller/cluster/controller_basic.go - About 2 hrs to fix

                Method controller.GetClusterStatus has 99 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (c *controller) GetClusterStatus(ctx context.Context, clusterID uint) (_ *GetClusterStatusResponse, err error) {
                const op = "cluster controller: get cluster status"
                defer wlog.Start(ctx, op).StopPrint()
                 
                resp := &GetClusterStatusResponse{}
                Severity: Major
                Found in core/controller/cluster/controller_status.go - About 2 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language