Patch WordPress via GitHub

A few days ago, I started tweeting about the Stack Overflow Developer Survey, where 74% of developers surveyed said they dread working with WordPress. I received a tonne of replies that I’m still working through, and I’ll post about that soon.

One reply that did come up a few times was contributing via GitHub. Matt announced in the State of the Word that you’d soon be able to contribute to WP via pull requests, however that hasn’t happened so far. I had a few discussions with some of the core team about this, but alas it never got anywhere.

However, after this discussion, I realised I could do something about it right now as a proof-of-concept. Trac exposes an XML-RPC interface, and GitHub exposes a REST API, so hooking the two up only requires a minimal amount of code.

So, introducing GitHub-to-Patch, a tiny utility to allow submitting PRs to WordPress.

Here’s how you submit a pull request for WordPress using this:

  1. Find the ticket on Trac you want to upload a patch to.
  2. Submit a pull request to the WordPress/WordPress repo, then close it to keep GitHub clean. (You can still continue to update it.)
  3. Head to the GitHub-to-Patch page.
  4. Select your pull request.
  5. Enter the ticket number.
  6. Enter your Trac/WordPress.org username and password.
  7. Preview the patch you’re about to submit and verify the details.
  8. Done! You should also leave a comment about the patch you just added. 🙂

If you update your PR and want to upload your changes, simply repeat the same process; Trac will automatically name the patches correctly to avoid overwriting previous ones.

Internally, the utility uses GitHub’s API to get a patch format of the pull request, then uses Trac’s XML-RPC API to upload. This requires your WordPress.org credentials, and because of cross-origin policy, also requires an intermediary server. 🙁 I hope to fix this in the future, either by integrating the tool into Trac itself, or by using OAuth with WordPress.org. In the meantime, if you don’t trust my server, you can install and run the tool from GitHub with minimal effort.

In the future, I’ll likely create a PR bot to automatically close PRs and point users to the tool, and to note when people have uploaded their PR as a patch.

Thanks to Eric Andrew Lewis for his pull request to the grunt-patch-wordpress repo that made me realise I could do this. 🙂

One thought on “Patch WordPress via GitHub

  1. I worked on something along these lines that handles one-way sync of PRs over to Trac, along with updated patches with new commits on the PR, as well as any comments from anyone about a year ago. It’s done as an additional feature on the “trac-github” Trac plugin, so it only requires the Trac server itself, and manually configuring a webhook on the GitHub repo(s) in question:
    https://github.com/trac-hacks/trac-github/compare/master…tierra:issue-sync

    Also see: https://github.com/trac-hacks/trac-github/issues/75

    But it’s still just one-way like yours, and doesn’t sync Trac comments back to the GitHub pull request, so it’s still lacking in some core functionality that would be nice to have (but difficult to pull off cleanly since it would require a GitHub user account to post on behalf of).

    Also, on the subject of a bot that automatically closes PRs, I also implemented that once already too in this simple job you can just add to cron (but try to avoid running it more than maybe a couple times a day – sometimes the GitHub API search query for open PRs returns cached results, so you’ll get multiple comments on PRs):
    https://gist.github.com/tierra/c65c39eb575741bf36fc

    Enjoy!

Leave a Reply