No description
This repository has been archived on 2024-11-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Find a file
scott lee davis 0acb31f8a7 changed single expression plugin upload to validate responses (#36)
* changed single expression plugin upload to individual calls checking response.  fixes problems with no uploads on Ubuntu 16.04

* Updated error message as requested by @levb on #discussion_r275448965

* removed double PLUGIN_VERSION ref

* added  --post301 --location to curl invocation in ./build/bin/manifest apply
mkdir -p server/dist;
cd server && env GOOS=linux GOARCH=amd64 /usr/local/go/bin/go build -o dist/plugin-linux-amd64;
cd server && env GOOS=darwin GOARCH=amd64 /usr/local/go/bin/go build -o dist/plugin-darwin-amd64;
cd server && env GOOS=windows GOARCH=amd64 /usr/local/go/bin/go build -o dist/plugin-windows-amd64.exe;
cd webapp && /usr/local/bin/npm run build;

> webapp@0.0.1 build /home/skawtus/workspace/mattermost-plugin-sample/webapp
> webpack --mode=production

Hash: f6fcda45461a2f57b51b
Version: webpack 4.16.1
Time: 509ms
Built at: 2019-04-16 09:56:33
  Asset      Size  Chunks             Chunk Names
main.js  1.61 KiB       0  [emitted]  main
[0] multi ./src/index.js 28 bytes {0} [built]
[1] ./src/index.js 1.28 KiB {0} [built]
[2] ./src/manifest.js 174 bytes {0} [built]
rm -rf dist/
mkdir -p dist/com.mattermost.sample-plugin
cp plugin.json dist/com.mattermost.sample-plugin/
cp -r assets dist/com.mattermost.sample-plugin/
cp -r public/ dist/com.mattermost.sample-plugin/
mkdir -p dist/com.mattermost.sample-plugin/server/dist;
cp -r server/dist/* dist/com.mattermost.sample-plugin/server/dist/;
mkdir -p dist/com.mattermost.sample-plugin/webapp/dist;
cp -r webapp/dist/* dist/com.mattermost.sample-plugin/webapp/dist/;
cd dist && tar -cvzf com.mattermost.sample-plugin-0.1.0.tar.gz com.mattermost.sample-plugin
com.mattermost.sample-plugin/
com.mattermost.sample-plugin/webapp/
com.mattermost.sample-plugin/webapp/dist/
com.mattermost.sample-plugin/webapp/dist/main.js
com.mattermost.sample-plugin/assets/
com.mattermost.sample-plugin/assets/.gitkeep
com.mattermost.sample-plugin/plugin.json
com.mattermost.sample-plugin/server/
com.mattermost.sample-plugin/server/dist/
com.mattermost.sample-plugin/server/dist/plugin-darwin-amd64
com.mattermost.sample-plugin/server/dist/plugin-windows-amd64.exe
com.mattermost.sample-plugin/server/dist/plugin-linux-amd64
com.mattermost.sample-plugin/public/
com.mattermost.sample-plugin/public/hello.html
plugin built at: dist/com.mattermost.sample-plugin-0.1.0.tar.gz
Installing plugin via API
OK.

* reverted to original request sequence, combine with post301 & location flags to curl
2019-04-22 11:41:09 -04:00
.circleci Go modules (#22) 2019-04-10 12:42:33 -07:00
assets Allow plugins to include assets in the bundle (#28) 2019-03-18 20:09:23 +01:00
build Go modules (#22) 2019-04-10 12:42:33 -07:00
public MM-14575: Automatically serve static files for plugins (#33) 2019-04-02 13:22:01 -07:00
server Go modules (#22) 2019-04-10 12:42:33 -07:00
webapp Start with version 0.1.0 (#35) 2019-04-04 07:44:40 -07:00
.editorconfig Add .editorconfig (#34) 2019-03-25 10:31:26 -04:00
.gitignore initial commit 2018-07-23 13:43:22 -04:00
CHANGELOG.md initial commit 2018-07-23 13:43:22 -04:00
go.mod Go modules (#22) 2019-04-10 12:42:33 -07:00
go.sum Go modules (#22) 2019-04-10 12:42:33 -07:00
LICENSE initial commit 2018-07-23 13:43:22 -04:00
Makefile changed single expression plugin upload to validate responses (#36) 2019-04-22 11:41:09 -04:00
plugin.json Start with version 0.1.0 (#35) 2019-04-04 07:44:40 -07:00
README.md Go modules (#22) 2019-04-10 12:42:33 -07:00

Sample Plugin CircleCI branch

This plugin serves as a starting point for writing a Mattermost plugin. Feel free to base your own plugin off this repository.

Getting Started

Shallow clone the repository to a directory outside of $GOPATH matching your plugin name:

git clone --depth 1 https://github.com/mattermost/mattermost-plugin-sample com.example.my-plugin

Edit plugin.json with your id, name, and description:

{
    "id": "com.example.my-plugin",
    "name": "My Plugin",
    "description": "A plugin to enhance Mattermost."
}

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

There is a build target to automate deploying and enabling the plugin to your server, but it requires configuration and http to be installed:

export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
export MM_ADMIN_USERNAME=admin
export MM_ADMIN_PASSWORD=password
make deploy

Alternatively, if you are running your mattermost-server out of a sibling directory by the same name, use the deploy target alone to unpack the files into the right directory. You will need to restart your server and manually enable your plugin.

In production, deploy and upload your plugin via the System Console.

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:

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")
}