Hubot with Git Submodules

I love hubot and use one in a few different places. One thing I do find though is that I often want to edit or evolve those plugins, and it seems somehow unethical to just hardcode my changes into my own repo. Once I figured out how to wire together a forked repo as a submodule, it became much easier to work with hubots with external plugins, so I thought I’d share my recipe for that.

Plugins as Submodules

Git submodules can get messy if you’re not totally clear on what is going on. The basic premise is this: there’s a git repo in your subdirectory, and the parent directory will notice if things change in there. You need to remember to commit and push on both the main repo and the submodule and then everything will work! The git-scm reference for this has good examples: so I go there, and I grap the repo URL.

Then, I add it as a submodule. I’ve created a directory called my_modules inside my hubot folder to keep submodules in.

git submodule add my_modules/hubot-github-repo-event-notifier

There are two particular things to notice about this command:

  1. It is run from the top level of the repo, not the subdirectory
  2. It uses the https version of the URL – I usually work with SSH for github, but if you’re going to push to heroku, the https one makes more sense there

Tell Hubot About The Plugin

To get hubot to “see” this plugin, create a symlink in the scripts/ directory that points to the script you want to run in your plugin. My command looks like this:

cd scripts
ln -s ../my_modules/hubot-github-repo-event-notifier/

Now when you run hubot, the plugin should load. You can easily test your hubot locally (without having to commit and push to heroku every time) by running ./bin/hubot from the commandline; this starts hubot with the shell adapter and is really hand for the types of commands where you say something and the bot does something. I have a trick for testing webhooks on my local machine that I’ll share in a separate blog post but the main thing is, any really basic mistakes like syntax errors will become obvious at this point :)

Submodules to Heroku

There isn’t anything special to do here. Make sure that both your main and submodule repositories have changes added, committed and pushed. When you push the main repo to heroku, it knows how to handle the submodules and will plug them in accordingly.

I love that so many of the hubot plugins are packaged via npm but often I want to tweak or evolve them – or even just take advantage of their newest changes without waiting for it to be packaged! The github integration in particular I found was a lot less useful than I expected from any of the plugins I could find, so if you’re using hubot and github and you want to try my version, feel free … the main reason I wanted to work with submodules and hubot is so that I could share what I was working on in case it was useful to anyone else.

3 thoughts on “Hubot with Git Submodules

  1. I stumbled across this post because I wanted to find out a good way to test Hubot webhooks locally. The funny part is that the Hubot script you’re writing about (hubot-github-repo-event-notifier), is the same one I’m modifying and that motivated me to search for this in the first place. :) Small world. I look forward to hearing how you test your webhooks locally.

    • Taylor: That’s funny! Where is your branch? I am happy to share improvements/changes with you from my own.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.