diff --git a/Makefile b/Makefile index ea99a27b6c..60ebc1dc33 100644 --- a/Makefile +++ b/Makefile @@ -230,7 +230,10 @@ check-prereqs: ## Checks prerequisite software status. ./scripts/prereq-check.sh # TODO: remove govet and gofmt checks once golangci-lint is being enforced. -check-style: govet gofmt check-licenses ## Runs govet and gofmt against all packages. +check-style: govet gofmt check-licenses check-plugin-golint ## Runs govet and gofmt against all packages and also ensures plugin package golint compliant + +check-plugin-golint: # Checks if golint returns any uncompliant code for any file that starts with plugin/helpers + @! golint ./plugin/ | grep plugin/helpers test-te-race: ## Checks for race conditions in the team edition. @echo Testing TE race conditions diff --git a/plugin/helpers.go b/plugin/helpers.go index 7b62fffa80..5a2e4e33ca 100644 --- a/plugin/helpers.go +++ b/plugin/helpers.go @@ -9,6 +9,9 @@ import ( "github.com/pkg/errors" ) +// Helpers provide a common patterns plugins use. +// +// Plugins obtain access to the Helpers by embedding MattermostPlugin. type Helpers interface { // EnsureBot either returns an existing bot user matching the given bot, or creates a bot user from the given bot. // Returns the id of the resulting bot. @@ -55,6 +58,7 @@ type Helpers interface { KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error } +// HelpersImpl implements the helpers interface with an API that retrieves data on behalf of the plugin. type HelpersImpl struct { API API } diff --git a/plugin/helpers_bots.go b/plugin/helpers_bots.go index d7ab57ce64..44355a0397 100644 --- a/plugin/helpers_bots.go +++ b/plugin/helpers_bots.go @@ -4,12 +4,14 @@ package plugin import ( + "github.com/pkg/errors" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" - "github.com/pkg/errors" ) -func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotId string, retErr error) { +// EnsureBot implements Helpers.EnsureBot +func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotID string, retErr error) { err := p.ensureServerVersion("5.10.0") if err != nil { return "", errors.Wrap(err, "failed to ensure bot") @@ -23,34 +25,34 @@ func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotId string, retErr error) // If we fail for any reason, this could be a race between creation of bot and // retrieval from another EnsureBot. Just try the basic retrieve existing again. defer func() { - if retBotId == "" || retErr != nil { + if retBotID == "" || retErr != nil { var err error - var botIdBytes []byte + var botIDBytes []byte err = utils.ProgressiveRetry(func() error { - botIdBytes, err = p.API.KVGet(BOT_USER_KEY) + botIDBytes, err = p.API.KVGet(BOT_USER_KEY) if err != nil { return err } return nil }) - if err == nil && botIdBytes != nil { - retBotId = string(botIdBytes) + if err == nil && botIDBytes != nil { + retBotID = string(botIDBytes) retErr = nil } } }() - botIdBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY) + botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY) if kvGetErr != nil { return "", errors.Wrap(kvGetErr, "failed to get bot") } // If the bot has already been created, there is nothing to do. - if botIdBytes != nil { - botId := string(botIdBytes) - return botId, nil + if botIDBytes != nil { + botID := string(botIDBytes) + return botID, nil } // Check for an existing bot user with that username. If one exists, then use that.