Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/xerrors
Browse files Browse the repository at this point in the history
# Conflicts:
#	ignite/cmd/ignite/main.go
  • Loading branch information
Pantani authored and Pantani committed Dec 5, 2023
2 parents 1d157f9 + d6595bd commit 0dd5281
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 104 deletions.
9 changes: 0 additions & 9 deletions ignite/cmd/ignite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ func main() {
func run() int {
const exitCodeOK, exitCodeError = 0, 1
var wg sync.WaitGroup

defer func() {
if r := recover(); r != nil {
analytics.SendMetric(&wg, os.Args, analytics.WithError(errors.Errorf("%v", r)))
fmt.Println(r)
os.Exit(exitCodeError)
}
}()

if len(os.Args) > 1 {
analytics.SendMetric(&wg, os.Args)
}
Expand Down
48 changes: 8 additions & 40 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,25 @@ const (

var gaclient gacli.Client

type (
// metric represents an analytics metric.
options struct {
// err sets metrics type as an error metric.
err error
}

// anonIdentity represents an analytics identity file.
anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}
)
// anonIdentity represents an analytics identity file.
type anonIdentity struct {
// name represents the username.
Name string `json:"name" yaml:"name"`
// doNotTrack represents the user track choice.
DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"`
}

func init() {
gaclient = gacli.New(telemetryEndpoint)
}

// Option configures ChainCmd.
type Option func(*options)

// WithError with application command error.
func WithError(error error) Option {
return func(m *options) {
m.err = error
}
}

// SendMetric send command metrics to analytics.
func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) {
func SendMetric(wg *sync.WaitGroup, args []string) {
// only the app name
if len(args) <= 1 {
return
}

// apply analytics options.
var opt options
for _, o := range opts {
o(&opt)
}

if args[1] == "version" {
return
}
Expand All @@ -83,14 +59,6 @@ func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) {
SessionID: dntInfo.Name,
Version: version.Version,
}

switch {
case opt.err == nil:
met.Status = "success"
case opt.err != nil:
met.Status = "error"
met.Error = opt.err.Error()
}
met.Cmd = args[1]

wg.Add(1)
Expand Down
2 changes: 0 additions & 2 deletions ignite/pkg/gacli/gacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ type (
}
// Metric represents a data point.
Metric struct {
Status string `json:"status,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
FullCmd string `json:"full_command,omitempty"`
Cmd string `json:"command,omitempty"`
Error string `json:"error,omitempty"`
Version string `json:"version,omitempty"`
SessionID string `json:"session_id,omitempty"`
EngagementTimeMsec string `json:"engagement_time_msec,omitempty"`
Expand Down
27 changes: 14 additions & 13 deletions ignite/services/scaffolder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scaffolder

import (
"context"
"fmt"
"go/ast"
"go/parser"
"go/token"
Expand Down Expand Up @@ -47,22 +48,22 @@ func checkComponentValidity(appPath, moduleName string, compName multiformatname
func checkComponentCreated(appPath, moduleName string, compName multiformatname.Name, noMessage bool) (err error) {
// associate the type to check with the component that scaffold this type
typesToCheck := map[string]string{
compName.UpperCamel: componentType,
"queryall" + compName.LowerCase + "request": componentType,
"queryall" + compName.LowerCase + "response": componentType,
"queryget" + compName.LowerCase + "request": componentType,
"queryget" + compName.LowerCase + "response": componentType,
"query" + compName.LowerCase + "request": componentQuery,
"query" + compName.LowerCase + "response": componentQuery,
compName.LowerCase + "packetdata": componentPacket,
compName.UpperCamel: componentType,
fmt.Sprintf("queryall%srequest", compName.LowerCase): componentType,
fmt.Sprintf("queryall%sresponse", compName.LowerCase): componentType,
fmt.Sprintf("queryget%srequest", compName.LowerCase): componentType,
fmt.Sprintf("queryget%sresponse", compName.LowerCase): componentType,
fmt.Sprintf("query%srequest", compName.LowerCase): componentQuery,
fmt.Sprintf("query%sresponse", compName.LowerCase): componentQuery,
fmt.Sprintf("%spacketdata", compName.LowerCase): componentPacket,
}

if !noMessage {
typesToCheck["msgcreate"+compName.LowerCase] = componentType
typesToCheck["msgupdate"+compName.LowerCase] = componentType
typesToCheck["msgdelete"+compName.LowerCase] = componentType
typesToCheck["msg"+compName.LowerCase] = componentMessage
typesToCheck["msgsend"+compName.LowerCase] = componentPacket
typesToCheck[fmt.Sprintf("msgcreate%s", compName.LowerCase)] = componentType
typesToCheck[fmt.Sprintf("msgupdate%s", compName.LowerCase)] = componentType
typesToCheck[fmt.Sprintf("msgdelete%s", compName.LowerCase)] = componentType
typesToCheck[fmt.Sprintf("msg%s", compName.LowerCase)] = componentMessage
typesToCheck[fmt.Sprintf("msgsend%s", compName.LowerCase)] = componentPacket
}

absPath, err := filepath.Abs(filepath.Join(appPath, "x", moduleName, "types"))
Expand Down
8 changes: 6 additions & 2 deletions ignite/templates/ibc/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func protoModify(opts *PacketOptions) genny.RunFn {
if err != nil {
return err
}
name := xstrings.Title(opts.ModuleName) + "PacketData"
name := fmt.Sprintf("%sPacketData", xstrings.Title(opts.ModuleName))
message, err := protoutil.GetMessageByName(protoFile, name)
if err != nil {
return errors.Errorf("failed while looking up '%s' message in %s: %w", name, path, err)

Check warning on line 197 in ignite/templates/ibc/packet.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/ibc/packet.go#L197

Added line #L197 was not covered by tests
Expand Down Expand Up @@ -305,7 +305,11 @@ func protoTxModify(opts *PacketOptions) genny.RunFn {
return errors.Errorf("failed while looking up service 'Msg' in %s: %w", path, err)

Check warning on line 305 in ignite/templates/ibc/packet.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/ibc/packet.go#L305

Added line #L305 was not covered by tests
}
typenameUpper := opts.PacketName.UpperCamel
send := protoutil.NewRPC("Send"+typenameUpper, "MsgSend"+typenameUpper, "MsgSend"+typenameUpper+"Response")
send := protoutil.NewRPC(
fmt.Sprintf("Send%s", typenameUpper),
fmt.Sprintf("MsgSend%s", typenameUpper),
fmt.Sprintf("MsgSend%sResponse", typenameUpper),
)
protoutil.Append(serviceMsg, send)

// Create fields for MsgSend.
Expand Down
9 changes: 8 additions & 1 deletion ignite/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ func protoTxRPCModify(opts *Options) genny.RunFn {
return errors.Errorf("failed while looking up service 'Msg' in %s: %w", path, err)

Check warning on line 102 in ignite/templates/message/message.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/message/message.go#L102

Added line #L102 was not covered by tests
}
typenameUpper := opts.MsgName.UpperCamel
protoutil.Append(serviceMsg, protoutil.NewRPC(typenameUpper, "Msg"+typenameUpper, "Msg"+typenameUpper+"Response"))
protoutil.Append(
serviceMsg,
protoutil.NewRPC(
typenameUpper,
fmt.Sprintf("Msg%s", typenameUpper),
fmt.Sprintf("Msg%sResponse", typenameUpper),
),
)

newFile := genny.NewFileS(path, protoutil.Print(protoFile))
return r.File(newFile)
Expand Down
5 changes: 4 additions & 1 deletion ignite/templates/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func protoQueryModify(opts *Options) genny.RunFn {
}

typenameUpper, appModulePath := opts.QueryName.UpperCamel, gomodulepath.ExtractAppPath(opts.ModulePath)
rpcSingle := protoutil.NewRPC(typenameUpper, "Query"+typenameUpper+"Request", "Query"+typenameUpper+"Response",
rpcSingle := protoutil.NewRPC(
typenameUpper,
fmt.Sprintf("Query%sRequest", typenameUpper),
fmt.Sprintf("Query%sResponse", typenameUpper),
protoutil.WithRPCOptions(
protoutil.NewOption(
"google.api.http",
Expand Down
50 changes: 35 additions & 15 deletions ignite/templates/typed/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,21 @@ func protoTxModify(opts *typed.Options) genny.RunFn {
// Create, update, delete rpcs. Better to append them altogether, single traversal.
typenameUpper := opts.TypeName.UpperCamel
protoutil.Append(serviceMsg,
protoutil.NewRPC("Create"+typenameUpper, "MsgCreate"+typenameUpper, "MsgCreate"+typenameUpper+"Response"),
protoutil.NewRPC("Update"+typenameUpper, "MsgUpdate"+typenameUpper, "MsgUpdate"+typenameUpper+"Response"),
protoutil.NewRPC("Delete"+typenameUpper, "MsgDelete"+typenameUpper, "MsgDelete"+typenameUpper+"Response"),
protoutil.NewRPC(
fmt.Sprintf("Create%s", typenameUpper),
fmt.Sprintf("MsgCreate%s", typenameUpper),
fmt.Sprintf("MsgCreate%sResponse", typenameUpper),
),
protoutil.NewRPC(
fmt.Sprintf("Update%s", typenameUpper),
fmt.Sprintf("MsgUpdate%s", typenameUpper),
fmt.Sprintf("MsgUpdate%sResponse", typenameUpper),
),
protoutil.NewRPC(
fmt.Sprintf("Delete%s", typenameUpper),
fmt.Sprintf("MsgDelete%s", typenameUpper),
fmt.Sprintf("MsgDelete%sResponse", typenameUpper),
),
)

// - Ensure custom types are imported
Expand Down Expand Up @@ -142,26 +154,26 @@ func protoTxModify(opts *typed.Options) genny.RunFn {
}

msgCreate := protoutil.NewMessage(
"MsgCreate"+typenameUpper,
fmt.Sprintf("MsgCreate%s", typenameUpper),
protoutil.WithFields(createFields...),
protoutil.WithMessageOptions(creatorOpt),
)
msgCreateResponse := protoutil.NewMessage(
"MsgCreate"+typenameUpper+"Response",
fmt.Sprintf("MsgCreate%sResponse", typenameUpper),
protoutil.WithFields(protoutil.NewField("id", "uint64", 1)),
)
msgUpdate := protoutil.NewMessage(
"MsgUpdate"+typenameUpper,
fmt.Sprintf("MsgUpdate%s", typenameUpper),
protoutil.WithFields(updateFields...),
protoutil.WithMessageOptions(creatorOpt),
)
msgUpdateResponse := protoutil.NewMessage("MsgUpdate" + typenameUpper + "Response")
msgUpdateResponse := protoutil.NewMessage(fmt.Sprintf("MsgUpdate%sResponse", typenameUpper))
msgDelete := protoutil.NewMessage(
"MsgDelete"+typenameUpper,
fmt.Sprintf("MsgDelete%s", typenameUpper),
protoutil.WithFields(udfields...),
protoutil.WithMessageOptions(creatorOpt),
)
msgDeleteResponse := protoutil.NewMessage("MsgDelete" + typenameUpper + "Response")
msgDeleteResponse := protoutil.NewMessage(fmt.Sprintf("MsgDelete%sResponse", typenameUpper))
protoutil.Append(
protoFile,
msgCreate,
Expand Down Expand Up @@ -205,7 +217,10 @@ func protoQueryModify(opts *typed.Options) genny.RunFn {
}
appModulePath := gomodulepath.ExtractAppPath(opts.ModulePath)
typenameUpper := opts.TypeName.UpperCamel
rpcQueryGet := protoutil.NewRPC(typenameUpper, "QueryGet"+typenameUpper+"Request", "QueryGet"+typenameUpper+"Response",
rpcQueryGet := protoutil.NewRPC(
typenameUpper,
fmt.Sprintf("QueryGet%sRequest", typenameUpper),
fmt.Sprintf("QueryGet%sResponse", typenameUpper),
protoutil.WithRPCOptions(
protoutil.NewOption(
"google.api.http",
Expand All @@ -220,7 +235,10 @@ func protoQueryModify(opts *typed.Options) genny.RunFn {
)
protoutil.AttachComment(rpcQueryGet, fmt.Sprintf("Queries a %v by id.", typenameUpper))

rpcQueryAll := protoutil.NewRPC(typenameUpper+"All", "QueryAll"+typenameUpper+"Request", "QueryAll"+typenameUpper+"Response",
rpcQueryAll := protoutil.NewRPC(
fmt.Sprintf("%sAll", typenameUpper),
fmt.Sprintf("QueryAll%sRequest", typenameUpper),
fmt.Sprintf("QueryAll%sResponse", typenameUpper),
protoutil.WithRPCOptions(
protoutil.NewOption(
"google.api.http",
Expand All @@ -241,19 +259,21 @@ func protoQueryModify(opts *typed.Options) genny.RunFn {
gogoOption := protoutil.NewOption("gogoproto.nullable", "false", protoutil.Custom())

queryGetRequest := protoutil.NewMessage(
"QueryGet"+typenameUpper+"Request",
fmt.Sprintf("QueryGet%sRequest", typenameUpper),
protoutil.WithFields(protoutil.NewField("id", "uint64", 1)),
)
field := protoutil.NewField(typenameUpper, typenameUpper, 1, protoutil.WithFieldOptions(gogoOption))
queryGetResponse := protoutil.NewMessage("QueryGet"+typenameUpper+"Response", protoutil.WithFields(field))
queryGetResponse := protoutil.NewMessage(
fmt.Sprintf("QueryGet%sResponse", typenameUpper),
protoutil.WithFields(field))

queryAllRequest := protoutil.NewMessage(
"QueryAll"+typenameUpper+"Request",
fmt.Sprintf("QueryAll%sRequest", typenameUpper),
protoutil.WithFields(protoutil.NewField(paginationName, paginationType+"Request", 1)),
)
field = protoutil.NewField(typenameUpper, typenameUpper, 1, protoutil.Repeated(), protoutil.WithFieldOptions(gogoOption))
queryAllResponse := protoutil.NewMessage(
"QueryAll"+typenameUpper+"Response",
fmt.Sprintf("QueryAll%sResponse", typenameUpper),
protoutil.WithFields(field, protoutil.NewField(paginationName, paginationType+"Response", 2)),
)
protoutil.Append(protoFile, queryGetRequest, queryGetResponse, queryAllRequest, queryAllResponse)
Expand Down
Loading

0 comments on commit 0dd5281

Please sign in to comment.