170 lines
4.3 KiB
TypeScript
170 lines
4.3 KiB
TypeScript
/*
|
|
* Copykitku. 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 CopykitkuConfig {
|
|
vendorConfigs: CopykitkuProfile[];
|
|
}
|
|
|
|
export interface CopykitkuProfileBase {
|
|
name: string;
|
|
vendor: Vendor<VENDOR_TYPE>;
|
|
/** authentication etc., always depends on vendor */
|
|
config: CopykitkuVendorConfig;
|
|
}
|
|
|
|
export type CopykitkuVendorConfig = GitHubConfig | GitLabConfig;
|
|
|
|
export interface CopykitkuProfileGitHub extends CopykitkuProfileBase {
|
|
vendor: Vendor<VENDOR_TYPE.GITHUB>;
|
|
config: GitHubConfig;
|
|
}
|
|
|
|
export interface CopykitkuProfileGitLab extends CopykitkuProfileBase {
|
|
vendor: Vendor<VENDOR_TYPE.GITLAB>;
|
|
config: GitLabConfig;
|
|
}
|
|
|
|
export type CopykitkuProfile = CopykitkuProfileGitHub | CopykitkuProfileGitLab;
|
|
|
|
/** 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>;
|
|
/** 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>;
|
|
getCommit: (oid: string) => Promise<Commit>;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
export type CopykitkuProjectConfig = Partial<{
|
|
/** destination repository url (like "https://git.sakamoto.pl/laudompat/copykitku") */
|
|
dest: string;
|
|
patchHook: string;
|
|
}>;
|