Skip to content

Commit 80db187

Browse files
committed
chore: allow dry-run for non-prod envs
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent d1078a0 commit 80db187

2 files changed

Lines changed: 43 additions & 26 deletions

File tree

services/apps/git_integration/src/crowdgit/services/software_value/main.go

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,25 @@ func processRepository() StandardResponse {
5151
// Process single repository (the target path argument)
5252
repoDir := config.TargetPath
5353

54-
insightsDb, err := NewInsightsDB(ctx, config.InsightsDatabase)
55-
if err != nil {
56-
errorCode := ErrorCodeDatabaseConnection
57-
errorMessage := fmt.Sprintf("Error connecting to insights database: %v", err)
58-
return StandardResponse{
59-
Status: StatusFailure,
60-
ErrorCode: &errorCode,
61-
ErrorMessage: &errorMessage,
54+
dryRun := os.Getenv("IS_PROD_ENV") != "true"
55+
56+
var insightsDb *InsightsDB
57+
if !dryRun {
58+
var dbErr error
59+
insightsDb, dbErr = NewInsightsDB(ctx, config.InsightsDatabase)
60+
if dbErr != nil {
61+
errorCode := ErrorCodeDatabaseConnection
62+
errorMessage := fmt.Sprintf("Error connecting to insights database: %v", dbErr)
63+
return StandardResponse{
64+
Status: StatusFailure,
65+
ErrorCode: &errorCode,
66+
ErrorMessage: &errorMessage,
67+
}
6268
}
69+
defer insightsDb.Close()
70+
} else {
71+
fmt.Println("[DRY RUN] Skipping database connection")
6372
}
64-
defer insightsDb.Close()
6573

6674
// Get git URL for the repository
6775
gitUrl, err := getGitRepositoryURL(repoDir)
@@ -88,24 +96,32 @@ func processRepository() StandardResponse {
8896
}
8997
report.Repository.URL = gitUrl
9098

91-
// Save to database
92-
if err := insightsDb.saveProjectCost(ctx, report.Repository, report.Cocomo.CostInDollars); err != nil {
93-
errorCode := ErrorCodeDatabaseOperation
94-
errorMessage := fmt.Sprintf("Error saving project cost: %v", err)
95-
return StandardResponse{
96-
Status: StatusFailure,
97-
ErrorCode: &errorCode,
98-
ErrorMessage: &errorMessage,
99+
if dryRun {
100+
fmt.Printf("[DRY RUN] Would save project cost: repo=%s cost=$%.2f\n", report.Repository.URL, report.Cocomo.CostInDollars)
101+
fmt.Printf("[DRY RUN] Would save %d language stats entries\n", len(report.LanguageStats))
102+
for _, ls := range report.LanguageStats {
103+
fmt.Printf("[DRY RUN] language=%s lines=%d code=%d\n", ls.LanguageName, ls.Lines, ls.Code)
104+
}
105+
} else {
106+
// Save to database
107+
if err := insightsDb.saveProjectCost(ctx, report.Repository, report.Cocomo.CostInDollars); err != nil {
108+
errorCode := ErrorCodeDatabaseOperation
109+
errorMessage := fmt.Sprintf("Error saving project cost: %v", err)
110+
return StandardResponse{
111+
Status: StatusFailure,
112+
ErrorCode: &errorCode,
113+
ErrorMessage: &errorMessage,
114+
}
99115
}
100-
}
101116

102-
if err := insightsDb.saveLanguageStats(ctx, report.Repository, report.LanguageStats); err != nil {
103-
errorCode := ErrorCodeDatabaseOperation
104-
errorMessage := fmt.Sprintf("Error saving language stats: %v", err)
105-
return StandardResponse{
106-
Status: StatusFailure,
107-
ErrorCode: &errorCode,
108-
ErrorMessage: &errorMessage,
117+
if err := insightsDb.saveLanguageStats(ctx, report.Repository, report.LanguageStats); err != nil {
118+
errorCode := ErrorCodeDatabaseOperation
119+
errorMessage := fmt.Sprintf("Error saving language stats: %v", err)
120+
return StandardResponse{
121+
Status: StatusFailure,
122+
ErrorCode: &errorCode,
123+
ErrorMessage: &errorMessage,
124+
}
109125
}
110126
}
111127

@@ -123,7 +139,7 @@ func processRepository() StandardResponse {
123139
func getSCCReport(sccPath, dirPath string) (SCCReport, error) {
124140
cost, err := getCost(sccPath, dirPath)
125141
if err != nil {
126-
return SCCReport{}, fmt.Errorf("error getting SCC report for '%s': %v\"", err)
142+
return SCCReport{}, fmt.Errorf("error getting SCC report for '%s': %v", dirPath, err)
127143
}
128144

129145
// Skip saving to database if cost is 0 - do we want to do this?

services/apps/git_integration/src/crowdgit/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ def load_env_var(key: str, required=True, default=None):
4444
STUCK_RECURRENT_REPO_TIMEOUT_HOURS = int(
4545
load_env_var("STUCK_RECURRENT_REPO_TIMEOUT_HOURS", default="4")
4646
)
47+
IS_PROD_ENV = bool(load_env_var("IS_PROD_ENV"))

0 commit comments

Comments
 (0)