MM - 19155 Change plugin helpers files to be golint complied (#12686)
* MM-19155 Change plugin helpers files to be golint complied * add makefile target that checks if plugin/helpers files are golint compliant * MM-19155 - Change plugin helpers files to be golint complied * added comment documentation to exported plugin/helpers methods * changed variable names to be compliant with golint * Address feedback
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
36f3b14420
Коммит
1155b08404
5
Makefile
5
Makefile
@@ -230,7 +230,10 @@ check-prereqs: ## Checks prerequisite software status.
|
|||||||
./scripts/prereq-check.sh
|
./scripts/prereq-check.sh
|
||||||
|
|
||||||
# TODO: remove govet and gofmt checks once golangci-lint is being enforced.
|
# 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.
|
test-te-race: ## Checks for race conditions in the team edition.
|
||||||
@echo Testing TE race conditions
|
@echo Testing TE race conditions
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Helpers provide a common patterns plugins use.
|
||||||
|
//
|
||||||
|
// Plugins obtain access to the Helpers by embedding MattermostPlugin.
|
||||||
type Helpers interface {
|
type Helpers interface {
|
||||||
// EnsureBot either returns an existing bot user matching the given bot, or creates a bot user from the given bot.
|
// 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.
|
// Returns the id of the resulting bot.
|
||||||
@@ -55,6 +58,7 @@ type Helpers interface {
|
|||||||
KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error
|
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 {
|
type HelpersImpl struct {
|
||||||
API API
|
API API
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"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")
|
err := p.ensureServerVersion("5.10.0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "failed to ensure bot")
|
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
|
// 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.
|
// retrieval from another EnsureBot. Just try the basic retrieve existing again.
|
||||||
defer func() {
|
defer func() {
|
||||||
if retBotId == "" || retErr != nil {
|
if retBotID == "" || retErr != nil {
|
||||||
var err error
|
var err error
|
||||||
var botIdBytes []byte
|
var botIDBytes []byte
|
||||||
|
|
||||||
err = utils.ProgressiveRetry(func() error {
|
err = utils.ProgressiveRetry(func() error {
|
||||||
botIdBytes, err = p.API.KVGet(BOT_USER_KEY)
|
botIDBytes, err = p.API.KVGet(BOT_USER_KEY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil && botIdBytes != nil {
|
if err == nil && botIDBytes != nil {
|
||||||
retBotId = string(botIdBytes)
|
retBotID = string(botIDBytes)
|
||||||
retErr = nil
|
retErr = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
botIdBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
||||||
if kvGetErr != nil {
|
if kvGetErr != nil {
|
||||||
return "", errors.Wrap(kvGetErr, "failed to get bot")
|
return "", errors.Wrap(kvGetErr, "failed to get bot")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the bot has already been created, there is nothing to do.
|
// If the bot has already been created, there is nothing to do.
|
||||||
if botIdBytes != nil {
|
if botIDBytes != nil {
|
||||||
botId := string(botIdBytes)
|
botID := string(botIDBytes)
|
||||||
return botId, nil
|
return botID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for an existing bot user with that username. If one exists, then use that.
|
// Check for an existing bot user with that username. If one exists, then use that.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user