horizoncd/horizon

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

Summary

Maintainability
C
1 day
Test Coverage

Showing 5 of 5 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/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 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

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

func (d dao) ListByTemplateName(ctx context.Context, templateName string) ([]*models.TemplateRelease, error) {
var trs []*models.TemplateRelease
result := d.db.WithContext(ctx).Raw(common.TemplateReleaseQueryByTemplateName, templateName).Scan(&trs)
if result.Error != nil {
return nil, herrors.NewErrGetFailed(herrors.TemplateReleaseInDB, result.Error.Error())
Severity: Major
Found in pkg/templaterelease/dao/dao.go and 1 other location - About 1 hr to fix
pkg/templateschematag/dao/dao.go on lines 42..51

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

func (d dao) GetByTemplateNameAndRelease(ctx context.Context,
templateName, release string) (*models.TemplateRelease, error) {
var tr models.TemplateRelease
result := d.db.WithContext(ctx).Raw(common.TemplateReleaseQueryByTemplateNameAndName,
templateName, release).First(&tr)
Severity: Major
Found in pkg/templaterelease/dao/dao.go and 1 other location - About 1 hr to fix
pkg/environmentregion/dao/dao.go on lines 141..153

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

func (d dao) DeleteByID(ctx context.Context, id uint) error {
if res := d.db.Exec(common.TemplateReleaseDelete, id); res.Error != nil {
return perror.Wrap(herrors.NewErrDeleteFailed(herrors.TemplateInDB, res.Error.Error()),
fmt.Sprintf("failed to delete template, id = %d", id))
}
Severity: Minor
Found in pkg/templaterelease/dao/dao.go and 1 other location - About 55 mins to fix
pkg/template/dao/dao.go on lines 80..86
Category
Status