/* * Copykitku. Copyright (C) 2020 selfisekai 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 . */ import { GitHubConfig } from './vendor/github/vendormgr'; import { GitLabConfig } from './vendor/gitlab/vendormgr'; export interface CopykitkuConfig { vendorConfigs: CopykitkuProfile[]; } export interface CopykitkuProfileBase { name: string; vendor: Vendor; /** authentication etc., always depends on vendor */ config: CopykitkuVendorConfig; } export type CopykitkuVendorConfig = GitHubConfig | GitLabConfig; export interface CopykitkuProfileGitHub extends CopykitkuProfileBase { vendor: Vendor; config: GitHubConfig; } export interface CopykitkuProfileGitLab extends CopykitkuProfileBase { vendor: Vendor; 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 { /** indicates the used api */ type: T; /** the host, like 'framagit.org' */ domain: string; } export interface VendorManager { vendor: Vendor; config: T; initialize: () => Promise>; getRepo: (path: string) => Promise; } export interface Repo { vendor: Vendor; owner: Actor; name: string; url: string; } export interface RepoManager { repo: Repo; initialize: () => Promise; getIssue: (id: string) => Promise; replicateIssue: (issue: Issue) => Promise; getMergeRequest: (id: string) => Promise; /** 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; getCommit: (oid: string) => Promise; } 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; diffURL: string; diffContent: () => Promise; } /** 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; }>;