Showing 676 of 677 total issues
Method dao.UpsertByResourceTypeID
has 5 return statements (exceeds 4 allowed). Open
Open
func (d dao) UpsertByResourceTypeID(ctx context.Context, resourceType string,
resourceID uint, tags []*models.Tag) error {
// 1. if tags is empty, delete all tags
if len(tags) == 0 {
result := d.db.WithContext(ctx).Exec(common.TagDeleteAllByResourceTypeID, resourceType, resourceID)
Function jsonPatch
has 5 return statements (exceeds 4 allowed). Open
Open
func jsonPatch(obj interface{}, patchJSON []byte) (interface{}, error) {
objJSON, err := json.Marshal(obj)
if err != nil {
return nil, err
}
Function InitClient
has 5 return statements (exceeds 4 allowed). Open
Open
func InitClient(kubeconfig string) (*Client, error) {
var config *rest.Config
var err error
// startWith "/", kubeconfig is a filePath, else kubeconfig is fileContent
Method cd.GetPodEvents
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *cd) GetPodEvents(ctx context.Context,
params *GetPodEventsParams) (events []Event, err error) {
const op = "cd: get cluster pod events"
defer wlog.Start(ctx, op).StopPrint()
Method Repo.statChart
has 5 return statements (exceeds 4 allowed). Open
Open
func (h *Repo) statChart(name string, version string) (*Metadata, error) {
resp, err := h.do(http.MethodGet, h.statLink(name, version), nil)
if err != nil {
return nil, err
}
Method service.sync
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *service) sync(ctx context.Context) {
log.Info(ctx, "Start to sync grafana datasource")
logErr := func(err error) {
log.Errorf(ctx, "Sync grafana datasource error: %+v", err)
Method appGitopsRepo.GetApplication
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (g appGitopsRepo) GetApplication(ctx context.Context, application, environment string) (*GetResponse, error) {
const op = "gitlab repo: get application"
defer wlog.Start(ctx, op).StopPrint()
// 1. get data from gitlab
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method service.ParseJWTToken
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *service) ParseJWTToken(tokenStr string) (Claims, error) {
var claims Claims
_, err := jwt.ParseWithClaims(tokenStr, &claims, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, perror.Wrapf(herror.ErrTokenInvalid,
Method clusterGitopsRepo.UpdateTags
has 5 return statements (exceeds 4 allowed). Open
Open
func (g *clusterGitopsRepo) UpdateTags(ctx context.Context, application, cluster, templateName string,
tags []*tagmodels.Tag) (err error) {
const op = "cluster git repo: update tags"
defer wlog.Start(ctx, op).StopPrint()
Method helper.ListResourceEvents
has 5 return statements (exceeds 4 allowed). Open
Open
func (h *helper) ListResourceEvents(ctx context.Context, application string, param EventParam) (
eventList *corev1.EventList, err error) {
const op = "argo: list resource events"
defer wlog.Start(ctx, op).StopPrint()
Method dao.Create
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *dao) Create(ctx context.Context, application *models.Application,
extraMembers map[*usermodels.User]string) (*models.Application, error) {
err := d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
// TODO: check the group exist
Method TokenEndpointAuthMethod.UnmarshalJSON
has 5 return statements (exceeds 4 allowed). Open
Open
func (t *TokenEndpointAuthMethod) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case fmt.Sprintf("\"%s\"", ClientSecretSentAsPostStr):
*t = ClientSecretSentAsPost
Method S3Collector.GetPipelineRun
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *S3Collector) GetPipelineRun(ctx context.Context,
pr *prmodels.Pipelinerun) (*v1beta1.PipelineRun, error) {
const op = "s3Collector: getPipelineRun"
defer wlog.Start(ctx, op).StopPrint()
Method manager.Delete
has 5 return statements (exceeds 4 allowed). Open
Open
func (m manager) Delete(ctx context.Context, id uint) (int64, error) {
count, err := m.groupDAO.CountByParentID(ctx, id)
if err != nil {
return 0, err
}
Method Helper.GetTagArchive
has 5 return statements (exceeds 4 allowed). Open
Open
func (h Helper) GetTagArchive(ctx context.Context, gitURL, tagName string) (*git.Tag, error) {
pattern := regexp.MustCompile(`^(?:https://|git@)github.com[:/]([^/]+)/([^/]+?)(?:\.git)?$`)
matches := pattern.FindAllStringSubmatch(gitURL, -1)
if len(matches) == 0 || len(matches[0]) < 3 {
return nil, perror.Wrapf(herrors.ErrParamInvalid, "git url is incorrect: git url = %s", gitURL)
Method controller.UpdateTemplate
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *controller) UpdateTemplate(ctx context.Context, templateID uint, request UpdateTemplateRequest) error {
const op = "template controller: updateTemplate"
defer wlog.Start(ctx, op).StopPrint()
template, err := c.templateMgr.GetByID(ctx, templateID)
Method controller.GetClusterByName
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *controller) GetClusterByName(ctx context.Context,
clusterName string) (_ *GetClusterByNameResponse, err error) {
const op = "cluster controller: get cluster by name"
wlog.Start(ctx, op).StopPrint()
Method controller.retrieveClaimsAndUser
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *controller) retrieveClaimsAndUser(ctx context.Context) (*tokenservice.Claims, *usermodel.User, error) {
jwtTokenString, err := common.JWTTokenStringFromContext(ctx)
if err != nil {
return nil, nil, err
}
Method dao.Create
has 5 return statements (exceeds 4 allowed). Open
Open
func (d dao) Create(ctx context.Context, results *tekton.PipelineResults, data *global.HorizonMetaData) error {
prMetadata := results.Metadata
prResult := results.PrResult
trResults, stepResults := results.TrResults, results.StepResults
Method RegionList.Less
has 5 return statements (exceeds 4 allowed). Open
Open
func (r RegionList) Less(i, j int) bool {
const pre = "pre"
const online = "online"
if r[i].Environment == online {
return false