Skip to content

Implement GitlabMergeRequestSource task source #1182

@geoffjay

Description

@geoffjay

Summary

Implement the GitlabMergeRequestSource struct that fetches GitLab merge requests via the REST API v4, converting them to Task objects with MR-specific metadata (source branch, target branch, merge status).

Context

The scaffolding from the foundation issue provides GitlabConfig (auth/URL), the TriggerConfig::GitlabMergeRequests variant, and stub TaskSource implementation. This issue replaces the stub with real API calls.

GitLab REST API v4 endpoint: GET /api/v4/projects/:id/merge_requests

  • Project identified by owner%2Frepo (URL-encoded namespace/project)
  • Supports query params: labels, state, assignee_id (requires user lookup)
  • Returns JSON array of MR objects with branch info
  • Pagination via per_page and page params

Acceptance Criteria

  • GitlabMergeRequestSource::fetch_tasks() makes authenticated HTTP GET to GitLab API
  • URL construction: {base_url}/api/v4/projects/{owner}%2F{repo}/merge_requests
  • Query parameters applied:
    • state (default: opened)
    • labels (comma-separated)
    • assignee_username (when assignees field is set, query once per assignee or use appropriate API filter)
    • per_page=100 for efficient batching
  • Pagination handled: fetch all pages until no more results
  • Response deserialized into internal structs, mapped to Task:
    • source_id = MR iid (project-scoped MR number)
    • title = MR title
    • body = MR description
    • url = MR web_url
    • labels = MR labels array
    • assignee = first assignee's username
    • metadata: gitlab_project_id, gitlab_iid, source_branch, target_branch, merge_status, draft (boolean), state
  • Authentication via PRIVATE-TOKEN header with resolved token
  • Error handling: non-2xx responses logged at warn level with status code
  • source_type() returns "gitlab_merge_requests"

GitLab API Response Shape (relevant fields)

{
  "iid": 15,
  "title": "Add new feature",
  "description": "This MR adds...",
  "web_url": "https://gitlab.com/myorg/myrepo/-/merge_requests/15",
  "state": "opened",
  "labels": ["enhancement"],
  "assignees": [{"username": "bob"}],
  "source_branch": "feature/new-thing",
  "target_branch": "main",
  "merge_status": "can_be_merged",
  "draft": false,
  "project_id": 12345
}

Key Files

  • crates/orchestrator/src/scheduler/gitlab.rs - main implementation

Blocked By

  • The GitLab scaffolding issue (config and type variants must exist)

Stack Base

Branch off: feature/autonomous-pipeline
Blocked by: #1180

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions