-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add boilerplate for api, commands, kvstore access and job management #212
base: master
Are you sure you want to change the base?
Conversation
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.
I really appreciate the work you are doing for the starter template. This is a great way for community members to build plugins more easily.
I wonder if we should make the boilerplate code opt-in. Something like a cli tool that generates a fresh repo with all the code that was specified. go templates could drive such a CLI tool.
Go templates is a great suggestion and maybe something we can use in future! I know that too much boilerplate can be annoying but I think this current implementation is easy to manage because most stuff is separated into separate packages and it's just a case of deleting the package and the initialization logic in plugin.go. |
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.
Thanks, @BenCookie95! A few of my inline comments are more exploratory and aren't blocking, but a few high level thoughts I'd love to work through:
- I'm not a big fan of packages for packages sake, e.g.
configuration
. Similarly,command
, and especially the resulting interface just makes navigating the code all that much harder. Could we hoist some of the common code into thepublic
package and make this simple enough to have all the code live in themain
package? - The job manager feels like it comes with a lot of baggage that I'd love to avoid adding to the template. Could we illustrate running an HA-aware job using the existing
cluster
package instead?
router.ServeHTTP(w, r) | ||
} | ||
|
||
func (p *Plugin) MattermostAuthorizationRequired(next http.Handler) http.Handler { |
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.
It would be awesome to hoist this into the public
package.
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.
Yeah that makes sense
const helloCommandTrigger = "hello" | ||
|
||
// Register all your slash commands in the NewCommandHandler function. | ||
func NewCommandHandler(client *pluginapi.Client) Command { |
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.
One day, it would be awesome to hoist this into the public
package and just register callbacks for the slash commands to be handled.
In that future, I wonder if we would need a discrete package at all and could just do this all in command.go
?
server/command/command.go
Outdated
AutoComplete: true, | ||
AutoCompleteDesc: "Say hello to someone", | ||
AutoCompleteHint: "<username>", |
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.
I wonder if we should illustrate the advanced autocomplete functionality?
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.
What is that advanced functionality? I'm not aware, is there something I can read?
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.
Take a peek at https://github.com/mattermost/mattermost-plugin-playbooks/blob/6c50600fb6151ea1abfed82961e980131b0ca2ab/server/command/command.go#L61 (ironically in an unnecessary command
package itself ;P)
👍 to just having code vs. generating. That being said, as noted above, I'm not a huge fan of packages achieve this, so hopefully we can find a middle ground where it's still easy to remove but doesn't come with lots of cognitive overhead in the way the plugin is structured. |
My main thought process of creating separate packages from the start was to discourage the overuse of the I agree that I could move the config back into the main package because it doesn't serve much use as it's own package (probably went overboard with that one). Command in it's current state made sense to be in a separate package because there is a fair amount of boilerplate to work through. I'll take a look at hoisting some of that to the public package and then it would probably make sense to move it back to main?
Yeah, my initial thoughts were from a DE perspective because this was reused in a few plugins but it's overkill for a contributor coming in. I'll simplify it. Demo plugin already has a simple use of the cluster package that I will re-use |
Resolved most of the comments. Removed the config package and cleared out the overly complicated Job stuff |
@BenCookie95, for context, I recently went through an exercise in MS Teams collapsing many of the packages back into the On the "when" side for new packages, I was chatting with @crspeller and wrote down a few shared thoughts:
Curious as to your thoughts? |
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.
Thanks @BenCookie95! One comment about the commented code, but otherwise non-blocking.
server/command/command.go
Outdated
AutoComplete: true, | ||
AutoCompleteDesc: "Say hello to someone", | ||
AutoCompleteHint: "<username>", |
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.
Take a peek at https://github.com/mattermost/mattermost-plugin-playbooks/blob/6c50600fb6151ea1abfed82961e980131b0ca2ab/server/command/command.go#L61 (ironically in an unnecessary command
package itself ;P)
I'm happy with that criteria you laid out and I think I'll add it to the README of this plugin so contributors have some guidance. Thanks!
I can see how that can be painful if overused |
|
||
This is a central place for you to access the KVStore methods that are available in the `pluginapi.Client`. The package contains an interface for you to define your methods that will wrap the KVStore methods. An instance of the KVStore is created in the `OnActivate` hook. | ||
|
||
#### Jobs package |
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.
Not a package anymore.
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.
LGTM 👍 One change needed to readme.
Summary
Problem:
The starter template is too bare bones to kickstart most plugin efforts, requiring a lot of copy and paste from “known good” plugins to achieve a stable starting point.
Justification:
DE doesn’t use the starter template all that often anymore, spending extra time bootstrapping a plugin with all the necessary plumbing. This also leads to unnecessary divergences between plugins, complicating our developer integration strategy and story.
I added some skeleton code for creating an api and adding new slash commands. I separated the slash commands and KVStore access into their own packages for ease of use. I also added a simple mock for the command package to show how these separate packages can be easily tested.
I noticed we used this Job Manager code across a few different plugins and I thought it would be very useful to bring into the skeleton.
Ticket Link
https://mattermost.atlassian.net/browse/MM-61468
https://mattermost.atlassian.net/browse/MM-60911
https://mattermost.atlassian.net/browse/MM-60910
https://mattermost.atlassian.net/browse/MM-60909