This script helps manage GitLab webhooks for Axolo by ensuring that the webhook is active and functioning. If Axolo times out on a webhook that GitLab sends, GitLab may stop sending webhooks altogether. This script checks for failed webhooks and revives them if needed.
Axolo can sometimes time out on a webhook GitLab sends. If that happens, GitLab will stop sending webhooks altogether. This script helps in reviving the webhook if it sees that it has failed.
- Fetch all group-level webhooks from GitLab.
- Filter out the webhooks that match the Axolo URL (
https://api.axolo.co/gitlab/listen
). - For each matching webhook, check if it is valid by making a GET request to the GitLab API.
- If a webhook is invalid, delete the existing one and create a new webhook with the appropriate configuration.
- If no valid hooks are found, a new one will be created.
You will need an Owner Group Access Token from GitLab. This token should have sufficient permissions to manage webhooks at the group level. Follow these steps to create one:
- Go to your GitLab group settings.
- Navigate to Access Tokens.
- Create a new token with the required scopes (e.g.,
api
,write_repository
). - Replace
ACCESS_TOKEN
in the script with your generated token.
To ensure this script runs regularly and helps maintain the webhooks, follow these steps:
- Schedule the Script: Run this script every 30 minutes using a cron job, GitHub Actions, or another scheduling tool.
- Monitor for Failures: Set up monitoring to notify you if the script fails. You can log the output to a file or use a notification service.
- Replace Group ID: Update the
GROUP_ID
in the script with your actual GitLab group ID. - Set Access Token: Replace the
ACCESS_TOKEN
with your GitLab Owner Group Access Token.
node manageHooks.js