This GitHub App automatically fixes commit messages by removing "add " or "Add " prefixes when pushes are made to configured repositories. It listens for push events via webhooks, clones the repository, rewrites the commit history to clean up messages, and force pushes the changes back, ensuring consistent and clean commit logs without manual intervention.
To set up the app, start by creating a new GitHub App in your GitHub Settings under Developer settings > GitHub Apps. Click "New GitHub App" and fill in the details: set the GitHub App name to "Fix", provide a homepage URL like https://github.com/yourusername/fix-app (or any placeholder URL), enter the webhook URL pointing to your deployed app's endpoint (e.g., https://your-server.com/webhook), and generate a random webhook secret using a command like openssl rand -hex 20. Under permissions, grant Repository contents read and write access, and Repository metadata read-only access. Subscribe to the Push event to trigger the app on commits. After saving, download the private key from the app settings and save it securely to a file, such as private-key.pem.
Next, install the app on your desired repository or organization. Then, set the required environment variables: GITHUB_APP_ID with your app's ID, GITHUB_PRIVATE_KEY with the content of the private key file (paste the entire PEM content), and GITHUB_WEBHOOK_SECRET with the webhook secret you generated. Run the app locally with python github_app.py for testing, or deploy it to a production server like Render, Heroku, or AWS, updating the webhook URL accordingly to ensure it's publicly accessible.
The app operates by receiving push webhooks from GitHub. When a push is made to a repository where the app is installed, GitHub sends a webhook payload to your deployed app endpoint. The app then generates an installation access token using the installation ID from the webhook, clones the repository using that token for authentication, checks out the affected branch, and identifies commits unique to it (relative to the default branch). It then modifies commit messages in these unique commits by removing " add ", " Add ", leading "add ", or leading "Add " phrases. Finally, it pushes the rewritten history back to the branch using --force-with-lease, skipping the repository's default branch and actions if the push originated from a bot to prevent infinite loops.
The app requires Python 3.8 or later, along with the Flask, PyGitHub, and github-webhook libraries. Install these dependencies using pip install -r requirements.txt.
To deploy on Render.com:
- Push this code to a GitHub repository.
- Sign up for Render and connect your GitHub account.
- Create a new Web Service from your repo.
- Set the following:
- Environment: Python 3
- Build Command:
pip install -r requirements.txt - Start Command:
python github_app.py
- Add environment variables in Render's dashboard:
GITHUB_APP_ID: Your GitHub App IDGITHUB_PRIVATE_KEY: The full content of your private key (PEM format)GITHUB_WEBHOOK_SECRET: Your webhook secret
- Deploy and note the service URL (e.g.,
https://your-app.onrender.com). - Update your GitHub App's webhook URL to
https://your-app.onrender.com/webhook.