Skip to content

Commit

Permalink
sync cmd: Remove global variable ChromeVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrunwald committed Sep 16, 2024
1 parent 853d765 commit eb4ded1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
19 changes: 7 additions & 12 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
)

var (
// TODO Remove global variable ChromeVersion
ChromeVersion string
// TODO Remove global variable RunData
RunData repository.RunData
)
Expand Down Expand Up @@ -318,6 +316,7 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman
totalStepCount := 0
stepCountInCurrentRecipe := 0
baseCountStep := 0
chromeVersion := ""
var recipeResult utils.RecipeResult
for i := range recipesToExecute {
totalStepCount += len(recipesToExecute[i].recipe.Steps)
Expand Down Expand Up @@ -374,9 +373,7 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman
})
// We fall through, because recipeResult might be set and contains additional information
}
if ChromeVersion == "" {
ChromeVersion = browserDriver.ChromeVersion
}
chromeVersion = browserDriver.ChromeVersion

// We don't need to call `chromedp.Cancel()` here.
// The browserDriver will be closed gracefully when the recipe is finished.
Expand Down Expand Up @@ -408,18 +405,16 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman
})
// We fall through, because recipeResult might be set and contains additional information
}
if ChromeVersion == "" {
ChromeVersion = clientDriver.ChromeVersion
}
chromeVersion = clientDriver.ChromeVersion

// We don't need to call `chromedp.Cancel()` here.
// The browserDriver will be closed gracefully when the recipe is finished.
// In case of an external abort signal (e.g. CTRL+C), bubbletea will call `chromedp.Cancel()`.
}

// Send ChromeVersion into metrics
if len(ChromeVersion) > 0 {
p.Send(buchhalterMetricsRecord{ChromeVersion: ChromeVersion})
// Send Chrome Version into metrics
if len(chromeVersion) > 0 {
p.Send(buchhalterMetricsRecord{ChromeVersion: chromeVersion})
}

// TODO recipeResult can be empty! (not nil, but without values)
Expand Down Expand Up @@ -535,7 +530,7 @@ func runSyncCommandLogic(p *tea.Program, logger *slog.Logger, config *syncComman
if !developmentMode && alwaysSendMetrics {
logger.Info("Sending usage metrics to Buchhalter API", "always_send_metrics", alwaysSendMetrics, "development_mode", developmentMode)
p.Send(utils.ViewStatusUpdateMsg{Message: "Sending usage metrics to Buchhalter API"})
err = buchhalterAPIClient.SendMetrics(RunData, cliVersion, ChromeVersion, vaultProvider.Version, recipeParser.OicdbVersion)
err = buchhalterAPIClient.SendMetrics(RunData, cliVersion, chromeVersion, vaultProvider.Version, recipeParser.OicdbVersion)
if err != nil {
logger.Error("Error sending usage metrics to Buchhalter API", "error", err)
p.Send(utils.ViewStatusUpdateMsg{
Expand Down
9 changes: 9 additions & 0 deletions lib/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ func (c *BuchhalterAPIClient) SendMetrics(runData RunData, cliVersion, chromeVer
if err != nil {
return err
}

c.logger.Info("Sending metrics to Buchhalter SaaS",
"url", apiUrl,
"cliVersion", md.CliVersion,
"oicdbVersion", md.OicdbVersion,
"vaultVersion", md.VaultVersion,
"chromeVersion", md.ChromeVersion,
"os", md.OS,
)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiUrl, bytes.NewBuffer(mdj))
if err != nil {
return fmt.Errorf("error creating request: %w", err)
Expand Down

0 comments on commit eb4ded1

Please sign in to comment.