copykitku/src/types.ts

170 lines
4.3 KiB
TypeScript
Raw Normal View History

2020-08-21 11:53:55 +02:00
/*
2021-02-14 22:24:01 +01:00
* Copykitku. Copyright (C) 2020 selfisekai <laura@selfisekai.rocks> and other contributors.
2020-08-21 11:53:55 +02:00
*
* 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>.
*/
2021-02-14 04:43:37 +01:00
import { GitHubConfig } from './vendor/github/vendormgr';
import { GitLabConfig } from './vendor/gitlab/vendormgr';
2021-02-14 22:24:01 +01:00
export interface CopykitkuConfig {
vendorConfigs: CopykitkuProfile[];
2020-08-05 23:33:36 +02:00
}
2021-02-14 22:24:01 +01:00
export interface CopykitkuProfileBase {
2020-08-05 23:33:36 +02:00
name: string;
2021-02-14 16:59:23 +01:00
vendor: Vendor<VENDOR_TYPE>;
2020-08-05 23:33:36 +02:00
/** authentication etc., always depends on vendor */
2021-02-14 22:24:01 +01:00
config: CopykitkuVendorConfig;
2021-02-14 04:43:37 +01:00
}
2021-02-14 22:24:01 +01:00
export type CopykitkuVendorConfig = GitHubConfig | GitLabConfig;
2021-02-14 04:43:37 +01:00
2021-02-14 22:24:01 +01:00
export interface CopykitkuProfileGitHub extends CopykitkuProfileBase {
2021-02-14 04:43:37 +01:00
vendor: Vendor<VENDOR_TYPE.GITHUB>;
config: GitHubConfig;
2020-08-05 23:33:36 +02:00
}
2021-02-14 22:24:01 +01:00
export interface CopykitkuProfileGitLab extends CopykitkuProfileBase {
2021-02-14 04:43:37 +01:00
vendor: Vendor<VENDOR_TYPE.GITLAB>;
config: GitLabConfig;
}
2021-02-14 22:24:01 +01:00
export type CopykitkuProfile = CopykitkuProfileGitHub | CopykitkuProfileGitLab;
2021-02-14 04:43:37 +01:00
2020-08-05 23:33:36 +02:00
/** 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 */
2021-02-14 04:43:37 +01:00
// GITEA = 'gitea',
2020-08-05 23:33:36 +02:00
}
2021-02-14 04:43:37 +01:00
export interface Vendor<T = VENDOR_TYPE> {
2020-08-05 23:33:36 +02:00
/** indicates the used api */
2021-02-14 04:43:37 +01:00
type: T;
2020-08-05 23:33:36 +02:00
/** 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;
2021-02-01 13:59:57 +01:00
url: string;
2020-08-05 23:33:36 +02:00
}
export interface RepoManager {
repo: Repo;
initialize: () => Promise<RepoManager>;
getIssue: (id: string) => Promise<Issue>;
2020-08-26 21:34:43 +02:00
replicateIssue: (issue: Issue) => Promise<Issue>;
2020-08-20 17:05:20 +02:00
getMergeRequest: (id: string) => Promise<MergeRequest>;
2021-02-21 21:29:21 +01:00
/** this method is to be invoked after the commits are pushed to the branch */
replicateMergeRequest: (
mergeRequest: MergeRequest,
/** where the commits have been pushed */
destBranch: string,
/** where the newly-created MR should target */
targetBranch: string,
) => Promise<MergeRequest>;
2021-02-26 00:58:36 +01:00
getCommit: (oid: string) => Promise<Commit>;
2020-08-05 23:33:36 +02:00
}
2021-02-01 12:04:19 +01:00
export enum ENTITY_TYPE {
ISSUE = 'issue',
MERGE_REQUEST = 'merge_request',
2021-02-02 16:20:59 +01:00
COMMIT = 'commit',
2021-02-01 12:04:19 +01:00
}
2020-08-20 17:05:20 +02:00
/** issue, merge request or whatever the fuck you need */
export interface RepoElement {
2021-02-01 12:15:53 +01:00
type: ENTITY_TYPE;
2020-08-05 23:33:36 +02:00
id: string;
title: string;
2021-02-02 16:20:59 +01:00
/** text body of the entity */
2020-08-05 23:33:36 +02:00
content: string;
repo: Repo;
2021-02-02 16:20:59 +01:00
/** URL to a user-readable page */
2021-02-01 13:59:57 +01:00
url: string;
2020-08-05 23:33:36 +02:00
}
2020-08-20 17:05:20 +02:00
/** basic */
export enum ISSUE_STATE {
OPEN = 'open',
CLOSED = 'closed',
}
export interface Issue extends RepoElement {
2021-02-01 12:04:19 +01:00
type: ENTITY_TYPE.ISSUE;
2020-08-20 17:05:20 +02:00
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 {
2021-02-01 12:04:19 +01:00
type: ENTITY_TYPE.MERGE_REQUEST;
2020-08-20 17:05:20 +02:00
state: MERGE_REQUEST_STATE;
/** null if unknown */
mergability: MERGE_REQUEST_MERGABILITY | null;
2021-02-02 16:20:59 +01:00
commits: Commit[];
2020-08-20 17:05:20 +02:00
isDraft: boolean;
}
2021-02-02 16:20:59 +01:00
export interface Commit extends RepoElement {
type: ENTITY_TYPE.COMMIT;
patchURL: string;
2021-02-11 20:31:55 +01:00
patchContent: () => Promise<string>;
2021-02-02 16:20:59 +01:00
diffURL: string;
2021-02-11 20:31:55 +01:00
diffContent: () => Promise<string>;
2021-02-02 16:20:59 +01:00
}
2020-08-05 23:33:36 +02:00
/** 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;
}
2021-02-23 23:19:52 +01:00
export type CopykitkuProjectConfig = Partial<{
/** destination repository url (like "https://git.sakamoto.pl/laudompat/copykitku") */
dest: string;
2021-02-24 01:33:32 +01:00
patchHook: string;
2021-02-23 23:19:52 +01:00
}>;