Add initial implementation of serverless function for Gitea webhook handling
All checks were successful
Lint and Syntax Check / build (push) Successful in 7s

This commit is contained in:
Space-Banane
2026-04-02 15:45:11 +02:00
commit 694c674581
4 changed files with 372 additions and 0 deletions

41
README.md Normal file
View File

@@ -0,0 +1,41 @@
# Assign Me Openclaw (<a href="https://github.com/Space-Banane/shsf"><img src="https://github.com/Space-Banane/Space-Banane/blob/main/WORKS%20WITH%20SHSF%20-%20WHITE%20TEXT.png?raw=true" height="30" alt="Works with SHSF" style="vertical-align: middle;"></a>)
This project is a serverless function (designed for SHSF) that handles Gitea webhooks for issue and pull request assignments. It notifies an AI agent (via OpenClaw) when they are assigned or unassigned, even if the unassignment event lacks assignee data. The function uses a database to track assignees across events, ensuring accurate notifications.
## Features
- **Multiple Assignee Support**: Correctly handles Gitea events with multiple assignees.
- **State Persistence**: Uses a database to track assignees across events, ensuring "unassigned" events have the necessary context even when the payload is sparse.
- **AI Integration**: Sends formatted Markdown notifications to an OpenClaw-compatible API.
- **Assignment Logic**: Specifically identifies when the configured `AGENT_USERNAME` is involved in an assignment change.
## Environment Variables
The following environment variables are required for the service to function:
| Variable | Description |
| :--- | :--- |
| `OPENCLAW_URL` | The endpoint URL for the OpenClaw API. (with hook path) |
| `OPENCLAW_TOKEN` | The authentication token for OpenClaw. (from hooks, not gateway ui) |
| `OPENCLAW_PROXY_AUTH` | (Optional) Proxy credentials in `username:password` format. |
| `DATABASE_STORAGE_NAME` | The name of the database storage to use. |
| `AGENT_USERNAME` | The Gitea username of the AI agent (e.g., `whateveryouragentisnamed`). |
## How it works
1. **Webhook Reception**: The `main(args)` function receives a POST request from Gitea.
2. **Event Filtering**: It filters for `issues` and `pull_request` events with `assigned` or `unassigned` actions.
3. **Database Lookups**: If an `unassigned` event lacks assignee data, the script retrieves the last known assignees from the database.
4. **Agent Notification**: If the configured `AGENT_USERNAME` is found in the assignee list, a detailed Markdown message is constructed and sent to OpenClaw.
5. **Database Sync**: The current state of assignees for the specific issue/PR is updated in the database for future reference.
## Development
The project consists of:
- `main.py`: The entry point and logic for the webhook handler.
- `_db_com.py`: (Internal dependency at SHSF Runner level) Database communication module.
- `requirements.txt`: Python dependencies.
## Usage in SHSF
This script is intended to be deployed as a serverless function using SHSF. Ensure that all required environment variables are set in your Function.