horizoncd/horizon

View on GitHub
pkg/environment/dao/dao.go

Summary

Maintainability
C
1 day
Test Coverage

Showing 5 of 5 total issues

Method dao.DeleteByID has 6 return statements (exceeds 4 allowed).
Open

func (d *dao) DeleteByID(ctx context.Context, id uint) error {
environment, err := d.GetByID(ctx, id)
if err != nil {
return err
}
Severity: Major
Found in pkg/environment/dao/dao.go - About 40 mins 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 4 locations. Consider refactoring.
    Open

    func (d *dao) GetByID(ctx context.Context, id uint) (*models.Environment, error) {
    var environment models.Environment
    result := d.db.WithContext(ctx).Raw(common.EnvironmentGetByID, id).First(&environment)
     
    if result.Error != nil {
    Severity: Major
    Found in pkg/environment/dao/dao.go and 3 other locations - About 2 hrs to fix
    pkg/environment/dao/dao.go on lines 135..147
    pkg/environmentregion/dao/dao.go on lines 69..81
    pkg/environmentregion/dao/dao.go on lines 127..139

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

    func (d *dao) GetByName(ctx context.Context, name string) (*models.Environment, error) {
    var environment models.Environment
    result := d.db.WithContext(ctx).Raw(common.EnvironmentGetByName, name).First(&environment)
     
    if result.Error != nil {
    Severity: Major
    Found in pkg/environment/dao/dao.go and 3 other locations - About 2 hrs to fix
    pkg/environment/dao/dao.go on lines 121..133
    pkg/environmentregion/dao/dao.go on lines 69..81
    pkg/environmentregion/dao/dao.go on lines 127..139

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

    func (d *dao) CreateEnvironment(ctx context.Context, environment *models.Environment) (*models.Environment, error) {
    result := d.db.WithContext(ctx).Create(environment)
     
    if result.Error != nil {
    return nil, herrors.NewErrInsertFailed(herrors.EnvironmentRegionInDB, result.Error.Error())
    Severity: Major
    Found in pkg/environment/dao/dao.go and 4 other locations - About 1 hr to fix
    pkg/pr/dao/check.go on lines 87..95
    pkg/pr/dao/message.go on lines 27..35
    pkg/pr/dao/pipelinerun.go on lines 58..66
    pkg/region/dao/dao.go on lines 122..130

    There are no issues that match your filters.

    Category
    Status