-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
New Script Pattern #873
Comments
I like the idea and the doors it opens for testability. Also enjoy the idea of having config information declared very explicitly in here. Looking at it some more though, it feels "too complex" for a simple script that you may want to have for easy interactions with some REST API. Given the examples in your test snippet, what's explicitly required in the class to make sure a script is structured properly and can be loaded? Is there some sort of error checking to be done on each script class that gets loaded in? |
cc #249 for a slightly different take |
We're going to use Hubot Evolution |
I had a crazy pipe dream idea for a new script format that I think will still be backwards-compatible, be fairly powerful, and not require programmatic launching (#858). There is a lot in this example, so I've added lots of comments and will go through each piece. In short, it probably works as you would expect it to.
First, we now use a class instead of just a function. This makes it easy and obvious for adding helper methods that are accessible by unit tests. This would require a one-line change to
loadFile
, but I'm pretty sure this would be backwards compatible with existing scripts.Second, metadata about the script is specified as properties. This allows easy access at any time to any of the properties of a script and could enable magic extensions (like automated integration tests).
Routes are enumerated so you can directly access the handler for any given listener for unit testing. Help information is now associated with the listener and is accessible without needing to parse comments.
The
HubotScript
parent class would take care of doing all "new script" actions (like registering routes and validating config/dependencies), so we just need to haveloadFile
usenew
instead of calling the result ofrequire
directly.Moving to a more data-driven script model might also make hot reloading easier (#715) because we could have a clear list of everything the script has added to the global Robot context (would need to block monkey patches).
I'm still stewing on this (particularly the idea of async route definition), but I think this is a pretty clean foundation that will require a one line code change (and approximately a million lines of documentation changes plus updates to the generator).
The text was updated successfully, but these errors were encountered: