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

cherry-pick #7033 fix: cicd deployment dora delete when data nil #7044

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions backend/plugins/dora/tasks/change_lead_time_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package tasks

import (
"fmt"
"math"
"reflect"
"time"
Expand Down Expand Up @@ -48,16 +49,30 @@ func CalculateChangeLeadTime(taskCtx plugin.SubTaskContext) errors.Error {
data := taskCtx.GetData().(*DoraTaskData)

// Get pull requests by repo project_name
cursor, err := db.Cursor(
var clauses = []dal.Clause{
dal.Select("pr.id, pr.pull_request_key, pr.author_id, pr.merge_commit_sha, pr.created_date, pr.merged_date"),
dal.From("pull_requests pr"),
dal.Join(`LEFT JOIN project_mapping pm ON (pm.row_id = pr.base_repo_id)`),
dal.Where("pr.merged_date IS NOT NULL AND pm.project_name = ? AND pm.table = 'repos'", data.Options.ProjectName),
)
}
cursor, err := db.Cursor(clauses...)
if err != nil {
return err
}
defer cursor.Close()
count, err := db.Count(clauses...)
if err != nil {
return errors.Default.Wrap(err, "error getting count of clauses")
}
if count == 0 {
// Clear previous results from the project
deleteSql := fmt.Sprintf("DELETE FROM project_pr_metrics WHERE project_name = '%s'", data.Options.ProjectName)
err := db.Exec(deleteSql)
if err != nil {
return errors.Default.Wrap(err, "error deleting previous project_pr_metrics")
}
return nil
}

converter, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Expand Down
13 changes: 13 additions & 0 deletions backend/plugins/dora/tasks/deployment_commits_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ func GenerateDeploymentCommits(taskCtx plugin.SubTaskContext) errors.Error {
return err
}
defer cursor.Close()
count, err := db.Count(clauses...)
if err != nil {
return errors.Default.Wrap(err, "error getting count of clauses")
}
if count == 0 {
// Clear previous results from the project
deleteSql := fmt.Sprintf("DELETE cdc FROM cicd_deployment_commits cdc LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = cdc.cicd_scope_id) WHERE pm.project_name = '%s'", data.Options.ProjectName)
err := db.Exec(deleteSql)
if err != nil {
return errors.Default.Wrap(err, "error deleting previous cicd_deployment_commits")
}
return nil
}

enricher, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/dora/tasks/deployment_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package tasks

import (
"fmt"
"reflect"
"time"

Expand Down Expand Up @@ -90,6 +91,19 @@ func GenerateDeployment(taskCtx plugin.SubTaskContext) errors.Error {
return err
}
defer cursor.Close()
count, err := db.Count(clauses...)
if err != nil {
return errors.Default.Wrap(err, "error getting count of clauses")
}
if count == 0 {
// Clear previous results from the project
deleteSql := fmt.Sprintf("DELETE cd FROM cicd_deployments cd LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = cd.cicd_scope_id) WHERE pm.project_name = '%s'", data.Options.ProjectName)
err := db.Exec(deleteSql)
if err != nil {
return errors.Default.Wrap(err, "error deleting previous deployments")
}
return nil
}

enricher, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/dora/tasks/incident_deploy_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package tasks

import (
"fmt"
"reflect"
"time"

Expand Down Expand Up @@ -62,6 +63,19 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
return err
}
defer cursor.Close()
count, err := db.Count(clauses...)
if err != nil {
return errors.Default.Wrap(err, "error getting count of clauses")
}
if count == 0 {
// Clear previous results from the project
deleteSql := fmt.Sprintf("DELETE FROM project_issue_metrics WHERE project_name = '%s'", data.Options.ProjectName)
err := db.Exec(deleteSql)
if err != nil {
return errors.Default.Wrap(err, "error deleting previous project_issue_metrics")
}
return nil
}

enricher, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Expand Down
2 changes: 0 additions & 2 deletions backend/plugins/github_graphql/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tasks

import (
"encoding/json"
"fmt"
"regexp"

"github.com/apache/incubator-devlake/core/errors"
Expand Down Expand Up @@ -53,7 +52,6 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error {
}
}
if config != nil && len(config.PrComponent) > 0 {
fmt.Println("config.PrComponent1", config.PrComponent)
labelComponentRegex, err = errors.Convert01(regexp.Compile(config.PrComponent))
if err != nil {
return errors.Default.Wrap(err, "regexp Compile prComponent failed")
Expand Down
Loading