horizoncd/horizon

View on GitHub

Showing 676 of 677 total issues

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

func (d dao) GetRefOfApplication(ctx context.Context, id uint) ([]*amodels.Application, uint, error) {
onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
var (
applications []*amodels.Application
total uint
Severity: Major
Found in pkg/template/dao/dao.go and 3 other locations - About 4 hrs to fix
pkg/template/dao/dao.go on lines 138..158
pkg/templaterelease/dao/dao.go on lines 108..128
pkg/templaterelease/dao/dao.go on lines 130..150

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

func (a *API) GetWebhookLog(c *gin.Context) {
const op = "webhook: get log"
idStr := c.Param(_webhookLogIDParam)
id, err := strconv.ParseUint(idStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/webhook/apis.go and 2 other locations - About 4 hrs to fix
core/http/api/v2/webhook/apis.go on lines 138..162
core/http/api/v2/webhook/apis.go on lines 254..278

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

func (d dao) GetRefOfCluster(ctx context.Context, id uint) ([]*cmodel.Cluster, uint, error) {
onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
var (
clusters []*cmodel.Cluster
total uint
Severity: Major
Found in pkg/template/dao/dao.go and 3 other locations - About 4 hrs to fix
pkg/template/dao/dao.go on lines 116..136
pkg/templaterelease/dao/dao.go on lines 108..128
pkg/templaterelease/dao/dao.go on lines 130..150

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

func (a *API) GetWebhook(c *gin.Context) {
const op = "webhook: get"
idStr := c.Param(_webhookIDParam)
id, err := strconv.ParseUint(idStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/webhook/apis.go and 2 other locations - About 4 hrs to fix
core/http/api/v2/webhook/apis.go on lines 228..252
core/http/api/v2/webhook/apis.go on lines 254..278

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

func (d dao) GetRefOfApplication(ctx context.Context, id uint) ([]*amodels.Application, uint, error) {
onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
var (
applications []*amodels.Application
total uint
Severity: Major
Found in pkg/templaterelease/dao/dao.go and 3 other locations - About 4 hrs to fix
pkg/template/dao/dao.go on lines 116..136
pkg/template/dao/dao.go on lines 138..158
pkg/templaterelease/dao/dao.go on lines 130..150

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

func (a *API) ResendWebhook(c *gin.Context) {
const op = "webhook: resend"
idStr := c.Param(_webhookLogIDParam)
id, err := strconv.ParseUint(idStr, 10, 0)
if err != nil {
Severity: Major
Found in core/http/api/v2/webhook/apis.go and 2 other locations - About 4 hrs to fix
core/http/api/v2/webhook/apis.go on lines 138..162
core/http/api/v2/webhook/apis.go on lines 228..252

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

func (d dao) GetRefOfCluster(ctx context.Context, id uint) ([]*cmodel.Cluster, uint, error) {
onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
var (
clusters []*cmodel.Cluster
total uint
Severity: Major
Found in pkg/templaterelease/dao/dao.go and 3 other locations - About 4 hrs to fix
pkg/template/dao/dao.go on lines 116..136
pkg/template/dao/dao.go on lines 138..158
pkg/templaterelease/dao/dao.go on lines 108..128

File util.go has 588 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 pkg/cd/util.go - About 4 hrs to fix

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

    func (s *service) listTemplateMembers(ctx context.Context, resourceID uint) ([]models.Member, error) {
    var (
    retMembers []models.Member
    members []models.Member
    err error
    Severity: Major
    Found in pkg/member/service/service.go and 1 other location - About 4 hrs to fix
    pkg/member/service/service.go on lines 461..493

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

    func (s *service) listApplicationMembers(ctx context.Context, resourceID uint) ([]models.Member, error) {
    var (
    retMembers []models.Member
    members []models.Member
    err error
    Severity: Major
    Found in pkg/member/service/service.go and 1 other location - About 4 hrs to fix
    pkg/member/service/service.go on lines 547..579

    File controller_operation.go has 582 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/controller/cluster/controller_operation.go - About 4 hrs to fix

      Method controller.createPipelineRun has 124 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
      r *CreatePipelineRunRequest) (*prmodels.Pipelinerun, error) {
      defer wlog.Start(ctx, "cluster controller: create pipeline run").StopPrint()
       
      cluster, err := c.clusterMgr.GetByID(ctx, clusterID)
      Severity: Major
      Found in core/controller/cluster/controller_basic_v2.go - About 3 hrs to fix

        Method controller.GetByFullPath has 124 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *controller) GetByFullPath(ctx context.Context,
        resourcePath string, resourceType string) (*service.Child, error) {
        const op = "get record by fullPath"
        defer wlog.Start(ctx, op).StopPrint()
         
         
        Severity: Major
        Found in core/controller/group/controller.go - About 3 hrs to fix

          Function process has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
          Open

          func process(ctx context.Context, jobConfig *autofree.Config, clusterCtr clusterctl.Controller,
          prCtr prctl.Controller) {
          op := "job: cluster auto-free"
          query := &q.Query{
          PageNumber: common.DefaultPageNumber,
          Severity: Minor
          Found in pkg/jobs/autofree/autofree.go - About 3 hrs to fix

          Method controller.CreateClusterV2 has 122 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (c *controller) CreateClusterV2(ctx context.Context,
          params *CreateClusterParamsV2) (*CreateClusterResponseV2, error) {
          const op = "cluster controller: create cluster v2"
          defer wlog.Start(ctx, op).StopPrint()
           
           
          Severity: Major
          Found in core/controller/cluster/controller_basic_v2.go - About 3 hrs to fix

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

            func (a *API) DeleteByID(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 104..128

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

            func (a *API) DeleteByID(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 97..121

            Method controller.BuildDeploy has 121 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *controller) BuildDeploy(ctx context.Context, clusterID uint,
            r *BuildDeployRequest) (_ *BuildDeployResponse, err error) {
            const op = "cluster controller: build deploy"
            defer wlog.Start(ctx, op).StopPrint()
             
             
            Severity: Major
            Found in core/controller/cluster/controller_build_deploy.go - About 3 hrs to fix

              Method clusterGitopsRepo.GetCluster has 120 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (g *clusterGitopsRepo) GetCluster(ctx context.Context,
              application, cluster, templateName string) (_ *ClusterFiles, err error) {
              const op = "cluster git repo: get cluster"
              defer wlog.Start(ctx, op).StopPrint()
               
               
              Severity: Major
              Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 3 hrs to fix

                Method controller.List has a Cognitive Complexity of 41 (exceeds 20 allowed). Consider refactoring.
                Open

                func (c *controller) List(ctx context.Context, query *q.Query) (
                listApplicationResp []*ListApplicationResponse, count int, err error) {
                const op = "application controller: list application"
                defer wlog.Start(ctx, op).StopPrint()
                 
                 
                Severity: Minor
                Found in core/controller/application/controller.go - About 3 hrs to fix
                Severity
                Category
                Status
                Source
                Language