-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable more linters #252
Merged
Merged
Enable more linters #252
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
568c837
Update build system and config file
hanzei 562fe9d
Auto fix
hanzei 0b44be3
Fix simple errors
hanzei 135bb89
Enable goconst
hanzei fd36a1c
Enable errcheck
hanzei 6b3bcf1
Update dependencies
hanzei 8be86b0
Fix typo
hanzei c24908b
Consistent import odering
hanzei 203413d
Drop hasBeenNotified
hanzei 0953348
Add comment why crypto/sha1 is needed
hanzei fb01beb
s/GET/http.MethodGet/g
hanzei 27ac79a
Move all features to consts
hanzei 3e086f1
Merge remote-tracking branch 'origin/master' into golangci-lint
hanzei 2b10008
Fix eslint warnings
hanzei e4e2c0c
Merge remote-tracking branch 'origin/master' into golangci-lint
hanzei e991778
Merge remote-tracking branch 'origin/master' into golangci-lint
hanzei 51d0b50
Update dependencies
hanzei 91ea349
go mod tidy
hanzei 592a5e6
Fix RHS title
hanzei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,65 @@ | ||
service: | ||
golangci-lint-version: 1.23.0 | ||
|
||
run: | ||
timeout: 5m | ||
modules-download-mode: readonly | ||
|
||
linters-settings: | ||
goconst: | ||
min-len: 2 | ||
min-occurrences: 2 | ||
gofmt: | ||
simplify: true | ||
goimports: | ||
local-prefixes: github.com/mattermost/mattermost-plugin-github | ||
golint: | ||
min-confidence: 0 | ||
govet: | ||
check-shadowing: true | ||
enable-all: true | ||
misspell: | ||
locale: US | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
- deadcode | ||
- errcheck | ||
- goconst | ||
- gocritic | ||
- gofmt | ||
- goimports | ||
- golint | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- interfacer | ||
- misspell | ||
- nakedret | ||
- staticcheck | ||
- structcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unused | ||
- varcheck | ||
# TODO: enable this later | ||
# - errcheck | ||
- whitespace | ||
|
||
issues: | ||
exclude-rules: | ||
- linters: | ||
# ignore unused warning for manifest | ||
- varcheck | ||
- deadcode | ||
text: "manifest" | ||
- path: server/manifest.go | ||
linters: | ||
- deadcode | ||
- unused | ||
- varcheck | ||
- path: server/configuration.go | ||
linters: | ||
- unused | ||
- path: _test\.go | ||
linters: | ||
- bodyclose | ||
- goconst | ||
- scopelint # https://github.com/kyoh86/scopelint/issues/4 | ||
- path: server/webhook.go | ||
linters: | ||
- goconst | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Include custome targets and environment variables here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// main handles deployment of the plugin to a development server using either the Client4 API | ||
agnivade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// or by copying the plugin bundle into a sibling mattermost-server/plugin directory. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/mattermost/mattermost-server/v5/model" | ||
"github.com/mholt/archiver/v3" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func main() { | ||
err := deploy() | ||
if err != nil { | ||
fmt.Printf("Failed to deploy: %s\n", err.Error()) | ||
fmt.Println() | ||
fmt.Println("Usage:") | ||
fmt.Println(" deploy <plugin id> <bundle path>") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// deploy handles deployment of the plugin to a development server. | ||
func deploy() error { | ||
if len(os.Args) < 3 { | ||
return errors.New("invalid number of arguments") | ||
} | ||
|
||
pluginID := os.Args[1] | ||
bundlePath := os.Args[2] | ||
|
||
siteURL := os.Getenv("MM_SERVICESETTINGS_SITEURL") | ||
adminToken := os.Getenv("MM_ADMIN_TOKEN") | ||
adminUsername := os.Getenv("MM_ADMIN_USERNAME") | ||
adminPassword := os.Getenv("MM_ADMIN_PASSWORD") | ||
copyTargetDirectory, _ := filepath.Abs("../mattermost-server") | ||
|
||
if siteURL != "" { | ||
client := model.NewAPIv4Client(siteURL) | ||
|
||
if adminToken != "" { | ||
log.Printf("Authenticating using token against %s.", siteURL) | ||
client.SetToken(adminToken) | ||
|
||
return uploadPlugin(client, pluginID, bundlePath) | ||
} | ||
|
||
if adminUsername != "" && adminPassword != "" { | ||
client := model.NewAPIv4Client(siteURL) | ||
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL) | ||
_, resp := client.Login(adminUsername, adminPassword) | ||
if resp.Error != nil { | ||
return errors.Wrapf(resp.Error, "failed to login as %s", adminUsername) | ||
} | ||
|
||
return uploadPlugin(client, pluginID, bundlePath) | ||
} | ||
} | ||
|
||
_, err := os.Stat(copyTargetDirectory) | ||
if os.IsNotExist(err) { | ||
return errors.New("no supported deployment method available, please install plugin manually") | ||
} else if err != nil { | ||
return errors.Wrapf(err, "failed to stat %s", copyTargetDirectory) | ||
} | ||
|
||
log.Printf("Installing plugin to mattermost-server found in %s.", copyTargetDirectory) | ||
log.Print("Server restart required to load updated plugin.") | ||
return copyPlugin(pluginID, copyTargetDirectory, bundlePath) | ||
} | ||
|
||
// uploadPlugin attempts to upload and enable a plugin via the Client4 API. | ||
// It will fail if plugin uploads are disabled. | ||
func uploadPlugin(client *model.Client4, pluginID, bundlePath string) error { | ||
pluginBundle, err := os.Open(bundlePath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to open %s", bundlePath) | ||
} | ||
defer pluginBundle.Close() | ||
|
||
log.Print("Uploading plugin via API.") | ||
_, resp := client.UploadPluginForced(pluginBundle) | ||
if resp.Error != nil { | ||
return errors.Wrap(resp.Error, "failed to upload plugin bundle") | ||
} | ||
|
||
log.Print("Enabling plugin.") | ||
_, resp = client.EnablePlugin(pluginID) | ||
if resp.Error != nil { | ||
return errors.Wrap(resp.Error, "Failed to enable plugin") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// copyPlugin attempts to install a plugin by copying it to a sibling ../mattermost-server/plugin | ||
// directory. A server restart is required before the plugin will start. | ||
func copyPlugin(pluginID, targetPath, bundlePath string) error { | ||
targetPath = filepath.Join(targetPath, "plugins") | ||
|
||
err := os.MkdirAll(targetPath, 0777) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to create %s", targetPath) | ||
} | ||
|
||
existingPluginPath := filepath.Join(targetPath, pluginID) | ||
err = os.RemoveAll(existingPluginPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to remove existing existing plugin directory %s", existingPluginPath) | ||
} | ||
|
||
err = archiver.Unarchive(bundlePath, targetPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to unarchive %s into %s", bundlePath, targetPath) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are so many action types like
"opened"
inserver/webhook.go
that refactoring them intoconst
's did make the code more readable.