copykitku/src/types.ts
2020-08-20 17:05:20 +02:00

109 lines
2.4 KiB
TypeScript

export interface CopycatConfig {
vendorConfigs: CopycatProfile[];
}
export interface CopycatProfile {
name: string;
vendor: Vendor;
/** authentication etc., always depends on vendor */
config: any;
}
/** indicates the used api */
export enum VENDOR_TYPE {
/** github, https://en.wikipedia.org/wiki/GitHub, both github.com (default) and github enterprise server */
GITHUB = 'github',
/** gitlab, https://en.wikipedia.org/wiki/GitLab */
GITLAB = 'gitlab',
/** gitea, https://en.wikipedia.org/wiki/Gitea */
GITEA = 'gitea',
}
export interface Vendor {
/** human-readable name like 'GitLab' */
display: string;
/** indicates the used api */
type: VENDOR_TYPE;
/** the host, like 'framagit.org' */
domain: string;
}
export interface VendorManager<T = any> {
vendor: Vendor;
config: T;
initialize: () => Promise<VendorManager<T>>;
getRepo: (path: string) => Promise<RepoManager>;
}
export interface Repo {
vendor: Vendor;
owner: Actor;
name: string;
}
export interface RepoManager {
repo: Repo;
initialize: () => Promise<RepoManager>;
getIssue: (id: string) => Promise<Issue>;
getMergeRequest: (id: string) => Promise<MergeRequest>;
}
/** issue, merge request or whatever the fuck you need */
export interface RepoElement {
id: string;
title: string;
content: string;
repo: Repo;
}
/** basic */
export enum ISSUE_STATE {
OPEN = 'open',
CLOSED = 'closed',
}
export interface Issue extends RepoElement {
state: ISSUE_STATE;
}
export enum MERGE_REQUEST_STATE {
OPEN = 'open',
/** closed without merging */
CLOSED = 'closed',
MERGED = 'merged',
}
export enum MERGE_REQUEST_MERGABILITY {
MERGEABLE = 'mergeable',
CONFLICTING = 'conflicting',
}
export interface MergeRequest extends RepoElement {
state: MERGE_REQUEST_STATE;
/** null if unknown */
mergability: MERGE_REQUEST_MERGABILITY | null;
isDraft: boolean;
}
/** the account that did an action */
export enum ACTOR_TYPE {
/** human person, absolutely not a sentient lizard */
USER = 'user',
/** organization */
ORG = 'org',
/** bot */
BOT = 'bot',
/** deleted account, imported actions or anything */
GHOST = 'ghost',
/** unknown (before initializing sth) */
UNKNOWN = 'unknown',
}
/** repository owner, issue/MR/comment/... creator */
export interface Actor {
type: ACTOR_TYPE;
username: string;
display_name?: string | null;
vendor: Vendor;
}