Skip to content

Commit

Permalink
Address PR minor comments
Browse files Browse the repository at this point in the history
- Make err handling more idiomatic
- Rename exportCommandTrigger variable
  • Loading branch information
agarciamontoro committed Mar 18, 2020
1 parent 6bcf988 commit 4ca5b9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 12 additions & 6 deletions server/activate_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import (
"github.com/pkg/errors"
)

const (
botUsername = "channelexport"
botDisplayName = "Channel Export Bot"
botDescription = "A bot account created by the channel export plugin."
)

// OnActivate is invoked when the plugin is activated.
func (p *Plugin) OnActivate() error {
p.client = pluginapi.NewClient(p.API)

botID, ensureBotError := p.Helpers.EnsureBot(&model.Bot{
Username: "channelexport",
DisplayName: "Channel Export Bot",
Description: "A bot account created by the channel export plugin.",
botID, err := p.Helpers.EnsureBot(&model.Bot{
Username: botUsername,
DisplayName: botDisplayName,
Description: botDescription,
})
if ensureBotError != nil {
return errors.Wrap(ensureBotError, "failed to ensure bot.")
if err != nil {
return errors.Wrap(err, "failed to ensure bot.")
}

p.botID = botID
Expand Down
9 changes: 5 additions & 4 deletions server/command_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"strings"
"time"

Expand All @@ -11,15 +12,15 @@ import (
"github.com/mattermost/mattermost-server/v5/plugin"
)

const commandTriggerExport = "export"
const exportCommandTrigger = "export"

func (p *Plugin) registerCommands() error {
if err := p.client.SlashCommand.Register(&model.Command{
Trigger: commandTriggerExport,
Trigger: exportCommandTrigger,
AutoComplete: true,
AutoCompleteDesc: "Export the current channel.",
}); err != nil {
return errors.Wrapf(err, "failed to register %s command", commandTriggerExport)
return errors.Wrapf(err, "failed to register %s command", exportCommandTrigger)
}

return nil
Expand All @@ -30,7 +31,7 @@ func (p *Plugin) registerCommands() error {
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
trigger := strings.TrimPrefix(strings.Fields(args.Command)[0], "/")
switch trigger {
case commandTriggerExport:
case exportCommandTrigger:
return p.executeCommandExport(args), nil

default:
Expand Down

0 comments on commit 4ca5b9f

Please sign in to comment.