refactor vendor/config types a bit
This commit is contained in:
parent
7e82b27acf
commit
eb67ccf62b
29
src/types.ts
29
src/types.ts
|
@ -6,17 +6,34 @@
|
||||||
* or, if the file is unavailable, visit <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
* 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 {
|
export interface CopycatConfig {
|
||||||
vendorConfigs: CopycatProfile[];
|
vendorConfigs: CopycatProfile[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CopycatProfile {
|
export interface CopycatProfileBase {
|
||||||
name: string;
|
name: string;
|
||||||
vendor: Vendor;
|
vendor: Vendor;
|
||||||
/** authentication etc., always depends on 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 */
|
/** indicates the used api */
|
||||||
export enum VENDOR_TYPE {
|
export enum VENDOR_TYPE {
|
||||||
/** github, https://en.wikipedia.org/wiki/GitHub, both github.com (default) and github enterprise server */
|
/** 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, https://en.wikipedia.org/wiki/GitLab */
|
||||||
GITLAB = 'gitlab',
|
GITLAB = 'gitlab',
|
||||||
/** gitea, https://en.wikipedia.org/wiki/Gitea */
|
/** gitea, https://en.wikipedia.org/wiki/Gitea */
|
||||||
GITEA = 'gitea',
|
// GITEA = 'gitea',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Vendor {
|
export interface Vendor<T = VENDOR_TYPE> {
|
||||||
/** human-readable name like 'GitLab' */
|
|
||||||
display: string;
|
|
||||||
/** indicates the used api */
|
/** indicates the used api */
|
||||||
type: VENDOR_TYPE;
|
type: T;
|
||||||
/** the host, like 'framagit.org' */
|
/** the host, like 'framagit.org' */
|
||||||
domain: string;
|
domain: string;
|
||||||
}
|
}
|
||||||
|
|
8
src/vendor/github/vendormgr.ts
vendored
8
src/vendor/github/vendormgr.ts
vendored
|
@ -13,7 +13,7 @@ import GitHubRepoManager from './repomgr';
|
||||||
|
|
||||||
export interface GitHubConfig {
|
export interface GitHubConfig {
|
||||||
token: string;
|
token: string;
|
||||||
domain?: string | null;
|
domain: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GitHubVendorManager implements VendorManager<GitHubConfig> {
|
export default class GitHubVendorManager implements VendorManager<GitHubConfig> {
|
||||||
|
@ -23,12 +23,8 @@ export default class GitHubVendorManager implements VendorManager<GitHubConfig>
|
||||||
|
|
||||||
constructor(config: GitHubConfig) {
|
constructor(config: GitHubConfig) {
|
||||||
this.vendor = {
|
this.vendor = {
|
||||||
display:
|
|
||||||
config.domain && config.domain !== 'github.com'
|
|
||||||
? `Github Enterprise @ ${config.domain}`
|
|
||||||
: 'Microsoft GitHub',
|
|
||||||
type: VENDOR_TYPE.GITHUB,
|
type: VENDOR_TYPE.GITHUB,
|
||||||
domain: config.domain || 'github.com',
|
domain: config.domain,
|
||||||
};
|
};
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.gqlEndpoint = `https://${
|
this.gqlEndpoint = `https://${
|
||||||
|
|
1
src/vendor/gitlab/vendormgr.ts
vendored
1
src/vendor/gitlab/vendormgr.ts
vendored
|
@ -27,7 +27,6 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
||||||
|
|
||||||
constructor(config: GitLabConfig) {
|
constructor(config: GitLabConfig) {
|
||||||
this.vendor = {
|
this.vendor = {
|
||||||
display: `GitLab @ ${config.domain}`,
|
|
||||||
type: VENDOR_TYPE.GITLAB,
|
type: VENDOR_TYPE.GITLAB,
|
||||||
domain: config.domain,
|
domain: config.domain,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue