Skip to content

Commit

Permalink
Fix help message, send the core message over gRPC, add invoke type, p…
Browse files Browse the repository at this point in the history
…ublish exec parser (#1307)
  • Loading branch information
mszostok authored Nov 15, 2023
1 parent 35176a6 commit 0fd6ce2
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 73 deletions.
2 changes: 1 addition & 1 deletion internal/executor/thread-mate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"

"github.com/kubeshop/botkube/internal/executor/x/mathx"
"github.com/kubeshop/botkube/internal/loggerx"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/mathx"
)

const (
Expand Down
14 changes: 7 additions & 7 deletions internal/executor/x/output/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/sirupsen/logrus"

"github.com/kubeshop/botkube/internal/executor/x"
"github.com/kubeshop/botkube/internal/executor/x/parser"
"github.com/kubeshop/botkube/internal/executor/x/state"
"github.com/kubeshop/botkube/internal/executor/x/template"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/formatx"
)

// Parser defines
type Parser interface {
TableSeparated(in string) parser.TableOutput
TableSeparated(in string) formatx.TableOutput
}

// TableCommandParser allows to render table command output into interactive message based on registered templates.
Expand All @@ -32,7 +32,7 @@ func NewTableCommandParser(log logrus.FieldLogger) *TableCommandParser {
return &TableCommandParser{
log: log,
parsers: map[string]Parser{
"space": &parser.TableSpace{},
"space": &formatx.TableSpace{},
},
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func (p *TableCommandParser) RenderMessage(cmd, output string, state *state.Cont
}, nil
}

func (p *TableCommandParser) renderActions(msgCtx template.ParseMessage, table parser.Table, cmd string, idx int) (api.Section, error) {
func (p *TableCommandParser) renderActions(msgCtx template.ParseMessage, table formatx.Table, cmd string, idx int) (api.Section, error) {
if idx >= len(table.Rows) {
idx = len(table.Rows) - 1
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (p *TableCommandParser) renderActions(msgCtx template.ParseMessage, table p
}, nil
}

func (p *TableCommandParser) renderPreview(msgCtx template.ParseMessage, out parser.TableOutput, requestedRow int) (api.Section, error) {
func (p *TableCommandParser) renderPreview(msgCtx template.ParseMessage, out formatx.TableOutput, requestedRow int) (api.Section, error) {
headerLine := out.Lines[0]

if requestedRow >= len(out.Table.Rows) {
Expand Down Expand Up @@ -161,7 +161,7 @@ func (*TableCommandParser) getPreviewLine(lines []string, idx int) string {
return lines[1] // otherwise default first line
}

func (p *TableCommandParser) renderDropdowns(selects []template.Select, commandData parser.Table, cmd string, state *state.Container) (api.Section, int) {
func (p *TableCommandParser) renderDropdowns(selects []template.Select, commandData formatx.Table, cmd string, state *state.Container) (api.Section, int) {
var (
dropdowns []api.Select
lastSelectedIdx int
Expand All @@ -187,7 +187,7 @@ func (p *TableCommandParser) renderDropdowns(selects []template.Select, commandD
}, lastSelectedIdx
}

func (p *TableCommandParser) selectDropdown(name, cmd, keyTpl string, table parser.Table, state *state.Container) (*api.Select, int) {
func (p *TableCommandParser) selectDropdown(name, cmd, keyTpl string, table formatx.Table, state *state.Container) (*api.Select, int) {
log := p.log.WithField("selectName", name)
var options []api.OptionItem
for idx, row := range table.Rows {
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/x/output/message_tutorial.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"

"github.com/kubeshop/botkube/internal/executor/x"
"github.com/kubeshop/botkube/internal/executor/x/mathx"
"github.com/kubeshop/botkube/internal/executor/x/state"
"github.com/kubeshop/botkube/internal/executor/x/template"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/mathx"
)

// TutorialWrapper allows constructing interactive message with predefined steps.
Expand Down
134 changes: 100 additions & 34 deletions pkg/api/cloudteams/cloud_teams.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/api/executor/grpc_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/kubeshop/botkube/internal/executor/x/mathx"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/mathx"
)

const maxMessageNumberForSingleCommandExecution = 15
Expand Down
8 changes: 3 additions & 5 deletions pkg/bot/interactive/plugin_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var pluginHelpProvider = map[string]pluginHelpProviderFn{
}
},
"botkube/kubectl": func(platform config.CommPlatformIntegration, btnBuilder *api.ButtonBuilder) api.Section {
if platform.IsInteractive() {
// TODO(https://github.com/kubeshop/botkube-cloud/issues/645): add support for kubectl builder
if platform.IsInteractive() && platform != config.CloudTeamsCommPlatformIntegration {
return api.Section{
Base: api.Base{
Header: "Run kubectl commands",
Expand All @@ -30,11 +31,8 @@ var pluginHelpProvider = map[string]pluginHelpProviderFn{

// without the kubectl command builder
return api.Section{
Base: api.Base{
Header: "Run kubectl commands (if enabled)",
},
Buttons: []api.Button{
btnBuilder.ForCommandWithoutDesc("kubectl help", "kubectl help"),
btnBuilder.ForCommandWithBoldDesc("kubectl help", "Run kubectl commands (if enabled)", "kubectl help"),
},
}
},
Expand Down
Loading

0 comments on commit 0fd6ce2

Please sign in to comment.