A lightweight Python application that monitors GitHub repositories for new commits and triggers Argo Events when changes are detected. This tool is designed for GitOps workflows and CI/CD pipelines that need to react to repository changes.
- 🔍 Repository Monitoring: Polls GitHub API to check for new commits
- 🔄 State Persistence: Tracks the last seen commit to avoid duplicate notifications
- 🚀 Argo Events Integration: Triggers Argo Events endpoints when new commits are detected
- 🐳 Containerized: Ready-to-use Docker image
- ⚙️ Configurable: Environment-based configuration for flexibility
docker run -d \
--name github-poller \
-e GITHUB_API_URL="https://api.github.com/repos/username/repo-name/commits" \
-e GITHUB_TOKEN="your_github_token" \
-e ARGO_EVENT_SOURCE_URL="http://argo-events-webhook:12000/github-poller" \
-v /path/to/data:/data \
alyvusal/github-pollerversion: '3.8'
services:
github-poller:
image: alyvusal/github-poller
environment:
- GITHUB_API_URL=https://api.github.com/repos/username/repo-name/commits
- GITHUB_TOKEN=${GITHUB_TOKEN}
- ARGO_EVENT_SOURCE_URL=http://argo-events-webhook:12000/github-poller
- LAST_COMMIT_FILE=/data/last_commit.txt
volumes:
- ./data:/data
restart: unless-stopped| Variable | Required | Default | Description |
|---|---|---|---|
GITHUB_API_URL |
✅ | - | GitHub API endpoint for commits (e.g., https://api.github.com/repos/username/repo-name/commits) |
GITHUB_TOKEN |
✅ | - | GitHub personal access token or OAuth token |
ARGO_EVENT_SOURCE_URL |
✅ | - | Argo Events webhook endpoint URL |
LAST_COMMIT_FILE |
❌ | /data/last_commit.txt |
Path to file storing the last seen commit SHA |
- Go to GitHub Settings → Developer settings → Personal access tokens
- Generate a new token with
reposcope (for private repos) orpublic_repo(for public repos) - Use the token as
GITHUB_TOKENenvironment variable
The application sends a POST request to the specified Argo Events endpoint with the following payload:
{
"event": "new_commit"
}# Set environment variables
export GITHUB_API_URL="https://api.github.com/repos/myorg/myapp/commits"
export GITHUB_TOKEN="ghp_your_token_here"
export ARGO_EVENT_SOURCE_URL="http://argo-events-webhook:12000/github-poller"
# Run the container
docker run --rm \
-e GITHUB_API_URL \
-e GITHUB_TOKEN \
-e ARGO_EVENT_SOURCE_URL \
-v $(pwd)/data:/data \
alyvusal/github-pollerapiVersion: apps/v1
kind: Deployment
metadata:
name: github-poller
spec:
replicas: 1
selector:
matchLabels:
app: github-poller
template:
metadata:
labels:
app: github-poller
spec:
containers:
- name: github-poller
image: alyvusal/github-poller
env:
- name: GITHUB_API_URL
value: "https://api.github.com/repos/username/repo-name/commits"
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: github-token-secret
key: token
- name: ARGO_EVENT_SOURCE_URL
value: "http://argo-events-webhook:12000/github-poller"
- name: LAST_COMMIT_FILE
value: "/data/last_commit.txt"
volumeMounts:
- name: data-volume
mountPath: /data
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: github-poller-pvc# Clone the repository
git clone <repository-url>
cd github-poller
# Install dependencies
pip install requests
# Set environment variables
export GITHUB_API_URL="https://api.github.com/repos/username/repo-name/commits"
export GITHUB_TOKEN="your_token"
export ARGO_EVENT_SOURCE_URL="http://localhost:12000/github-poller"
# Run the application
python poller.pydocker build -t github-poller .The application follows a simple polling pattern:
- Fetch Latest Commit: Queries GitHub API for the most recent commit
- Compare with Previous: Checks against the last known commit SHA
- Trigger Event: If a new commit is detected, triggers Argo Events
- Update State: Stores the new commit SHA for future comparisons
Error: "Error fetching commits: 401"
- Check that your
GITHUB_TOKENis valid and has the correct permissions - Ensure the repository URL is correct
Error: "Failed to trigger Argo event: 404"
- Verify the
ARGO_EVENT_SOURCE_URLis correct - Ensure the Argo Events webhook is properly configured
No new commits detected
- Check the
LAST_COMMIT_FILEto see the last processed commit - Verify the GitHub API URL points to the correct repository
The application provides basic logging:
New commit detected: <sha>- When a new commit is foundNo new commits detected.- When no changes are detectedSuccessfully triggered Argo event.- When Argo Events is notified- Error messages for API failures
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
The image is available on Docker Hub: alyvusal/github-poller