-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
3565113
to
bfe8675
Compare
} | ||
|
||
func (d *dao) GetFirstCanRollbackPipelinerun(ctx context.Context, clusterID uint) (*models.Pipelinerun, error) { | ||
func (d *pipelinerunDAO) GetFirstCanRollbackPipelinerun(ctx context.Context, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 != "" { |
There was a problem hiding this comment.
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.
bfe8675
to
16e7722
Compare
Signed-off-by: closetool <[email protected]>
Signed-off-by: kiloson <[email protected]>
Signed-off-by: kiloson <[email protected]>
Signed-off-by: kiloson <[email protected]>
Signed-off-by: kiloson <[email protected]>
Signed-off-by: xu.zhu <[email protected]>
16e7722
to
2763d46
Compare
return checkRuns, nil | ||
} | ||
|
||
func (d *checkDAO) CreateCheckRun(ctx context.Context, run *models.CheckRun) (*models.CheckRun, error) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
3670732
to
98dcedf
Compare
Signed-off-by: xu.zhu <[email protected]>
98dcedf
to
135cf6a
Compare
} | ||
|
||
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments below
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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).
Signed-off-by: xu.zhu <[email protected]>
return c.execute(ctx, pr) | ||
} | ||
|
||
func (c *controller) execute(ctx context.Context, pr *prmodels.Pipelinerun) error { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
Code Climate has analyzed commit a5203e3 and detected 47 issues on this pull request. Here's the issue category breakdown:
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. |
Description of your changes
Fixes #
I have:
make build && make lint
to ensure this PR is ready for review.How has this code been tested
Special notes for your reviewer