Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
add metrics acceptance question info (#537)
Browse files Browse the repository at this point in the history
* add metrics acceptance question info

Signed-off-by: victor-schumacher <[email protected]>

* add timestamp

Signed-off-by: victor-schumacher <[email protected]>

* add metric sender to initCmd struct

Signed-off-by: victor-schumacher <[email protected]>

* fix spaces

* format test
  • Loading branch information
victor-schumacher authored Sep 22, 2020
1 parent 5fb596c commit 8a23623
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func executionTime(startTime time.Time) float64 {
}

var Data metric.DataCollectorManager
var MetricSender = metric.NewHttpSender(metric.ServerRestURL, http.DefaultClient)

func buildCommands() *cobra.Command {
userHomeDir := api.UserHomeDir()
Expand Down Expand Up @@ -176,7 +177,7 @@ func buildCommands() *cobra.Command {
addCmd := cmd.NewAddCmd()
createCmd := cmd.NewCreateCmd()
deleteCmd := cmd.NewDeleteCmd()
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, configManager, fileManager, inputList, inputBool)
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, configManager, fileManager, inputList, inputBool, MetricSender)
listCmd := cmd.NewListCmd()
setCmd := cmd.NewSetCmd()
showCmd := cmd.NewShowCmd()
Expand Down Expand Up @@ -285,8 +286,7 @@ func sendMetric(commandExecutionTime float64, err ...string) {
metricEnable := metric.NewChecker(stream.NewFileManager())
if metricEnable.Check() {
var collectData metric.APIData
metricManager := metric.NewHttpSender(metric.ServerRestURL, http.DefaultClient)
collectData, _ = Data.Collect(commandExecutionTime, cmd.Version, err...)
metricManager.Send(collectData)
MetricSender.Send(collectData)
}
}
20 changes: 19 additions & 1 deletion pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type initCmd struct {
file stream.FileWriteReadExister
prompt.InputList
prompt.InputBool
metricSender metric.SendManagerHttp
}

func NewInitCmd(
Expand All @@ -88,8 +89,18 @@ func NewInitCmd(
file stream.FileWriteReadExister,
inList prompt.InputList,
inBool prompt.InputBool,
metricSender metric.SendManagerHttp,
) *cobra.Command {
o := initCmd{repo: repo, git: git, tutorial: tutorial, config: config, file: file, InputList: inList, InputBool: inBool}
o := initCmd{
repo: repo,
git: git,
tutorial: tutorial,
config: config,
file: file,
InputList: inList,
InputBool: inBool,
metricSender: metricSender,
}

cmd := &cobra.Command{
Use: "init",
Expand Down Expand Up @@ -232,6 +243,13 @@ You can view our Privacy Policy (http://insights.zup.com.br/politica-privacidade
responseToWrite := "yes"
if choose == DoNotAcceptMetrics {
responseToWrite = "no"
in.metricSender.Send(metric.APIData{
Id: "rit_init",
Timestamp: time.Now(),
Data: metric.Data{
MetricsAcceptance: responseToWrite,
},
})
}

if err = in.file.Write(metric.FilePath, []byte(responseToWrite)); err != nil {
Expand Down
26 changes: 24 additions & 2 deletions pkg/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package cmd

import (
"errors"
"net/http"
"strings"
"testing"

"github.com/ZupIT/ritchie-cli/pkg/formula"
"github.com/ZupIT/ritchie-cli/pkg/git"
"github.com/ZupIT/ritchie-cli/pkg/metric"
"github.com/ZupIT/ritchie-cli/pkg/prompt"
"github.com/ZupIT/ritchie-cli/pkg/rtutorial"
"github.com/ZupIT/ritchie-cli/pkg/stream"
Expand Down Expand Up @@ -359,8 +361,28 @@ func Test_initCmd_runAnyEntry(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
field := tt.fields

initPrompt := NewInitCmd(field.repo, field.git, field.tutorial, field.config, field.file, field.inList, field.inBool)
initStdin := NewInitCmd(field.repo, field.git, field.tutorial, field.config, field.file, field.inList, field.inBool)
metricSender := metric.NewHttpSender("", http.DefaultClient)

initPrompt := NewInitCmd(
field.repo,
field.git,
field.tutorial,
field.config,
field.file,
field.inList,
field.inBool,
metricSender,
)
initStdin := NewInitCmd(
field.repo,
field.git,
field.tutorial,
field.config,
field.file,
field.inList,
field.inBool,
metricSender,
)

initPrompt.PersistentFlags().Bool("stdin", false, "input by stdin")
initStdin.PersistentFlags().Bool("stdin", true, "input by stdin")
Expand Down
1 change: 1 addition & 0 deletions pkg/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Data struct {
CommandError string `json:"commandError,omitempty"`
CommonsRepoAdded string `json:"commonsRepoAdded,omitempty"`
CommandExecutionTime float64 `json:"commandExecutionTime"`
MetricsAcceptance string `json:"metricsAcceptance,omitempty"`
FormulaRepo formula.Repo `json:"repo,omitempty"`
}

Expand Down

0 comments on commit 8a23623

Please sign in to comment.