copykitku/src/types.ts
Laura Liberda 3f20cfde24 fix types
2021-02-14 16:59:23 +01:00

155 lines
3.7 KiB
TypeScript

/*
* Copycat. Copyright (C) 2020 selfisekai <laura@selfisekai.rocks> and other contributors.
*
* This is free software, and you are welcome to redistribute it
* under the GNU General Public License 3.0 or later; see the LICENSE file for details,
* or, if the file is unavailable, visit <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
*/
import { GitHubConfig } from './vendor/github/vendormgr';
import { GitLabConfig } from './vendor/gitlab/vendormgr';
export interface CopycatConfig {
vendorConfigs: CopycatProfile[];
}
export interface CopycatProfileBase {
name: string;
vendor: Vendor<VENDOR_TYPE>;
/** authentication etc., always depends on vendor */
config: CopycatVendorConfig;
}
export type CopycatVendorConfig = GitHubConfig | GitLabConfig;
export interface CopycatProfileGitHub extends CopycatProfileBase {
vendor: Vendor<VENDOR_TYPE.GITHUB>;
config: GitHubConfig;
}
export interface CopycatProfileGitLab extends CopycatProfileBase {
vendor: Vendor<VENDOR_TYPE.GITLAB>;
config: GitLabConfig;
}
export type CopycatProfile = CopycatProfileGitHub | CopycatProfileGitLab;
/** 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<T = VENDOR_TYPE> {
/** indicates the used api */
type: T;
/** 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;
url: string;
}
export interface RepoManager {
repo: Repo;
initialize: () => Promise<RepoManager>;
getIssue: (id: string) => Promise<Issue>;
replicateIssue: (issue: Issue) => Promise<Issue>;
getMergeRequest: (id: string) => Promise<MergeRequest>;
}
export enum ENTITY_TYPE {
ISSUE = 'issue',
MERGE_REQUEST = 'merge_request',
COMMIT = 'commit',
}
/** issue, merge request or whatever the fuck you need */
export interface RepoElement {
type: ENTITY_TYPE;
id: string;
title: string;
/** text body of the entity */
content: string;
repo: Repo;
/** URL to a user-readable page */
url: string;
}
/** basic */
export enum ISSUE_STATE {
OPEN = 'open',
CLOSED = 'closed',
}
export interface Issue extends RepoElement {
type: ENTITY_TYPE.ISSUE;
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 {
type: ENTITY_TYPE.MERGE_REQUEST;
state: MERGE_REQUEST_STATE;
/** null if unknown */
mergability: MERGE_REQUEST_MERGABILITY | null;
commits: Commit[];
isDraft: boolean;
}
export interface Commit extends RepoElement {
type: ENTITY_TYPE.COMMIT;
patchURL: string;
patchContent: () => Promise<string>;
diffURL: string;
diffContent: () => Promise<string>;
}
/** 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;
}