// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as AnalysisAPI from '../analysis'; import * as SyncsAPI from './syncs'; import { Sync, SyncCreateParams, SyncListParams, SyncListResponse, SyncRetrieveParams, Syncs } from './syncs'; 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 Repositories extends APIResource { syncs: SyncsAPI.Syncs = new SyncsAPI.Syncs(this._client); /** * Creates a new repository for code analysis * * @example * ```ts * const repository = await client.repositories.create({ * name: 'backend-api', * }); * ``` */ create(params: RepositoryCreateParams, options?: RequestOptions): APIPromise { const { 'Idempotency-Key': idempotencyKey, ...body } = params; return this._client.post('/repositories', { body, ...options, headers: buildHeaders([ { ...(idempotencyKey != null ? { 'Idempotency-Key': idempotencyKey } : undefined) }, options?.headers, ]), }); } /** * Retrieves a repository by its ID or external ID * * @example * ```ts * const repository = await client.repositories.retrieve('id'); * ``` */ retrieve(id: string, options?: RequestOptions): APIPromise { return this._client.get(path`/repositories/${id}`, options); } /** * Updates a repository by its ID or external ID * * @example * ```ts * const repository = await client.repositories.update('id'); * ``` */ update(id: string, body: RepositoryUpdateParams, options?: RequestOptions): APIPromise { return this._client.patch(path`/repositories/${id}`, { body, ...options }); } /** * Retrieves a paginated list of repositories in your workspace * * @example * ```ts * const repositories = await client.repositories.list(); * ``` */ list( query: RepositoryListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get('/repositories', { query, ...options }); } /** * Permanently deletes a repository and all associated data * * @example * ```ts * await client.repositories.delete('id'); * ``` */ delete(id: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/repositories/${id}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), }); } } export interface PaginatedList { /** * Array of response elements */ data?: Array; /** * True if there are more elements */ has_more?: boolean; object?: 'list'; /** * URL for accessing this list */ url?: string; } export interface Repository { /** * Unique identifier of the repository */ id?: string; /** * Whether the repository is archived */ archived?: boolean; /** * Unix timestamp when the repository was created */ created_at?: number; /** * Types of analysis to perform */ detection?: Array<'security' | 'secrets' | 'dependencies'>; /** * Glob patterns of files and folders to ignore */ exclude_patterns?: Array; /** * Repository's identifier in your system */ external_id?: string; /** * Total number of files */ file_count?: number; /** * Types of issues to fix */ fix?: Array<'security' | 'secrets' | 'dependencies'>; /** * Git commit hash, branch, or tag representing the current state of the * repository. This is automatically updated to the last seen ref from successful * sync operations. */ git_ref?: string | null; /** * Programming languages to analyze */ languages?: Array; /** * Unix timestamp of the last successful sync operation (null if no syncs have * completed) */ last_synced_at?: number | null; /** * Repository name */ name?: string; object?: 'repository'; /** * Total uploaded size in bytes */ size_bytes?: number; /** * Glob patterns of test files and folders */ test_patterns?: Array; /** * Unix timestamp when the repository was last modified */ updated_at?: number; /** * Workspace this repository belongs to */ workspace?: string; } export interface RepositoryListResponse extends PaginatedList { data?: Array; } export interface RepositoryCreateParams { /** * Body param: Repository's display name */ name: string; /** * Body param: Whether the repository is archived. We'll return a validation error * if an analysis is requested on an archived repository. */ archived?: boolean; /** * Body param: Controls what kind of analysis should be performed. Can be overriden * per analysis request. */ detection?: Array<'security' | 'secrets' | 'dependencies'>; /** * Body param: Glob patterns of files and folders to ignore */ exclude_patterns?: Array; /** * Body param: Repository's identifier in your system */ external_id?: string; /** * Body param: Controls which issues are fixed (defaults to same as detection). Can * be overriden per analysis request. */ fix?: Array<'security' | 'secrets' | 'dependencies'>; /** * Body param: Programming languages to analyze (auto-detected if not provided) */ languages?: Array; /** * Body param: Glob patterns of test files and folders (auto-detected if not * provided) */ test_patterns?: Array; /** * Header param: Idempotency key for safely retrying operations */ 'Idempotency-Key'?: string; } export interface RepositoryUpdateParams { /** * Whether the repository is archived */ archived?: boolean; /** * Controls what kind of analysis should be performed */ detection?: Array<'security' | 'secrets' | 'dependencies'>; /** * Glob patterns of files and folders to ignore */ exclude_patterns?: Array; /** * Repository's identifier in your system */ external_id?: string; /** * Controls which issues are fixed */ fix?: Array<'security' | 'secrets' | 'dependencies'>; /** * Programming languages to analyze */ languages?: Array; /** * Repository name */ name?: string; /** * Glob patterns of test files and folders */ test_patterns?: Array; } export interface RepositoryListParams { /** * Cursor for pagination (object ID) */ after?: string; archived?: boolean; /** * Cursor for pagination (object ID) */ before?: string; /** * Number of items to return */ limit?: number; status?: 'empty' | 'uploading' | 'error' | 'ready'; } Repositories.Syncs = Syncs; export declare namespace Repositories { export { type PaginatedList as PaginatedList, type Repository as Repository, type RepositoryListResponse as RepositoryListResponse, type RepositoryCreateParams as RepositoryCreateParams, type RepositoryUpdateParams as RepositoryUpdateParams, type RepositoryListParams as RepositoryListParams, }; export { Syncs as Syncs, type Sync as Sync, type SyncListResponse as SyncListResponse, type SyncCreateParams as SyncCreateParams, type SyncRetrieveParams as SyncRetrieveParams, type SyncListParams as SyncListParams, }; }