Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support for pipelinerun checks #193

Merged
merged 11 commits into from
Sep 22, 2023
Merged

Conversation

xuzhu-591
Copy link
Collaborator

@xuzhu-591 xuzhu-591 commented Sep 12, 2023

Description of your changes

  • feat: add check api
  • feat: support for pipelinerun checks

Fixes #

I have:

  • Read and followed Horizon's contribution process.
  • Run make build && make lint to ensure this PR is ready for review.

How has this code been tested

Special notes for your reviewer

@xuzhu-591 xuzhu-591 force-pushed the feat-approval branch 5 times, most recently from 3565113 to bfe8675 Compare September 18, 2023 11:28
}

func (d *dao) GetFirstCanRollbackPipelinerun(ctx context.Context, clusterID uint) (*models.Pipelinerun, error) {
func (d *pipelinerunDAO) GetFirstCanRollbackPipelinerun(ctx context.Context,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}
return pipelineBasics, nil
}
func (s *Service) GetCheckByResource(ctx context.Context, resourceID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Service.GetCheckByResource has 5 return statements (exceeds 4 allowed).

})
}

func (a *API) CreatePrMessage(c *gin.Context) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

return c.prSvc.OfPipelineBasic(ctx, pipelineRun, firstCanRollbackPipelinerun)
}

func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

} else if r.Git.Tag != "" {
gitRefType = codemodels.GitRefTypeTag
gitRef = r.Git.Tag
} else if r.Git.Branch != "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid deeply nested control flow statements.

return checkRuns, nil
}

func (d *checkDAO) CreateCheckRun(ctx context.Context, run *models.CheckRun) (*models.CheckRun, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

response.SuccessWithData(c, checkRuns)
}

func (a *API) CreateCheckRun(c *gin.Context) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -659,3 +661,185 @@ func (c *controller) ToggleLikeStatus(ctx context.Context, clusterID uint, like
}
return nil
}

func (c *controller) CreatePipelineRun(ctx context.Context, clusterID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.CreatePipelineRun has 5 return statements (exceeds 4 allowed).

return c.prSvc.OfPipelineBasic(ctx, pipelineRun, firstCanRollbackPipelinerun)
}

func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.createPipelineRun has 13 return statements (exceeds 4 allowed).

return c.execute(ctx, pr)
}

func (c *controller) execute(ctx context.Context, pr *prmodels.Pipelinerun) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.execute has 79 lines of code (exceeds 50 allowed). Consider refactoring.

@xuzhu-591 xuzhu-591 force-pushed the feat-approval branch 2 times, most recently from 3670732 to 98dcedf Compare September 19, 2023 08:10
Signed-off-by: xu.zhu <[email protected]>
}

func (d *dao) Create(ctx context.Context, pipelinerun *models.Pipelinerun) (*models.Pipelinerun, error) {
func (d *pipelinerunDAO) Create(ctx context.Context, pipelinerun *models.Pipelinerun) (*models.Pipelinerun, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

case prmodels.ActionBuildDeploy:
action = prmodels.ActionBuildDeploy

if r.Git != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

"github.com/horizoncd/horizon/pkg/pr/models"
)

type CheckDAO interface {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

return c.execute(ctx, pr)
}

func (c *controller) execute(ctx context.Context, pr *prmodels.Pipelinerun) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.execute has 12 return statements (exceeds 4 allowed).

return c.updatePrStatus(ctx, Checkrun)
}

func (c *controller) updatePrStatus(ctx context.Context, checkrun *prmodels.CheckRun) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.updatePrStatus has 5 return statements (exceeds 4 allowed).

Copy link
Collaborator

@kilosonc kilosonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments below

core/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
core/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/event/models/event.go Show resolved Hide resolved
Signed-off-by: xu.zhu <[email protected]>
Signed-off-by: xu.zhu <[email protected]>
// nolint
//
//go:generate mockgen -source=$GOFILE -destination=../../../mock/pkg/pipelinerun/manager/mock_check_manager.go
type CheckManager interface {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

return &prMessageDAO{db: db}
}

func (d *prMessageDAO) Create(ctx context.Context, prMessage *models.PRMessage) (*models.PRMessage, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -142,7 +145,7 @@ func (d *dao) GetLatestByClusterIDAndActionAndStatus(ctx context.Context,
return &pipelinerun, nil
}

func (d *dao) GetLatestSuccessByClusterID(ctx context.Context, clusterID uint) (*models.Pipelinerun, error) {
func (d *pipelinerunDAO) GetLatestSuccessByClusterID(ctx context.Context, clusterID uint) (*models.Pipelinerun, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

return c.prMgr.PipelineRun.UpdateStatusByID(ctx, checkrun.PipelineRunID, prStatus)
}

func (c *controller) calculatePrSuccessStatus(ctx context.Context,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.calculatePrSuccessStatus has 6 return statements (exceeds 4 allowed).

pkg/pr/dao/pipelinerun.go Show resolved Hide resolved
Signed-off-by: xu.zhu <[email protected]>
return c.execute(ctx, pr)
}

func (c *controller) execute(ctx context.Context, pr *prmodels.Pipelinerun) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.execute has 83 lines of code (exceeds 50 allowed). Consider refactoring.

@@ -73,7 +76,7 @@ func (d *dao) GetByID(ctx context.Context, pipelinerunID uint) (*models.Pipeline
return &pr, nil
}

func (d *dao) GetByCIEventID(ctx context.Context, ciEventID string) (*models.Pipelinerun, error) {
func (d *pipelinerunDAO) GetByCIEventID(ctx context.Context, ciEventID string) (*models.Pipelinerun, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -527,3 +528,35 @@ func (a *API) DeleteFavorite(c *gin.Context) {
}
response.Success(c)
}

func (a *API) CreatePipelineRun(c *gin.Context) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method API.CreatePipelineRun has 5 return statements (exceeds 4 allowed).

f(uint(id))
}

func (a *API) withCheckrunID(c *gin.Context, f func(pipelineRunID uint)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}
return pipelineBasics, nil
}
func (s *Service) GetCheckByResource(ctx context.Context, resourceID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Service.GetCheckByResource has 52 lines of code (exceeds 50 allowed). Consider refactoring.

Signed-off-by: xu.zhu <[email protected]>
return c.prSvc.OfPipelineBasic(ctx, pipelineRun, firstCanRollbackPipelinerun)
}

func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.createPipelineRun has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.

})
}

func (c *controller) ListPRMessages(ctx context.Context,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method controller.ListPRMessages has 57 lines of code (exceeds 50 allowed). Consider refactoring.

})
}

func (a *API) withPipelinerunID(c *gin.Context, f func(pipelineRunID uint)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -85,7 +88,7 @@ func (d *dao) GetByCIEventID(ctx context.Context, ciEventID string) (*models.Pip
return &pr, nil
}

func (d *dao) DeleteByClusterID(ctx context.Context, clusterID uint) error {
func (d *pipelinerunDAO) DeleteByClusterID(ctx context.Context, clusterID uint) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -95,7 +98,7 @@ func (d *dao) DeleteByClusterID(ctx context.Context, clusterID uint) error {
return result.Error
}

func (d *dao) DeleteByID(ctx context.Context, pipelinerunID uint) error {
func (d *pipelinerunDAO) DeleteByID(ctx context.Context, pipelinerunID uint) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@codeclimate
Copy link

codeclimate bot commented Sep 21, 2023

Code Climate has analyzed commit a5203e3 and detected 47 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 20
Duplication 27

The test coverage on the diff in this pull request is 70.6% (60% is the threshold).

This pull request will bring the total coverage in the repository to 65.9% (-0.1% change).

View more on Code Climate.

@xuzhu-591 xuzhu-591 changed the title Feat approval Feat: support for pipelinerun checks Sep 22, 2023
@xuzhu-591 xuzhu-591 merged commit d09b910 into horizoncd:main Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants