Assign Me Openclaw (Works with SHSF)

This project is a serverless function (designed for SHSF) that handles Gitea webhooks for issue and pull request assignments and comments. It notifies an AI agent (via OpenClaw) when they are assigned, unassigned, or mentioned in a comment. 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 & Mention Logic: Specifically identifies when the configured AGENT_USERNAME is involved in an assignment change or mentioned in a comment (e.g., @youragent).
  • Comment Notifications: Notifies the agent about new comments on issues or PRs they are assigned to, or when they are tagged.

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.
OPENCLAW_THINKING (Optional) The thinking effort for the agent (e.g., low, medium, high). Defaults to low.
DATABASE_STORAGE_NAME The name of the database storage to use.
AGENT_USERNAME The Gitea username of the AI agent (e.g., whateveryouragentisnamed).
AGENT_PROMPT_FILE (Optional) Path to a custom Markdown template for notifications. If not provided, a default template will be used.
AGENT_HOURLY (Optional) Maximum number of triggers allowed per hour. Defaults to 60. Used for rate limiting.

How it works

  1. Webhook Reception: The main(args) function receives a POST request from Gitea.
  2. Event Filtering: It filters for issues, pull_request, and issue_comment events.
  3. Database Lookups: If an unassigned or issue_comment event lacks assignee data in the payload, the script retrieves the last known assignees from the database.
  4. Agent Notification: If the configured AGENT_USERNAME is found in the assignee list or is mentioned (case-insensitive) in a comment, 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.

Webhook Pointers

Ensure you Webhook is pointed from YOUR and YOUR AGENTS Gitea account to the Function, or have an Gitea Wide Webhook pointed to your Function, the code will filter events that don't belong to your agent.

Webhook Event Checklist

To use all features, ensure your Gitea webhook is configured to send:

  • Issues (Assignment changes)
  • Pull Request (Assignment changes)
  • Issue Comment (Created) - Note: Gitea sends both Issue and PR comments as issue_comment events.
  • Pull Request Comment (Created) - Note: Handled as issue_comment events in Gitea.

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.

Description
Assign your agent and have it get instant notifications via SHSF and Gitea Webhooks
Readme 104 KiB
Languages
Python 100%