Skip to content

Pull Request Sync Capability

PullRequestSyncCapability is the contract base for a capability that ingests a project's pull-request history into ClickHouse. Bind it with a Capability(kind='pr-sync', handler=...) in the plugin's manifest.

The host addresses this capability directly (manual sync endpoints, availability checks) and permissions it independently (project:pull-requests:write). Incremental sync from inbound webhook deliveries still flows through the plugin's webhook-actions catalog.

Surfaces: api, webhook.

See Authoring Plugins for the manifest, capabilities, context, credential decryption, and error conventions shared by every plugin.

from imbi.common.plugins import (
    PluginContext,
    PullRequestSyncCapability,
)


class GitHubPullRequestSync(PullRequestSyncCapability):
    async def sync_all_history(
        self,
        *,
        ctx: PluginContext,
        credentials: dict[str, str],
    ) -> int:
        ...

    async def check_available(
        self,
        *,
        ctx: PluginContext,
        credentials: dict[str, str],
    ) -> bool:
        ...

Method contracts

  • sync_all_history (required) — record the project's full pull-request history. Host-invoked with no webhook payload; both arguments are keyword-only. Returns the number of PRs recorded. Re-running is safe: the ClickHouse pull_requests table is ReplacingMergeTree.
  • check_available (optional, default True) — whether an on-demand sync can run for ctx right now. Override to report False when the remote / repository cannot be resolved. Both arguments are keyword-only.

Hints

  • cacheable — the host may cache reads from this capability.

API reference

PullRequestSyncCapability

Bases: CapabilityHandler

Ingest a project's pull-request history into ClickHouse.

Addressed directly by the host (manual sync endpoints, availability checks) and independently permissioned (project:pull-requests:write). The gateway-side webhook delivery still flows through the plugin's webhook-actions catalog.

check_available async

check_available(
    *, ctx: PluginContext, credentials: dict[str, str]
) -> bool

Whether an on-demand sync can run for ctx right now.

Default True; override to report False when the remote / repository can't be resolved.

Source code in libraries/common/src/imbi/common/plugins/base.py
async def check_available(
    self,
    *,
    ctx: PluginContext,
    credentials: dict[str, str],
) -> bool:
    """Whether an on-demand sync can run for ``ctx`` right now.

    Default ``True``; override to report ``False`` when the remote /
    repository can't be resolved.
    """
    del ctx, credentials
    return True

sync_all_history abstractmethod async

sync_all_history(
    *, ctx: PluginContext, credentials: dict[str, str]
) -> int

Record the project's full pull-request history.

Host-invoked (no webhook payload). Returns the number of PRs recorded. Re-running is safe: the ClickHouse pull_requests table is ReplacingMergeTree.

Source code in libraries/common/src/imbi/common/plugins/base.py
@abc.abstractmethod
async def sync_all_history(
    self,
    *,
    ctx: PluginContext,
    credentials: dict[str, str],
) -> int:
    """Record the project's full pull-request history.

    Host-invoked (no webhook payload). Returns the number of PRs
    recorded. Re-running is safe: the ClickHouse ``pull_requests``
    table is ``ReplacingMergeTree``.
    """