A Drupal 7 module that hooks into the project-create event and automatically provisions a private Bitbucket repository with the agency workflow already enforced: branch protection, approval rules, push restrictions, and PR webhooks.
Case study: 5am.dev/work/drupal-bitbucket
When a PM creates a "site" content type node in the Drupal intranet, the module:
- Authenticates against Bitbucket using OAuth2 client credentials (no service-user impersonation, no personal access tokens).
- Slugifies the project title and creates a private repository.
- Adds a PR webhook back to the intranet bot, subscribing to every relevant pull-request event.
- Creates three standard branches:
master,staging,develop. - Applies branch restrictions:
- Push-restricted to the admin group only
- Two approvals required for any merge to
masterorstaging - Delete-protected so nobody can wipe a main branch by accident
- Per-group merge permissions (developer, junior, reviewer)
The headline outcome: junior developers stopped occasionally landing in production by accident — not because they got better at the rules, but because the rules were finally in the path.
PHP · Drupal 7 · Bitbucket REST API v2 · OAuth2 (client credentials) · Symfony Dotenv · php-curl-class
composer installCopy .env.example to .env and fill in:
CLIENT_ID,CLIENT_SECRET— your Bitbucket OAuth app credentialsUSER— the Bitbucket workspaceADMINISTER_GROUP,DEVELOPER_GROUP,JUNIOR_GROUP,REVIEWER_GROUP— group slugsAUTH— shared secret for the webhook callback
Enable the module in Drupal at admin/modules.
Drupal 7 reached end-of-life in January 2025, so this module is preserved as a portfolio artifact. The pattern (encode the workflow, hook it into project creation, never trust a human to remember) would translate cleanly to a GitHub Actions workflow or a small webhook receiver in front of any modern repo host.