refactor vendor/config types a bit

This commit is contained in:
Laura Liberda 2021-02-14 04:43:37 +01:00
parent 7e82b27acf
commit eb67ccf62b
3 changed files with 24 additions and 14 deletions

View file

@ -6,17 +6,34 @@
* 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 CopycatProfile {
export interface CopycatProfileBase {
name: string;
vendor: Vendor;
/** authentication etc., always depends on vendor */
config: any;
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 */
@ -24,14 +41,12 @@ export enum VENDOR_TYPE {
/** gitlab, https://en.wikipedia.org/wiki/GitLab */
GITLAB = 'gitlab',
/** gitea, https://en.wikipedia.org/wiki/Gitea */
GITEA = 'gitea',
// GITEA = 'gitea',
}
export interface Vendor {
/** human-readable name like 'GitLab' */
display: string;
export interface Vendor<T = VENDOR_TYPE> {
/** indicates the used api */
type: VENDOR_TYPE;
type: T;
/** the host, like 'framagit.org' */
domain: string;
}

View file

@ -13,7 +13,7 @@ import GitHubRepoManager from './repomgr';
export interface GitHubConfig {
token: string;
domain?: string | null;
domain: string;
}
export default class GitHubVendorManager implements VendorManager<GitHubConfig> {
@ -23,12 +23,8 @@ export default class GitHubVendorManager implements VendorManager<GitHubConfig>
constructor(config: GitHubConfig) {
this.vendor = {
display:
config.domain && config.domain !== 'github.com'
? `Github Enterprise @ ${config.domain}`
: 'Microsoft GitHub',
type: VENDOR_TYPE.GITHUB,
domain: config.domain || 'github.com',
domain: config.domain,
};
this.config = config;
this.gqlEndpoint = `https://${

View file

@ -27,7 +27,6 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
constructor(config: GitLabConfig) {
this.vendor = {
display: `GitLab @ ${config.domain}`,
type: VENDOR_TYPE.GITLAB,
domain: config.domain,
};