Mattermost plugin first commit
This commit is contained in:
parent
65234e17dd
commit
88121da341
6
mattermost-plugin/.gitignore
vendored
Normal file
6
mattermost-plugin/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
dist/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Mac
|
||||||
|
.DS_Store
|
||||||
|
|
201
mattermost-plugin/LICENSE
Normal file
201
mattermost-plugin/LICENSE
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
259
mattermost-plugin/Makefile
Normal file
259
mattermost-plugin/Makefile
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
GO ?= $(shell command -v go 2> /dev/null)
|
||||||
|
NPM ?= $(shell command -v npm 2> /dev/null)
|
||||||
|
CURL ?= $(shell command -v curl 2> /dev/null)
|
||||||
|
MM_DEBUG ?=
|
||||||
|
MANIFEST_FILE ?= plugin.json
|
||||||
|
GOPATH ?= $(shell go env GOPATH)
|
||||||
|
GO_TEST_FLAGS ?= -race
|
||||||
|
GO_BUILD_FLAGS ?=
|
||||||
|
MM_UTILITIES_DIR ?= ../mattermost-utilities
|
||||||
|
DLV_DEBUG_PORT := 2346
|
||||||
|
DEFAULT_GOOS := $(shell go env GOOS)
|
||||||
|
DEFAULT_GOARCH := $(shell go env GOARCH)
|
||||||
|
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
|
# You can include assets this directory into the bundle. This can be e.g. used to include profile pictures.
|
||||||
|
ASSETS_DIR ?= assets
|
||||||
|
|
||||||
|
## Define the default target (make all)
|
||||||
|
.PHONY: default
|
||||||
|
default: all
|
||||||
|
|
||||||
|
# Verify environment, and define PLUGIN_ID, PLUGIN_VERSION, HAS_SERVER and HAS_WEBAPP as needed.
|
||||||
|
include build/setup.mk
|
||||||
|
include build/legacy.mk
|
||||||
|
|
||||||
|
BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz
|
||||||
|
|
||||||
|
# Include custom makefile, if present
|
||||||
|
ifneq ($(wildcard build/custom.mk),)
|
||||||
|
include build/custom.mk
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Checks the code style, tests, builds and bundles the plugin.
|
||||||
|
.PHONY: all
|
||||||
|
all: dist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Builds the server, if it exists, for all supported architectures, unless MM_SERVICESETTINGS_ENABLEDEVELOPER is set.
|
||||||
|
.PHONY: server
|
||||||
|
server:
|
||||||
|
ifneq ($(HAS_SERVER),)
|
||||||
|
mkdir -p server/dist;
|
||||||
|
ifeq ($(MM_DEBUG),)
|
||||||
|
ifneq ($(MM_SERVICESETTINGS_ENABLEDEVELOPER),)
|
||||||
|
@echo Building plugin only for $(DEFAULT_GOOS)-$(DEFAULT_GOARCH) because MM_SERVICESETTINGS_ENABLEDEVELOPER is enabled
|
||||||
|
cd server && $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-$(DEFAULT_GOOS)-$(DEFAULT_GOARCH);
|
||||||
|
else
|
||||||
|
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-amd64;
|
||||||
|
cd server && env GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-arm64;
|
||||||
|
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-amd64;
|
||||||
|
cd server && env GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-arm64;
|
||||||
|
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
$(info DEBUG mode is on; to disable, unset MM_DEBUG)
|
||||||
|
ifneq ($(MM_SERVICESETTINGS_ENABLEDEVELOPER),)
|
||||||
|
@echo Building plugin only for $(DEFAULT_GOOS)-$(DEFAULT_GOARCH) because MM_SERVICESETTINGS_ENABLEDEVELOPER is enabled
|
||||||
|
cd server && $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-$(DEFAULT_GOOS)-$(DEFAULT_GOARCH);
|
||||||
|
else
|
||||||
|
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-linux-amd64;
|
||||||
|
cd server && env GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-linux-arm64;
|
||||||
|
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-darwin-amd64;
|
||||||
|
cd server && env GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-darwin-arm64;
|
||||||
|
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -gcflags "all=-N -l" -trimpath -o dist/plugin-windows-amd64.exe;
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Ensures NPM dependencies are installed without having to run this all the time.
|
||||||
|
webapp/node_modules: $(wildcard webapp/package.json)
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
cd webapp && $(NPM) install
|
||||||
|
touch $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Builds the webapp, if it exists.
|
||||||
|
.PHONY: webapp
|
||||||
|
webapp: webapp/node_modules
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
ifeq ($(MM_DEBUG),)
|
||||||
|
cd webapp && $(NPM) run build;
|
||||||
|
else
|
||||||
|
cd webapp && $(NPM) run debug;
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Generates a tar bundle of the plugin for install.
|
||||||
|
.PHONY: bundle
|
||||||
|
bundle:
|
||||||
|
rm -rf dist/
|
||||||
|
mkdir -p dist/$(PLUGIN_ID)
|
||||||
|
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/
|
||||||
|
ifneq ($(wildcard $(ASSETS_DIR)/.),)
|
||||||
|
cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/
|
||||||
|
endif
|
||||||
|
ifneq ($(HAS_PUBLIC),)
|
||||||
|
cp -r public dist/$(PLUGIN_ID)/
|
||||||
|
endif
|
||||||
|
ifneq ($(HAS_SERVER),)
|
||||||
|
mkdir -p dist/$(PLUGIN_ID)/server
|
||||||
|
cp -r server/dist dist/$(PLUGIN_ID)/server/
|
||||||
|
endif
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
mkdir -p dist/$(PLUGIN_ID)/webapp
|
||||||
|
cp -r webapp/dist dist/$(PLUGIN_ID)/webapp/
|
||||||
|
endif
|
||||||
|
cd dist && tar -cvzf $(BUNDLE_NAME) $(PLUGIN_ID)
|
||||||
|
|
||||||
|
@echo plugin built at: dist/$(BUNDLE_NAME)
|
||||||
|
|
||||||
|
## Builds and bundles the plugin.
|
||||||
|
.PHONY: dist
|
||||||
|
dist: server webapp bundle
|
||||||
|
|
||||||
|
## Builds and installs the plugin to a server.
|
||||||
|
.PHONY: deploy
|
||||||
|
deploy: dist
|
||||||
|
./build/bin/pluginctl deploy $(PLUGIN_ID) dist/$(BUNDLE_NAME)
|
||||||
|
|
||||||
|
## Builds and installs the plugin to a server, updating the webapp automatically when changed.
|
||||||
|
.PHONY: watch
|
||||||
|
watch: server bundle
|
||||||
|
ifeq ($(MM_DEBUG),)
|
||||||
|
cd webapp && $(NPM) run build:watch
|
||||||
|
else
|
||||||
|
cd webapp && $(NPM) run debug:watch
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Installs a previous built plugin with updated webpack assets to a server.
|
||||||
|
.PHONY: deploy-from-watch
|
||||||
|
deploy-from-watch: bundle
|
||||||
|
./build/bin/pluginctl deploy $(PLUGIN_ID) dist/$(BUNDLE_NAME)
|
||||||
|
|
||||||
|
## Setup dlv for attaching, identifying the plugin PID for other targets.
|
||||||
|
.PHONY: setup-attach
|
||||||
|
setup-attach:
|
||||||
|
$(eval PLUGIN_PID := $(shell ps aux | grep "plugins/${PLUGIN_ID}" | grep -v "grep" | awk -F " " '{print $$2}'))
|
||||||
|
$(eval NUM_PID := $(shell echo -n ${PLUGIN_PID} | wc -w))
|
||||||
|
|
||||||
|
@if [ ${NUM_PID} -gt 2 ]; then \
|
||||||
|
echo "** There is more than 1 plugin process running. Run 'make kill reset' to restart just one."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check if setup-attach succeeded.
|
||||||
|
.PHONY: check-attach
|
||||||
|
check-attach:
|
||||||
|
@if [ -z ${PLUGIN_PID} ]; then \
|
||||||
|
echo "Could not find plugin PID; the plugin is not running. Exiting."; \
|
||||||
|
exit 1; \
|
||||||
|
else \
|
||||||
|
echo "Located Plugin running with PID: ${PLUGIN_PID}"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Attach dlv to an existing plugin instance.
|
||||||
|
.PHONY: attach
|
||||||
|
attach: setup-attach check-attach
|
||||||
|
dlv attach ${PLUGIN_PID}
|
||||||
|
|
||||||
|
## Attach dlv to an existing plugin instance, exposing a headless instance on $DLV_DEBUG_PORT.
|
||||||
|
.PHONY: attach-headless
|
||||||
|
attach-headless: setup-attach check-attach
|
||||||
|
dlv attach ${PLUGIN_PID} --listen :$(DLV_DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient
|
||||||
|
|
||||||
|
## Detach dlv from an existing plugin instance, if previously attached.
|
||||||
|
.PHONY: detach
|
||||||
|
detach: setup-attach
|
||||||
|
@DELVE_PID=$(shell ps aux | grep "dlv attach ${PLUGIN_PID}" | grep -v "grep" | awk -F " " '{print $$2}') && \
|
||||||
|
if [ "$$DELVE_PID" -gt 0 ] > /dev/null 2>&1 ; then \
|
||||||
|
echo "Located existing delve process running with PID: $$DELVE_PID. Killing." ; \
|
||||||
|
kill -9 $$DELVE_PID ; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Runs any lints and unit tests defined for the server and webapp, if they exist.
|
||||||
|
.PHONY: test
|
||||||
|
test: webapp/node_modules
|
||||||
|
ifneq ($(HAS_SERVER),)
|
||||||
|
$(GO) test -v $(GO_TEST_FLAGS) ./server/...
|
||||||
|
endif
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
cd webapp && $(NPM) run test;
|
||||||
|
endif
|
||||||
|
ifneq ($(wildcard ./build/sync/plan/.),)
|
||||||
|
cd ./build/sync && $(GO) test -v $(GO_TEST_FLAGS) ./...
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Creates a coverage report for the server code.
|
||||||
|
.PHONY: coverage
|
||||||
|
coverage: webapp/node_modules
|
||||||
|
ifneq ($(HAS_SERVER),)
|
||||||
|
$(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./server/...
|
||||||
|
$(GO) tool cover -html=server/coverage.txt
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Extract strings for translation from the source code.
|
||||||
|
.PHONY: i18n-extract
|
||||||
|
i18n-extract:
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
ifeq ($(HAS_MM_UTILITIES),)
|
||||||
|
@echo "You must clone github.com/mattermost/mattermost-utilities repo in .. to use this command"
|
||||||
|
else
|
||||||
|
cd $(MM_UTILITIES_DIR) && npm install && npm run babel && node mmjstool/build/index.js i18n extract-webapp --webapp-dir $(PWD)/webapp
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
## Disable the plugin.
|
||||||
|
.PHONY: disable
|
||||||
|
disable: detach
|
||||||
|
./build/bin/pluginctl disable $(PLUGIN_ID)
|
||||||
|
|
||||||
|
## Enable the plugin.
|
||||||
|
.PHONY: enable
|
||||||
|
enable:
|
||||||
|
./build/bin/pluginctl enable $(PLUGIN_ID)
|
||||||
|
|
||||||
|
## Reset the plugin, effectively disabling and re-enabling it on the server.
|
||||||
|
.PHONY: reset
|
||||||
|
reset: detach
|
||||||
|
./build/bin/pluginctl reset $(PLUGIN_ID)
|
||||||
|
|
||||||
|
## Kill all instances of the plugin, detaching any existing dlv instance.
|
||||||
|
.PHONY: kill
|
||||||
|
kill: detach
|
||||||
|
$(eval PLUGIN_PID := $(shell ps aux | grep "plugins/${PLUGIN_ID}" | grep -v "grep" | awk -F " " '{print $$2}'))
|
||||||
|
|
||||||
|
@for PID in ${PLUGIN_PID}; do \
|
||||||
|
echo "Killing plugin pid $$PID"; \
|
||||||
|
kill -9 $$PID; \
|
||||||
|
done; \
|
||||||
|
|
||||||
|
## Clean removes all build artifacts.
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -fr dist/
|
||||||
|
ifneq ($(HAS_SERVER),)
|
||||||
|
rm -fr server/coverage.txt
|
||||||
|
rm -fr server/dist
|
||||||
|
endif
|
||||||
|
ifneq ($(HAS_WEBAPP),)
|
||||||
|
rm -fr webapp/junit.xml
|
||||||
|
rm -fr webapp/dist
|
||||||
|
rm -fr webapp/node_modules
|
||||||
|
endif
|
||||||
|
rm -fr build/bin/
|
||||||
|
|
||||||
|
## Sync directory with a starter template
|
||||||
|
sync:
|
||||||
|
ifndef STARTERTEMPLATE_PATH
|
||||||
|
@echo STARTERTEMPLATE_PATH is not set.
|
||||||
|
@echo Set STARTERTEMPLATE_PATH to a local clone of https://github.com/mattermost/mattermost-plugin-starter-template and retry.
|
||||||
|
@exit 1
|
||||||
|
endif
|
||||||
|
cd ${STARTERTEMPLATE_PATH} && go run ./build/sync/main.go ./build/sync/plan.yml $(PWD)
|
||||||
|
|
||||||
|
# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||||
|
help:
|
||||||
|
@cat Makefile build/*.mk | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
|
138
mattermost-plugin/README.md
Normal file
138
mattermost-plugin/README.md
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
# Plugin Starter Template [![CircleCI branch](https://img.shields.io/circleci/project/github/mattermost/mattermost-plugin-starter-template/master.svg)](https://circleci.com/gh/mattermost/mattermost-plugin-starter-template)
|
||||||
|
|
||||||
|
This plugin serves as a starting point for writing a Mattermost plugin. Feel free to base your own plugin off this repository.
|
||||||
|
|
||||||
|
To learn more about plugins, see [our plugin documentation](https://developers.mattermost.com/extend/plugins/).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
Use GitHub's template feature to make a copy of this repository by clicking the "Use this template" button.
|
||||||
|
|
||||||
|
Alternatively shallow clone the repository matching your plugin name:
|
||||||
|
```
|
||||||
|
git clone --depth 1 https://github.com/mattermost/mattermost-plugin-starter-template com.example.my-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that this project uses [Go modules](https://github.com/golang/go/wiki/Modules). Be sure to locate the project outside of `$GOPATH`.
|
||||||
|
|
||||||
|
Edit the following files:
|
||||||
|
1. `plugin.json` with your `id`, `name`, and `description`:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"id": "com.example.my-plugin",
|
||||||
|
"name": "My Plugin",
|
||||||
|
"description": "A plugin to enhance Mattermost."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. `go.mod` with your Go module path, following the `<hosting-site>/<repository>/<module>` convention:
|
||||||
|
```
|
||||||
|
module github.com/example/my-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
3. `.golangci.yml` with your Go module path:
|
||||||
|
```yml
|
||||||
|
linters-settings:
|
||||||
|
# [...]
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/example/my-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
Build your plugin:
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
This will produce a single plugin file (with support for multiple architectures) for upload to your Mattermost server:
|
||||||
|
|
||||||
|
```
|
||||||
|
dist/com.example.my-plugin.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
To avoid having to manually install your plugin, build and deploy your plugin using one of the following options. In order for the below options to work, you must first enable plugin uploads via your config.json or API and restart Mattermost.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"PluginSettings" : {
|
||||||
|
...
|
||||||
|
"EnableUploads" : true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deploying with Local Mode
|
||||||
|
|
||||||
|
If your Mattermost server is running locally, you can enable [local mode](https://docs.mattermost.com/administration/mmctl-cli-tool.html#local-mode) to streamline deploying your plugin. Edit your server configuration as follows:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ServiceSettings": {
|
||||||
|
...
|
||||||
|
"EnableLocalMode": true,
|
||||||
|
"LocalModeSocketLocation": "/var/tmp/mattermost_local.socket"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and then deploy your plugin:
|
||||||
|
```
|
||||||
|
make deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
You may also customize the Unix socket path:
|
||||||
|
```
|
||||||
|
export MM_LOCALSOCKETPATH=/var/tmp/alternate_local.socket
|
||||||
|
make deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
If developing a plugin with a webapp, watch for changes and deploy those automatically:
|
||||||
|
```
|
||||||
|
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
|
||||||
|
export MM_ADMIN_TOKEN=j44acwd8obn78cdcx7koid4jkr
|
||||||
|
make watch
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deploying with credentials
|
||||||
|
|
||||||
|
Alternatively, you can authenticate with the server's API with credentials:
|
||||||
|
```
|
||||||
|
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
|
||||||
|
export MM_ADMIN_USERNAME=admin
|
||||||
|
export MM_ADMIN_PASSWORD=password
|
||||||
|
make deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
or with a [personal access token](https://docs.mattermost.com/developer/personal-access-tokens.html):
|
||||||
|
```
|
||||||
|
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
|
||||||
|
export MM_ADMIN_TOKEN=j44acwd8obn78cdcx7koid4jkr
|
||||||
|
make deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
## Q&A
|
||||||
|
|
||||||
|
### How do I make a server-only or web app-only plugin?
|
||||||
|
|
||||||
|
Simply delete the `server` or `webapp` folders and remove the corresponding sections from `plugin.json`. The build scripts will skip the missing portions automatically.
|
||||||
|
|
||||||
|
### How do I include assets in the plugin bundle?
|
||||||
|
|
||||||
|
Place them into the `assets` directory. To use an asset at runtime, build the path to your asset and open as a regular file:
|
||||||
|
|
||||||
|
```go
|
||||||
|
bundlePath, err := p.API.GetBundlePath()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to get bundle path")
|
||||||
|
}
|
||||||
|
|
||||||
|
profileImage, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "profile_image.png"))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to read profile image")
|
||||||
|
}
|
||||||
|
|
||||||
|
if appErr := p.API.SetProfileImage(userID, profileImage); appErr != nil {
|
||||||
|
return errors.Wrap(err, "failed to set profile image")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### How do I build the plugin with unminified JavaScript?
|
||||||
|
Setting the `MM_DEBUG` environment variable will invoke the debug builds. The simplist way to do this is to simply include this variable in your calls to `make` (e.g. `make dist MM_DEBUG=1`).
|
14
mattermost-plugin/assets/starter-template-icon.svg
Normal file
14
mattermost-plugin/assets/starter-template-icon.svg
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="241px" height="240px" viewBox="0 0 241 240" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
|
||||||
|
<title>blue-icon</title>
|
||||||
|
<desc>Created with Sketch.</desc>
|
||||||
|
<defs></defs>
|
||||||
|
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||||
|
<g id="06" transform="translate(-681.000000, -572.000000)" fill="#1875F0">
|
||||||
|
<g id="Group-2" transform="translate(626.000000, 517.000000)">
|
||||||
|
<path d="M216.908181,153.127705 C216.908181,153.127705 217.280588,169.452526 205.928754,180.543035 C194.57546,191.633544 180.631383,190.619887 171.560722,187.557072 C162.488602,184.494256 150.79503,176.85251 148.531381,161.16705 C146.269193,145.480133 156.508188,132.736607 156.508188,132.736607 L178.820463,105.066407 L191.815268,89.2629779 L202.969946,75.4912313 C202.969946,75.4912313 208.088713,68.6534193 209.547671,67.2421648 C209.836834,66.9625354 210.133299,66.7790286 210.423923,66.6377576 L210.635683,66.5299837 L210.673654,66.5154197 C211.28703,66.2518108 211.993873,66.195011 212.675888,66.4251227 C213.343299,66.6508652 213.860288,67.1081757 214.187421,67.6718037 L214.256061,67.7810339 L214.315938,67.9062846 C214.475124,68.2063036 214.608022,68.5485583 214.67082,68.9709151 C214.968745,70.976382 214.870897,79.5094471 214.870897,79.5094471 L215.342613,97.2047434 L216.039232,117.630795 L216.908181,153.127705 Z M245.790587,78.2043261 C287.057212,108.155253 305.982915,162.509669 288.774288,213.346872 C267.594104,275.911031 199.706245,309.46073 137.142925,288.281718 C74.5796048,267.10125 41.031812,199.213937 62.2105402,136.649778 C79.4482947,85.7295603 127.625459,54.0324057 178.690632,55.4145322 L162.322339,74.7541074 C132.028106,80.231639 105.87146,100.919843 95.5908489,131.290215 C80.2944535,176.475117 105.932628,225.982624 152.855846,241.866155 C199.777608,257.751142 250.216536,233.998666 265.512932,188.813764 C275.760046,158.543884 267.634882,126.336988 247.050359,103.595256 L245.790587,78.2043261 Z" id="blue-icon"></path>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
9
mattermost-plugin/go.mod
Normal file
9
mattermost-plugin/go.mod
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module github.com/zefhemel/mattermost-silverbullet-plugin
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mattermost/mattermost-server/v6 v6.2.1
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
|
github.com/stretchr/testify v1.7.0
|
||||||
|
)
|
1651
mattermost-plugin/go.sum
Normal file
1651
mattermost-plugin/go.sum
Normal file
File diff suppressed because it is too large
Load Diff
18
mattermost-plugin/plugin.go
Normal file
18
mattermost-plugin/plugin.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package root
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed" // Need to embed manifest file
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed plugin.json
|
||||||
|
var manifestString string
|
||||||
|
|
||||||
|
var Manifest model.Manifest
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_ = json.NewDecoder(strings.NewReader(manifestString)).Decode(&Manifest)
|
||||||
|
}
|
28
mattermost-plugin/plugin.json
Normal file
28
mattermost-plugin/plugin.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"id": "silverbullet",
|
||||||
|
"name": "Silver Bullet",
|
||||||
|
"description": "Silver Bullet integration into Mattermost",
|
||||||
|
"homepage_url": "https://github.com/silverbulletmd/silverbullet",
|
||||||
|
"support_url": "https://github.com/silverbulletmd/silverbullet/issues",
|
||||||
|
"release_notes_url": "https://github.com/silverbulletmd/silverbullet/releases/tag/v0.1.0",
|
||||||
|
"icon_path": "assets/starter-template-icon.svg",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"min_server_version": "6.0.0",
|
||||||
|
"server": {
|
||||||
|
"executables": {
|
||||||
|
"linux-amd64": "server/dist/plugin-linux-amd64",
|
||||||
|
"linux-arm64": "server/dist/plugin-linux-arm64",
|
||||||
|
"darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||||
|
"darwin-arm64": "server/dist/plugin-darwin-arm64",
|
||||||
|
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"webapp": {
|
||||||
|
"bundle_path": "webapp/dist/index.js"
|
||||||
|
},
|
||||||
|
"settings_schema": {
|
||||||
|
"header": "",
|
||||||
|
"footer": "",
|
||||||
|
"settings": []
|
||||||
|
}
|
||||||
|
}
|
83
mattermost-plugin/server/configuration.go
Normal file
83
mattermost-plugin/server/configuration.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// configuration captures the plugin's external configuration as exposed in the Mattermost server
|
||||||
|
// configuration, as well as values computed from the configuration. Any public fields will be
|
||||||
|
// deserialized from the Mattermost server configuration in OnConfigurationChange.
|
||||||
|
//
|
||||||
|
// As plugins are inherently concurrent (hooks being called asynchronously), and the plugin
|
||||||
|
// configuration can change at any time, access to the configuration must be synchronized. The
|
||||||
|
// strategy used in this plugin is to guard a pointer to the configuration, and clone the entire
|
||||||
|
// struct whenever it changes. You may replace this with whatever strategy you choose.
|
||||||
|
//
|
||||||
|
// If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep
|
||||||
|
// copy appropriate for your types.
|
||||||
|
type configuration struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone shallow copies the configuration. Your implementation may require a deep copy if
|
||||||
|
// your configuration has reference types.
|
||||||
|
func (c *configuration) Clone() *configuration {
|
||||||
|
var clone = *c
|
||||||
|
return &clone
|
||||||
|
}
|
||||||
|
|
||||||
|
// getConfiguration retrieves the active configuration under lock, making it safe to use
|
||||||
|
// concurrently. The active configuration may change underneath the client of this method, but
|
||||||
|
// the struct returned by this API call is considered immutable.
|
||||||
|
func (p *Plugin) getConfiguration() *configuration {
|
||||||
|
p.configurationLock.RLock()
|
||||||
|
defer p.configurationLock.RUnlock()
|
||||||
|
|
||||||
|
if p.configuration == nil {
|
||||||
|
return &configuration{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
// setConfiguration replaces the active configuration under lock.
|
||||||
|
//
|
||||||
|
// Do not call setConfiguration while holding the configurationLock, as sync.Mutex is not
|
||||||
|
// reentrant. In particular, avoid using the plugin API entirely, as this may in turn trigger a
|
||||||
|
// hook back into the plugin. If that hook attempts to acquire this lock, a deadlock may occur.
|
||||||
|
//
|
||||||
|
// This method panics if setConfiguration is called with the existing configuration. This almost
|
||||||
|
// certainly means that the configuration was modified without being cloned and may result in
|
||||||
|
// an unsafe access.
|
||||||
|
func (p *Plugin) setConfiguration(configuration *configuration) {
|
||||||
|
p.configurationLock.Lock()
|
||||||
|
defer p.configurationLock.Unlock()
|
||||||
|
|
||||||
|
if configuration != nil && p.configuration == configuration {
|
||||||
|
// Ignore assignment if the configuration struct is empty. Go will optimize the
|
||||||
|
// allocation for same to point at the same memory address, breaking the check
|
||||||
|
// above.
|
||||||
|
if reflect.ValueOf(*configuration).NumField() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("setConfiguration called with the existing configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
p.configuration = configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConfigurationChange is invoked when configuration changes may have been made.
|
||||||
|
func (p *Plugin) OnConfigurationChange() error {
|
||||||
|
var configuration = new(configuration)
|
||||||
|
|
||||||
|
// Load the public configuration fields from the Mattermost server configuration.
|
||||||
|
if err := p.API.LoadPluginConfiguration(configuration); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to load plugin configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
p.setConfiguration(configuration)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
9
mattermost-plugin/server/main.go
Normal file
9
mattermost-plugin/server/main.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
plugin.ClientMain(&Plugin{})
|
||||||
|
}
|
74
mattermost-plugin/server/plugin.go
Normal file
74
mattermost-plugin/server/plugin.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.
|
||||||
|
type Plugin struct {
|
||||||
|
plugin.MattermostPlugin
|
||||||
|
|
||||||
|
// configurationLock synchronizes access to the configuration.
|
||||||
|
configurationLock sync.RWMutex
|
||||||
|
|
||||||
|
// configuration is the active plugin configuration. Consult getConfiguration and
|
||||||
|
// setConfiguration for usage.
|
||||||
|
configuration *configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeHTTP demonstrates a plugin that handles HTTP requests by greeting the world.
|
||||||
|
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
if strings.HasPrefix(r.URL.Path, "/fs") || strings.HasPrefix(r.URL.Path, "/plug/") {
|
||||||
|
p.httpProxy(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.URL.Path == "/global.plug.json" {
|
||||||
|
p.httpProxy(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r2, err := http.Get("http://localhost:8065")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
io.Copy(w, r2.Body)
|
||||||
|
|
||||||
|
// fmt.Fprint(w, "Hello, world!")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Plugin) httpProxy(w http.ResponseWriter, r *http.Request) {
|
||||||
|
defer r.Body.Close()
|
||||||
|
mlog.Info(fmt.Sprintf("Got HTTP request: %s: %s Headers: %+v", r.Method, r.URL, r.Header))
|
||||||
|
req, err := http.NewRequest(r.Method, fmt.Sprintf("http://localhost:%d%s", 3000, r.URL), r.Body)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("Proxy error: %s", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Header = r.Header
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("Proxy error: %s", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for k, vs := range res.Header {
|
||||||
|
for _, v := range vs {
|
||||||
|
w.Header().Add(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.WriteHeader(res.StatusCode)
|
||||||
|
_, err = io.Copy(w, res.Body)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Error("Error proxying", mlog.Err(err))
|
||||||
|
}
|
||||||
|
res.Body.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// See https://developers.mattermost.com/extend/plugins/server/reference/
|
28
mattermost-plugin/server/plugin_test.go
Normal file
28
mattermost-plugin/server/plugin_test.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestServeHTTP(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
plugin := Plugin{}
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
|
||||||
|
plugin.ServeHTTP(nil, w, r)
|
||||||
|
|
||||||
|
result := w.Result()
|
||||||
|
assert.NotNil(result)
|
||||||
|
defer result.Body.Close()
|
||||||
|
bodyBytes, err := ioutil.ReadAll(result.Body)
|
||||||
|
assert.Nil(err)
|
||||||
|
bodyString := string(bodyBytes)
|
||||||
|
|
||||||
|
assert.Equal("Hello, world!", bodyString)
|
||||||
|
}
|
3
mattermost-plugin/webapp/.gitignore
vendored
Normal file
3
mattermost-plugin/webapp/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.eslintcache
|
||||||
|
junit.xml
|
||||||
|
node_modules
|
1
mattermost-plugin/webapp/i18n/en.json
Normal file
1
mattermost-plugin/webapp/i18n/en.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
68
mattermost-plugin/webapp/package.json
Normal file
68
mattermost-plugin/webapp/package.json
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"name": "silverbullet-mattermost-plugin",
|
||||||
|
"private": true,
|
||||||
|
"author": {
|
||||||
|
"name": "Zef Hemel",
|
||||||
|
"email": "zef@zef.me"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"watch": "rm -rf .parcel-cache && parcel watch",
|
||||||
|
"build": "parcel build",
|
||||||
|
"clean": "rm -rf dist"
|
||||||
|
},
|
||||||
|
"targets": {
|
||||||
|
"plugin": {
|
||||||
|
"source": [
|
||||||
|
"src/index.tsx"
|
||||||
|
],
|
||||||
|
"distDir": "dist",
|
||||||
|
"context": "browser"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"alias": {
|
||||||
|
"react": "./src/hack.js",
|
||||||
|
"react/jsx-runtime": "react/jsx-runtime"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "6.0.1",
|
||||||
|
"@codemirror/commands": "6.0.0",
|
||||||
|
"@codemirror/lang-javascript": "6.0.0",
|
||||||
|
"@codemirror/lang-markdown": "6.0.0",
|
||||||
|
"@codemirror/language": "6.0.0",
|
||||||
|
"@codemirror/legacy-modes": "6.0.0",
|
||||||
|
"@codemirror/search": "6.0.0",
|
||||||
|
"@codemirror/state": "6.0.0",
|
||||||
|
"@codemirror/view": "6.0.0",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "6.0.0",
|
||||||
|
"@fortawesome/react-fontawesome": "0.1.17",
|
||||||
|
"@jest/globals": "^27.5.1",
|
||||||
|
"@lezer/highlight": "1.0.0",
|
||||||
|
"@lezer/markdown": "1.0.1",
|
||||||
|
"fake-indexeddb": "^3.1.7",
|
||||||
|
"fuzzysort": "^1.9.0",
|
||||||
|
"jest": "^27.5.1",
|
||||||
|
"knex": "^1.0.4",
|
||||||
|
"react": "17.0.2",
|
||||||
|
"react-dom": "17.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@parcel/packager-raw-url": "2.5.0",
|
||||||
|
"@parcel/service-worker": "2.5.0",
|
||||||
|
"@parcel/transformer-inline-string": "2.5.0",
|
||||||
|
"@parcel/transformer-sass": "2.5.0",
|
||||||
|
"@parcel/transformer-webmanifest": "2.5.0",
|
||||||
|
"@parcel/validator-typescript": "2.5.0",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
|
"@types/events": "^3.0.0",
|
||||||
|
"@types/jest": "^27.4.1",
|
||||||
|
"@types/react": "17.0.2",
|
||||||
|
"@types/react-dom": "17.0.2",
|
||||||
|
"assert": "^2.0.0",
|
||||||
|
"nodemon": "^2.0.18",
|
||||||
|
"parcel": "2.5.0",
|
||||||
|
"prettier": "^2.5.1",
|
||||||
|
"typescript": "^4.6.2"
|
||||||
|
}
|
||||||
|
}
|
3
mattermost-plugin/webapp/src/hack.js
Normal file
3
mattermost-plugin/webapp/src/hack.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default window.React;
|
||||||
|
const { useEffect, useRef } = window.React;
|
||||||
|
export { useEffect, useRef };
|
63
mattermost-plugin/webapp/src/index.tsx
Normal file
63
mattermost-plugin/webapp/src/index.tsx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import manifest from "./manifest";
|
||||||
|
import React, { useEffect, useRef } from "react";
|
||||||
|
import { Editor } from "@silverbulletmd/web/editor";
|
||||||
|
import { HttpSpacePrimitives } from "@silverbulletmd/common/spaces/http_space_primitives";
|
||||||
|
import { safeRun } from "@plugos/plugos/util";
|
||||||
|
import { Space } from "@silverbulletmd/common/spaces/space";
|
||||||
|
|
||||||
|
import "../../../packages/web/styles/main.scss";
|
||||||
|
import "./styles.scss";
|
||||||
|
|
||||||
|
function loadSheet(file: string) {
|
||||||
|
var sbCSS = document.createElement("link");
|
||||||
|
sbCSS.rel = "stylesheet";
|
||||||
|
sbCSS.type = "text/css";
|
||||||
|
sbCSS.href = `/static/plugins/silverbullet/${file}`;
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(sbCSS);
|
||||||
|
}
|
||||||
|
|
||||||
|
const MainApp = (): React.ReactElement => {
|
||||||
|
let ref = useRef<HTMLDivElement>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
loadSheet("index.css");
|
||||||
|
|
||||||
|
safeRun(async () => {
|
||||||
|
let httpPrimitives = new HttpSpacePrimitives("/plugins/silverbullet", "");
|
||||||
|
const editor = new Editor(
|
||||||
|
new Space(httpPrimitives, true),
|
||||||
|
ref.current!,
|
||||||
|
"/plugins/silverbullet"
|
||||||
|
);
|
||||||
|
await editor.init();
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<div id="sb-root" ref={ref}>
|
||||||
|
This is Silver Bullet
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class Plugin {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
|
public async initialize(registry: any, store: any) {
|
||||||
|
// @see https://developers.mattermost.com/extend/plugins/webapp/reference/
|
||||||
|
console.log("SUP YALL SILVER BULLET!!!");
|
||||||
|
|
||||||
|
registry.registerProduct(
|
||||||
|
"/plugins/silverbullet",
|
||||||
|
"product-boards",
|
||||||
|
"Silver Bullet",
|
||||||
|
"/plugins/silverbullet",
|
||||||
|
MainApp
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
registerPlugin(id: string, plugin: Plugin): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.registerPlugin(manifest.id, new Plugin());
|
5
mattermost-plugin/webapp/src/manifest.ts
Normal file
5
mattermost-plugin/webapp/src/manifest.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import manifest from '../../plugin.json';
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
|
export const id = manifest.id;
|
||||||
|
export const version = manifest.version;
|
134
package-lock.json
generated
134
package-lock.json
generated
@ -8,7 +8,8 @@
|
|||||||
"name": "silverbulletmd",
|
"name": "silverbulletmd",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*",
|
||||||
|
"mattermost-plugin/webapp"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@parcel/core": "2.5.0",
|
"@parcel/core": "2.5.0",
|
||||||
@ -26,6 +27,70 @@
|
|||||||
"typescript": "^4.6.2"
|
"typescript": "^4.6.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mattermost-plugin/webapp": {
|
||||||
|
"name": "silverbullet-mattermost-plugin",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "6.0.1",
|
||||||
|
"@codemirror/commands": "6.0.0",
|
||||||
|
"@codemirror/lang-javascript": "6.0.0",
|
||||||
|
"@codemirror/lang-markdown": "6.0.0",
|
||||||
|
"@codemirror/language": "6.0.0",
|
||||||
|
"@codemirror/legacy-modes": "6.0.0",
|
||||||
|
"@codemirror/search": "6.0.0",
|
||||||
|
"@codemirror/state": "6.0.0",
|
||||||
|
"@codemirror/view": "6.0.0",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "6.0.0",
|
||||||
|
"@fortawesome/react-fontawesome": "0.1.17",
|
||||||
|
"@jest/globals": "^27.5.1",
|
||||||
|
"@lezer/highlight": "1.0.0",
|
||||||
|
"@lezer/markdown": "1.0.1",
|
||||||
|
"fake-indexeddb": "^3.1.7",
|
||||||
|
"fuzzysort": "^1.9.0",
|
||||||
|
"jest": "^27.5.1",
|
||||||
|
"knex": "^1.0.4",
|
||||||
|
"react": "17.0.2",
|
||||||
|
"react-dom": "17.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@parcel/packager-raw-url": "2.5.0",
|
||||||
|
"@parcel/service-worker": "2.5.0",
|
||||||
|
"@parcel/transformer-inline-string": "2.5.0",
|
||||||
|
"@parcel/transformer-sass": "2.5.0",
|
||||||
|
"@parcel/transformer-webmanifest": "2.5.0",
|
||||||
|
"@parcel/validator-typescript": "2.5.0",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
|
"@types/events": "^3.0.0",
|
||||||
|
"@types/jest": "^27.4.1",
|
||||||
|
"@types/react": "17.0.2",
|
||||||
|
"@types/react-dom": "17.0.2",
|
||||||
|
"assert": "^2.0.0",
|
||||||
|
"nodemon": "^2.0.18",
|
||||||
|
"parcel": "2.5.0",
|
||||||
|
"prettier": "^2.5.1",
|
||||||
|
"typescript": "^4.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mattermost-plugin/webapp/node_modules/@types/react": {
|
||||||
|
"version": "17.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.2.tgz",
|
||||||
|
"integrity": "sha512-Xt40xQsrkdvjn1EyWe1Bc0dJLcil/9x2vAuW7ya+PuQip4UYUaXyhzWmAbwRsdMgwOFHpfp7/FFZebDU6Y8VHA==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/prop-types": "*",
|
||||||
|
"csstype": "^3.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mattermost-plugin/webapp/node_modules/@types/react-dom": {
|
||||||
|
"version": "17.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.2.tgz",
|
||||||
|
"integrity": "sha512-Icd9KEgdnFfJs39KyRyr0jQ7EKhq8U6CcHRMGAS45fp5qgUvxL3ujUCfWFttUK2UErqZNj97t9gsVPNAqcwoCg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/react": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@ampproject/remapping": {
|
"node_modules/@ampproject/remapping": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
||||||
@ -15289,6 +15354,10 @@
|
|||||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||||
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
|
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/silverbullet-mattermost-plugin": {
|
||||||
|
"resolved": "mattermost-plugin/webapp",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
"node_modules/simple-concat": {
|
"node_modules/simple-concat": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
|
||||||
@ -33108,6 +33177,69 @@
|
|||||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||||
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
|
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
|
||||||
},
|
},
|
||||||
|
"silverbullet-mattermost-plugin": {
|
||||||
|
"version": "file:mattermost-plugin/webapp",
|
||||||
|
"requires": {
|
||||||
|
"@codemirror/autocomplete": "6.0.1",
|
||||||
|
"@codemirror/commands": "6.0.0",
|
||||||
|
"@codemirror/lang-javascript": "6.0.0",
|
||||||
|
"@codemirror/lang-markdown": "6.0.0",
|
||||||
|
"@codemirror/language": "6.0.0",
|
||||||
|
"@codemirror/legacy-modes": "6.0.0",
|
||||||
|
"@codemirror/search": "6.0.0",
|
||||||
|
"@codemirror/state": "6.0.0",
|
||||||
|
"@codemirror/view": "6.0.0",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "6.0.0",
|
||||||
|
"@fortawesome/react-fontawesome": "0.1.17",
|
||||||
|
"@jest/globals": "^27.5.1",
|
||||||
|
"@lezer/highlight": "1.0.0",
|
||||||
|
"@lezer/markdown": "1.0.1",
|
||||||
|
"@parcel/packager-raw-url": "2.5.0",
|
||||||
|
"@parcel/service-worker": "2.5.0",
|
||||||
|
"@parcel/transformer-inline-string": "2.5.0",
|
||||||
|
"@parcel/transformer-sass": "2.5.0",
|
||||||
|
"@parcel/transformer-webmanifest": "2.5.0",
|
||||||
|
"@parcel/validator-typescript": "2.5.0",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
|
"@types/events": "^3.0.0",
|
||||||
|
"@types/jest": "^27.4.1",
|
||||||
|
"@types/react": "17.0.2",
|
||||||
|
"@types/react-dom": "17.0.2",
|
||||||
|
"assert": "^2.0.0",
|
||||||
|
"fake-indexeddb": "^3.1.7",
|
||||||
|
"fuzzysort": "^1.9.0",
|
||||||
|
"jest": "^27.5.1",
|
||||||
|
"knex": "^1.0.4",
|
||||||
|
"nodemon": "^2.0.18",
|
||||||
|
"parcel": "2.5.0",
|
||||||
|
"prettier": "^2.5.1",
|
||||||
|
"react": "17.0.2",
|
||||||
|
"react-dom": "17.0.2",
|
||||||
|
"typescript": "^4.6.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/react": {
|
||||||
|
"version": "17.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.2.tgz",
|
||||||
|
"integrity": "sha512-Xt40xQsrkdvjn1EyWe1Bc0dJLcil/9x2vAuW7ya+PuQip4UYUaXyhzWmAbwRsdMgwOFHpfp7/FFZebDU6Y8VHA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/prop-types": "*",
|
||||||
|
"csstype": "^3.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"version": "17.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.2.tgz",
|
||||||
|
"integrity": "sha512-Icd9KEgdnFfJs39KyRyr0jQ7EKhq8U6CcHRMGAS45fp5qgUvxL3ujUCfWFttUK2UErqZNj97t9gsVPNAqcwoCg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/react": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"simple-concat": {
|
"simple-concat": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
"typescript": "^4.6.2"
|
"typescript": "^4.6.2"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*",
|
||||||
|
"mattermost-plugin/webapp"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user