Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ trim_trailing_whitespace = true
[*.go]
indent_style = tab

[*.{js, jsx, ts, tsx, json, html}]
[*.{js,jsx,ts,tsx,json,html}]
indent_style = space
indent_size = 4

[webapp/package.json]
indent_size = 2

[{Makefile, *.mk}]
[{Makefile,*.mk}]
indent_style = tab

[*.md]
Expand Down
116 changes: 63 additions & 53 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,66 @@
version: "2"

run:
timeout: 5m
modules-download-mode: readonly

linters:
default: none
enable:
- bidichk
- errcheck
- govet
- ineffassign
- makezero
- misspell
- revive
- staticcheck
- unconvert
- unused
- whitespace
settings:
govet:
disable:
- fieldalignment
enable-all: true
exclusions:
generated: lax
presets:
- error
default: none
enable:
- bidichk
- bodyclose
- errcheck
- gocritic
- gosec
- govet
- ineffassign
- makezero
- misspell
- modernize
- nakedret
- revive
- staticcheck
- unconvert
- unqueryvet
- unused
- whitespace
settings:
govet:
enable-all: true
disable:
- fieldalignment
- shadow
revive:
rules:
- name: exported
disabled: true
- name: unused-parameter
disabled: true
unqueryvet:
check-sql-builders: true
exclusions:
paths:
- webapp
- mock.*
rules:
Comment thread
fmartingr marked this conversation as resolved.
- path: server/configuration.go
linters:
- unused
- path: _test\.go
linters:
- bodyclose

formatters:
enable:
- goimports
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any
exclusions:
generated: lax
paths:
- mock.*
issues:
max-issues-per-linter: 0 # no maximum
max-same-issues: 0 # no maximum
exclude-rules:
- linters:
- revive
text: unused-parameter
- linters:
- gofmt
path: server/matrix/client.go
line: 83
- linters:
- gofmt
path: server/matrix_util.go
line: 151
- linters:
- gofmt
path: server/sync_to_matrix.go
line: 162
enable:
- gofmt
- gofumpt
- goimports
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any
goimports:
local-prefixes:
- github.com/mattermost/mattermost-plugin-matrix-bridge
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.11
24.13.1
31 changes: 26 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ endif
# Used for semver bumping
PROTECTED_BRANCH := master
APP_NAME := $(shell basename -s .git `git config --get remote.origin.url`)
CURRENT_VERSION := $(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0")
CURRENT_VERSION := $(strip $(shell git describe --abbrev=0 --tags))
LATEST_RELEASE_TAG_RAW := $(shell git tag -l "v*" --sort=-v:refname | grep -v '\-rc' | head -n 1 || true)
LATEST_RELEASE_TAG := $(strip $(LATEST_RELEASE_TAG_RAW))
ifeq ($(LATEST_RELEASE_TAG),)
LATEST_RELEASE_TAG := $(CURRENT_VERSION)
endif
VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION))))
MAJOR := $(word 1,$(VERSION_PARTS))
MINOR := $(word 2,$(VERSION_PARTS))
PATCH := $(word 3,$(VERSION_PARTS))
RC := $(shell echo $(CURRENT_VERSION) | grep -oE 'rc[0-9]+' | sed 's/rc//' || echo "0")
RC := $(shell echo $(CURRENT_VERSION) | grep -oE 'rc[0-9]+' | sed 's/rc//')
# Check if current branch is protected
define check_protected_branch
@current_branch=$$(git rev-parse --abbrev-ref HEAD); \
Expand Down Expand Up @@ -82,6 +87,11 @@ endef
patch: ## to bump patch version (semver)
$(call check_protected_branch)
$(call check_pending_pulls)
@$(eval BASE_VERSION := $(strip $(LATEST_RELEASE_TAG)))
@$(eval BASE_VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(BASE_VERSION)))))
@$(eval MAJOR := $(word 1,$(BASE_VERSION_PARTS)))
@$(eval MINOR := $(word 2,$(BASE_VERSION_PARTS)))
@$(eval PATCH := $(word 3,$(BASE_VERSION_PARTS)))
@$(eval PATCH := $(shell echo $$(($(PATCH)+1))))
$(call prompt_approval,$(MAJOR).$(MINOR).$(PATCH))
@echo Bumping $(APP_NAME) to Patch version $(MAJOR).$(MINOR).$(PATCH)
Expand All @@ -92,6 +102,11 @@ patch: ## to bump patch version (semver)
minor: ## to bump minor version (semver)
$(call check_protected_branch)
$(call check_pending_pulls)
@$(eval BASE_VERSION := $(strip $(LATEST_RELEASE_TAG)))
@$(eval BASE_VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(BASE_VERSION)))))
@$(eval MAJOR := $(word 1,$(BASE_VERSION_PARTS)))
@$(eval MINOR := $(word 2,$(BASE_VERSION_PARTS)))
@$(eval PATCH := $(word 3,$(BASE_VERSION_PARTS)))
@$(eval MINOR := $(shell echo $$(($(MINOR)+1))))
@$(eval PATCH := 0)
$(call prompt_approval,$(MAJOR).$(MINOR).$(PATCH))
Expand All @@ -103,6 +118,11 @@ minor: ## to bump minor version (semver)
major: ## to bump major version (semver)
$(call check_protected_branch)
$(call check_pending_pulls)
@$(eval BASE_VERSION := $(strip $(LATEST_RELEASE_TAG)))
@$(eval BASE_VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(BASE_VERSION)))))
@$(eval MAJOR := $(word 1,$(BASE_VERSION_PARTS)))
@$(eval MINOR := $(word 2,$(BASE_VERSION_PARTS)))
@$(eval PATCH := $(word 3,$(BASE_VERSION_PARTS)))
$(eval MAJOR := $(shell echo $$(($(MAJOR)+1))))
$(eval MINOR := 0)
$(eval PATCH := 0)
Expand Down Expand Up @@ -164,8 +184,8 @@ apply:
## Install go tools
install-go-tools:
@echo Installing go tools
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
$(GO) install gotest.tools/gotestsum@v1.7.0
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.9.0
$(GO) install gotest.tools/gotestsum@v1.13.0

## Runs eslint and golangci-lint
.PHONY: check-style
Expand Down Expand Up @@ -193,6 +213,7 @@ ifneq ($(HAS_SERVER),)
ifneq ($(MM_DEBUG),)
$(info DEBUG mode is on; to disable, unset MM_DEBUG)
endif
rm -rf server/dist;
mkdir -p server/dist;
ifneq ($(MM_SERVICESETTINGS_ENABLEDEVELOPER),)
@echo Building plugin only for $(DEFAULT_GOOS)-$(DEFAULT_GOARCH) because MM_SERVICESETTINGS_ENABLEDEVELOPER is enabled
Expand Down Expand Up @@ -412,7 +433,7 @@ help:

mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/mockgen@v1.6.0
go install go.uber.org/mock/mockgen@v0.6.0
$(GOBIN)/mockgen -destination=server/command/mocks/mock_commands.go -package=mocks github.com/mattermost/mattermost-plugin-matrix-bridge/server/command Command
$(GOBIN)/mockgen -destination=server/mocks/mock_plugin_api.go -package=mocks github.com/mattermost/mattermost/server/public/plugin API
$(GOBIN)/mockgen -destination=server/mocks/mock_kvstore.go -package=mocks github.com/mattermost/mattermost-plugin-matrix-bridge/server/store/kvstore KVStore
Expand Down
24 changes: 14 additions & 10 deletions build/manifest/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Package main provides manifest management utilities for the Mattermost Matrix Bridge plugin.
package main

import (
"encoding/json"
"fmt"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -102,7 +102,7 @@ func findManifest() (*model.Manifest, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to find manifest in current working directory")
}
manifestFile, err := os.Open(manifestFilePath)
manifestFile, err := os.Open(manifestFilePath) //nolint:gosec
if err != nil {
return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath)
}
Expand All @@ -121,8 +121,8 @@ func findManifest() (*model.Manifest, error) {
// commit, and use the first version we find (to prevent causing errors)
if manifest.Version == "" {
var version string
tags := strings.Fields(BuildTagCurrent)
for _, t := range tags {
tags := strings.FieldsSeq(BuildTagCurrent)
for t := range tags {
if strings.HasPrefix(t, "v") {
version = t
break
Expand All @@ -140,7 +140,11 @@ func findManifest() (*model.Manifest, error) {

// If no release notes specified, generate one from the latest tag, if present.
if manifest.ReleaseNotesURL == "" && BuildTagLatest != "" {
manifest.ReleaseNotesURL = manifest.HomepageURL + "releases/tag/" + BuildTagLatest
releaseNotesURL, err := url.JoinPath(manifest.HomepageURL, "releases", "tag", BuildTagLatest)
if err != nil {
return nil, errors.Wrap(err, "failed to build release notes URL")
}
manifest.ReleaseNotesURL = releaseNotesURL
}

return &manifest, nil
Expand Down Expand Up @@ -169,8 +173,8 @@ func applyManifest(manifest *model.Manifest) error {
// write generated code to file by using Go file template.
if err := os.WriteFile(
"server/manifest.go",
[]byte(fmt.Sprintf(pluginIDGoFileTemplate, manifestStr)),
0600,
fmt.Appendf(nil, pluginIDGoFileTemplate, manifestStr),
0o600,
); err != nil {
return errors.Wrap(err, "failed to write server/manifest.go")
}
Expand All @@ -192,8 +196,8 @@ func applyManifest(manifest *model.Manifest) error {
// write generated code to file by using JS file template.
if err := os.WriteFile(
"webapp/src/manifest.ts",
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
0600,
fmt.Appendf(nil, pluginIDJSFileTemplate, manifestStr),
0o600,
); err != nil {
return errors.Wrap(err, "failed to open webapp/src/manifest.ts")
}
Expand All @@ -209,7 +213,7 @@ func distManifest(manifest *model.Manifest) error {
return err
}

if err := os.WriteFile(fmt.Sprintf("dist/%s/plugin.json", manifest.Id), manifestBytes, 0600); err != nil {
if err := os.WriteFile(fmt.Sprintf("dist/%s/plugin.json", manifest.Id), manifestBytes, 0o600); err != nil {
return errors.Wrap(err, "failed to write plugin.json")
}

Expand Down
2 changes: 1 addition & 1 deletion build/pluginctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func getUnixClient(socketPath string) (*model.Client4, bool) {
// deploy attempts to upload and enable a plugin via the Client4 API.
// It will fail if plugin uploads are disabled.
func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath string) error {
pluginBundle, err := os.Open(bundlePath)
pluginBundle, err := os.Open(bundlePath) //nolint:gosec
if err != nil {
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
}
Expand Down
Loading
Loading