developmentseed / jekyll-hook

No Longer Maintained | A server that listens for GitHub webhook posts and renders a Jekyll site
BSD 3-Clause "New" or "Revised" License
508 stars 83 forks source link

Feature/branch scripts #24

Closed olafveerman closed 9 years ago

olafveerman commented 9 years ago

First of all, great tool. We've been using it and are pretty happy with it.

This PR makes it possible to call different build and publish scripts based on which branch is firing the webhook. One of the use cases would be to build and publish a develop branch to a staging environment with simple authentication, while master would trigger a build and publish to a production environment.

The other commit makes it possible to use Jekyll Hook with branch names with a slash in them, like feature/pretty_map.

scisco commented 9 years ago

@danielfdsilva @olafveerman Great addition. Thank you for working this. I ran a few tests myself and it worked perfectly.

Sorry for the delay in acting on this. Merging the request now.

phillipadsmith commented 8 years ago

@olafveerman Do you know if it's still possible to make this work?

I think I've got it working (somehow) using a master and develop branch and two webhooks on one project, but I'm failing to grok how to get it set up with three branches on another project.

And, now that I look at it more closely, I'm not even sure how it would work because -- as far as I can tell -- there's no way to set-up a branch-specific Webhook from GitHub. Thus, for a push to branch Z, GitHub is sending three identical hooks for X, Y, and Z and jekyll-hook.js appears to just deal with the first, and then reports Not Z branch because the hook being processed is the first in the list of hook, which is something like http://domain.com/hooks/jekyll/develop.

Any thoughts / help appreciated. Feel like I'm missing something here.

phillipadsmith commented 8 years ago

@scisco @olafveerman I'm failing to see how this could work as described, nor why it's even necessary.

Would it not make more sense to simply use one Webhook and then check data.branch against the defined values for scripts in the config, e.g., something like:

        if ( typeof config.scripts[data.branch] === 'undefined'  ) {
            console.log('No build script defined for ' + data.branch);
            if (typeof cb === 'function') cb();
            return;
        }

As far as I can tell, that would eliminate the need to set-up more than one Webhook, as well as moving the "should jekyll-hook do something with this push" logic into the configuration file.

Thoughts? If that makes sense, I'll send a PR for what I've got working here: working for n branches, just based on a single hook and a config value for scripts.

Update: this doesn't take into account a #default script property, however. Not sure if that's needed, or if it would make more sense to just ask the user to define what to run against each branch, i.e., master, gh-pages, develop and so on?

Update: more sensible undefined check.

phillipadsmith commented 8 years ago

Bump @scisco @parkr https://github.com/developmentseed/jekyll-hook/pull/24#issuecomment-158209663