Implementation:OpenHands OpenHands GitlabView
| Knowledge Sources | |
|---|---|
| Domains | Platform_Integration, GitLab |
| Last Updated | 2026-02-11 21:00 GMT |
Overview
View hierarchy and factory for parsing GitLab webhook payloads into conversation-creating view objects.
Description
The GitLab view module defines a class hierarchy (GitlabIssue, GitlabIssueComment, GitlabMRComment, GitlabInlineMRComment) that each handle a specific webhook event type. The GitlabFactory creates the appropriate view from raw webhook payloads. Each view loads resolver context from the GitLab API, renders Jinja2 instruction templates, and creates OpenHands conversations with the appropriate trigger metadata.
Usage
Use these classes when processing incoming GitLab webhook events that need to create or update OpenHands conversations. The factory pattern automatically selects the correct view type based on the payload structure.
Code Reference
Source Location
- Repository: OpenHands
- File: enterprise/integrations/gitlab/gitlab_view.py
- Lines: 1-451
Signature
@dataclass
class GitlabIssue:
issue_number: str
project_id: str
title: str
description: str
previous_comments: list
is_mr: bool
# ... additional fields
async def _load_resolver_context(self) -> None: ...
async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]: ...
async def create_new_conversation(self, jinja_env, git_provider_tokens) -> str: ...
class GitlabFactory:
@staticmethod
def create_view(payload: dict, user_info: UserData, ...) -> GitlabIssue: ...
Import
from enterprise.integrations.gitlab.gitlab_view import GitlabFactory, GitlabIssue
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| payload | dict | Yes | Raw GitLab webhook JSON payload |
| user_info | UserData | Yes | Keycloak user data |
| installation_id | str | Yes | Webhook ID from database |
| project_id | str | Yes | GitLab project identifier |
| jinja_env | Environment | Yes | Jinja2 template environment |
Outputs
| Name | Type | Description |
|---|---|---|
| create_new_conversation() | str | Conversation ID of created conversation |
| _get_instructions() | tuple[str, str] | User instructions and conversation instructions |
Usage Examples
from enterprise.integrations.gitlab.gitlab_view import GitlabFactory
# Create view from webhook payload
view = GitlabFactory.create_view(
payload=webhook_json,
user_info=user_data,
installation_id="webhook-123",
project_id="456",
full_repo_name="org/repo",
)
# Load context and create conversation
await view._load_resolver_context()
conversation_id = await view.create_new_conversation(jinja_env, git_tokens)