Phabricator webhooks to update composer libraries on Packagist
We’ve been working with Phabricator for well over a year now, and so far I have nothing but praise for the effort Phacility has been making with it. Lately we’ve also started migrating some of our efforts towards composer packages, because, whether we like it or not, Composer is here to stay.
Our approach is currently to avoid external dependencies as much as possible and treat the composer packages as a less obnoxious git submodule (git modules are notoriously hard to move and keep track of when you’re switching branches).
So far we’ve been really happy with the results, and although there’s a learning curve, and there’s some considerations to be made about the whole packagist ecosystem (learn more about those on phacility’s post), our projects are coming along rather nicely.
One issue I had with this approach was the fact that Packagist does not have a straightforward way of integrating with Phabricator, they have instructions for Github and Bitbucket, but it seems Phabricator is a bit too much of a niche product for them.
The first thing we did was set up a Virtualhost on a server so we could receive our Phabricator webhooks and transliterate them into packagist webhooks. For this we used our own deploy script.
Once we had a host ready, we created a hook.php file that would do the transliterating. Download the source for hook.php.
With this done, all we needed is to go to Herald and click on Webhooks and then Create webhook. You can add a custom name and fill in the URL to your hook.php file that you created earlier.
From the top bar, click on Create project and create a project that you name Packagistand select the hashtag #packagist and #composer for it. This is important to make the Phabricator magic work later.
Once you're done creating a webhook, go back to Herald click on Create rule select Commits and Object rule and enter the #packagist hashtag you added earlier. This will cause Phabricator to automaticallly update any packages you have that have the Packagist hashtag.
For the conditions select Any of and Always. Under actions you need to select Webhook and select your newly created webhook. Once you've saved you should be done.
Now, whenever a package tagged with #packagist gets a commit, Packagist will automatically update your repository data.
There's a catch: Phabricator does not trigger commit hooks when you push a tag. This means that when you add a version number to your package it will not be automatically updated. I've reached out to the Phacility staff, since I consider this a bug and I will update this post whenever I get feedback from them.