UNPKG

@fancode/react-native-codepush-joystick

Version:
184 lines (183 loc) 5.66 kB
import { LocalPackage, RemotePackage } from "react-native-code-push"; export interface GithubPullRequest { id: number; number: number; title: string; state: string; url: string; created_at: string; updated_at: string; draft: boolean; statuses_url: string; user: { login: string; avatar_url: string; }; head?: { label: string; ref: string; }; base?: { label: string; ref: string; }; } export interface GithubWorkflowRun { id: number; name: string; head_branch: string; head_sha: string; run_number: number; status: GithubWorkflowStatus; conclusion?: "success" | "failure" | "cancelled" | "neutral" | "skipped" | "timed_out"; created_at: string; updated_at: string; run_started_at: string; } export declare enum GithubWorkflowStatus { COMPLETED = "completed", ACTION_REQUIRED = "action_required", CANCELLED = "cancelled", FAILURE = "failure", NEUTRAL = "neutral", SKIPPED = "skipped", STALE = "stale", SUCCESS = "success", TIMED_OUT = "timed_out", IN_PROGRESS = "in_progress", QUEUED = "queued", REQUESTED = "requested", WAITING = "waiting", PENDING = "pending" } export declare enum CodePushStatus { NOT_CHECKED = "NOT_CHECKED", AVAILABLE = "AVAILABLE", UN_AVAILABLE = "UN_AVAILABLE", ERROR = "ERROR", DOWNLOADED = "DOWNLOADED", ALREADY_RUNNING = "ALREADY_RUNNING", NOT_RUNNING = "NOT_RUNNING" } export interface GitHubConfig { owner: string; repo: string; token: string; } export interface GitHubActionsConfig { owner: string; repo: string; token: string; workflowFile: string; workflowInputs?: Record<string, string>; } export type CustomWorkflowRun = { id: string; status: string; startedAt: string; extra?: Record<string, any>; }; export type CustomBuildInfo = { buildId: string; status: { status: string; conclusion?: string; completedAt?: string; logs?: string[]; }; startedAt: string; }; export type CustomBuildStatus = { status: string; completedAt?: string; }; export type CustomProviderConfig = { triggerBuild: (params: TriggerBuildParams) => Promise<CustomBuildInfo>; getWorkflowRuns: (branchName: string) => Promise<CustomWorkflowRun[]>; cancelBuild: (buildId: string) => Promise<void>; findWorkflowStatus(workflowRun: CustomWorkflowRun | null): { workflowStatus: FindWorkflowStatus; buildInfo: CustomBuildInfo; } | null; }; export interface FindWorkflowStatus { isRunning: boolean; isFailed: boolean; isCancelled: boolean; isCompleted: boolean; rawStatus: string; rawConclusion?: string; id: string | number; startedAt: Date; } export type GithubActionsCICDProviderType = CICDProvider<GithubWorkflowBuildInfo, GithubWorkflowRun>; export type CustomCICDProviderType = CICDProvider<CustomBuildInfo, CustomWorkflowRun>; export interface CICDProvider<BuildInfo, WorkflowRun> { triggerBuild(params: TriggerBuildParams): Promise<BuildInfo>; getWorkflowRuns(branchName: string): Promise<WorkflowRun[]>; cancelBuild(buildId: string): Promise<void>; findWorkflowStatus(workflowRun: WorkflowRun | null): { workflowStatus: FindWorkflowStatus; buildInfo: BuildInfo; } | null; } export interface CodePushManagerConfig { sourceControl: { config: GitHubConfig; }; cicdProvider: CICDProvider<GithubWorkflowBuildInfo | CustomBuildInfo, GithubWorkflowRun | CustomWorkflowRun>; codepush: { deploymentKey?: string; }; appVersion: string; versioning?: { strategy?: "pr-based" | "custom"; customCalculator?: (pr: GithubPullRequest, baseVersion: string) => string; }; callbacks?: CodePushCallbacks; } export interface CodePushCallbacks { onPullRequestsFetched?: (prs: GithubPullRequest[]) => void; onBuildTriggered?: (pr: GithubPullRequest, buildInfo: GithubWorkflowBuildInfo | CustomBuildInfo) => void; onCodePushAvailable?: (pr: GithubPullRequest, packageInfo: RemotePackage) => void; onDownloadStarted?: (pr: GithubPullRequest, packageInfo: RemotePackage) => void; onDownloadProgress?: (pr: GithubPullRequest, progress: number) => void; onDownloadComplete?: (pr: GithubPullRequest, localPackage: LocalPackage) => void; onError?: (error: Error, context: string, metadata?: any) => void; onStateChange?: (pr: GithubPullRequest, newState: CodePushOptionState, oldState: CodePushOptionState) => void; } export interface FetchPROptions { state?: "open" | "closed" | "all"; per_page?: number; page?: number; sort?: "created" | "updated" | "popularity"; direction?: "asc" | "desc"; } export interface TriggerBuildParams { branch: string; version: string; } export interface GithubWorkflowBuildInfo { buildId: string; status: GithubWorkflowBuildStatus; startedAt: string; } export interface GithubWorkflowBuildStatus { status: GithubWorkflowStatus; conclusion?: "success" | "failure" | "cancelled" | "neutral" | "skipped" | "timed_out"; completedAt?: string; logs?: string[]; } export interface CodePushOptionState { status: CodePushStatus; loading: boolean; progress: number | null; message: string | null; buildInfo: GithubWorkflowBuildInfo | CustomBuildInfo | null; remotePackage: RemotePackage | null; branchName: string | null; targetVersion: string | null; } export interface AppUpdateMetadata { updateMetadata: LocalPackage | null; }