Skip to content

Conversation

@Ashish-devtron
Copy link
Contributor

With this PR, two API is being introduced to change the deployment type for all cd pipelines in an environment and trigger the deploy for the same.

Fixes #https://dev.azure.com/DevtronLabs/Devtron/_workitems/edit/2870

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

resp, err := handler.pipelineBuilder.ChangePipelineDeploymentType(ctx, deploymentTypeChangeRequest)

if err != nil {
nErr := errors.New("failed to change deployment type with error msg: " + err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use format printer


func (handler PipelineConfigRestHandlerImpl) HandleTriggerDeploymentAfterTypeChange(w http.ResponseWriter, r *http.Request) {

// Auth check
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this comment

func (impl PipelineRepositoryImpl) UpdateCdPipeline(pipeline *Pipeline) error {
err := impl.dbConnection.Update(pipeline)
func (impl PipelineRepositoryImpl) SetDeploymentAppCreatedInPipeline(deploymentAppCreated bool, pipelineId int, userId int32) error {
query := "update pipeline set deployment_app_created=?, updated_on=?, updated_by=? where id=?;"
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid writing native queries

query := "update pipeline set deployment_app_created = ?, deployment_app_type = ?, " +
"updated_by = ?, updated_on = ?, deployment_app_delete_request = ? where id in (?);"
var pipeline *Pipeline
_, err := impl.dbConnection.Query(pipeline, query, deploymentAppCreated, deploymentAppType, userId, time.Now(), delete, pg.In(cdPipelineIdIncludes))
Copy link
Contributor

Choose a reason for hiding this comment

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

check empty array for pg.In

"updated_by = ?, updated_on = ?, deployment_app_delete_request = ? where id in (?);"
var pipeline *Pipeline
_, err := impl.dbConnection.Query(pipeline, query, deploymentAppType, userId, time.Now(), pg.In(cdPipelineIdIncludes))
_, err := impl.dbConnection.Query(pipeline, query, deploymentAppType, userId, time.Now(), delete, pg.In(cdPipelineIdIncludes))
Copy link
Contributor

Choose a reason for hiding this comment

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

use isDeleted


for _, pipeline := range pipelines {

artifactDetails, err := impl.RetrieveArtifactsByCDPipeline(pipeline, "DEPLOY")
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to extract out from iteration

}
_, err = impl.application.Get(ctx, req)
}
fmt.Println(err.Error() == "rpc error: code = NotFound desc = error getting application: applications.argoproj.io \"app-1-test-env\" not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

hardcoded

@vikramdevtron vikramdevtron self-requested a review May 9, 2023 13:37
vikramdevtron
vikramdevtron previously approved these changes May 9, 2023
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
20.2% 20.2% Duplication

@vikramdevtron vikramdevtron self-requested a review May 23, 2023 06:02
@Ashish-devtron Ashish-devtron merged commit 30a4365 into main May 23, 2023
@Ashish-devtron Ashish-devtron deleted the change-cd-deployment-type branch May 23, 2023 06:49
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.

3 participants