// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as RepositoriesAPI from './repositories'; import { APIPromise } from '../../core/api-promise'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class Syncs extends APIResource { /** * Creates a new sync operation and returns a signed upload URL for uploading code * bundle * * @example * ```ts * const sync = await client.repositories.syncs.create('id', { * type: 'incremental', * }); * ``` */ create(id: string, params: SyncCreateParams, options?: RequestOptions): APIPromise { const { 'Idempotency-Key': idempotencyKey, ...body } = params; return this._client.post(path`/repositories/${id}/syncs`, { body, ...options, headers: buildHeaders([ { ...(idempotencyKey != null ? { 'Idempotency-Key': idempotencyKey } : undefined) }, options?.headers, ]), }); } /** * Retrieves a sync by its ID * * @example * ```ts * const sync = await client.repositories.syncs.retrieve( * 'sync_id', * { id: 'id' }, * ); * ``` */ retrieve(syncID: string, params: SyncRetrieveParams, options?: RequestOptions): APIPromise { const { id } = params; return this._client.get(path`/repositories/${id}/syncs/${syncID}`, options); } /** * Retrieves a paginated list of syncs for a repository * * @example * ```ts * const syncs = await client.repositories.syncs.list('id'); * ``` */ list( id: string, query: SyncListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get(path`/repositories/${id}/syncs`, { query, ...options }); } } export interface Sync { /** * Unique identifier of the sync */ id?: string; /** * The git reference where the uploaded bundle will be applied. Only used for * incremental syncs. This reference must exist in the already synced repository. */ base_ref?: string | null; /** * Unix timestamp when the sync completed */ completed_at?: number | null; /** * Unix timestamp when the sync was created */ created_at?: number; /** * Error details if status is failed */ error?: Sync.Error | null; /** * Upload format (git bundle file, can be uploaded directly without additional * compression) */ format?: 'bundle'; object?: 'sync'; /** * Repository this sync belongs to */ repository?: string; /** * Size of uploaded file in bytes */ size_bytes?: number | null; /** * Current status of the sync */ status?: 'pending_upload' | 'processing' | 'completed' | 'failed' | 'expired'; /** * Type of sync */ type?: 'full' | 'incremental'; /** * Unix timestamp when the sync was last updated */ updated_at?: number; /** * Unix timestamp when the upload URL expires */ upload_expires_at?: number | null; /** * Signed URL for uploading the code bundle */ upload_url?: string | null; } export namespace Sync { /** * Error details if status is failed */ export interface Error { code?: string; message?: string; } } export interface SyncListResponse extends RepositoriesAPI.PaginatedList { data?: Array; } export interface SyncCreateParams { /** * Body param: Type of sync */ type: 'full' | 'incremental'; /** * Body param: The git reference where the uploaded bundle will be applied. * Required for incremental syncs only. This reference must exist in the already * synced repository. */ base_ref?: string; /** * Header param: Idempotency key for safely retrying operations */ 'Idempotency-Key'?: string; } export interface SyncRetrieveParams { /** * Repository ID (can be internal ID or external:{external_id}) */ id: string; } export interface SyncListParams { /** * Cursor for pagination (object ID) */ after?: string; /** * Cursor for pagination (object ID) */ before?: string; /** * Number of items to return */ limit?: number; /** * Filter by sync status */ status?: 'pending_upload' | 'processing' | 'completed' | 'failed' | 'expired'; /** * Filter by sync type */ type?: 'full' | 'incremental'; } export declare namespace Syncs { export { type Sync as Sync, type SyncListResponse as SyncListResponse, type SyncCreateParams as SyncCreateParams, type SyncRetrieveParams as SyncRetrieveParams, type SyncListParams as SyncListParams, }; }