UNPKG

repository-provider

Version:

abstract interface to git repository providers like github, bitbucket and gitlab

278 lines (277 loc) 9.82 kB
/** * @typedef {import('./project.mjs').Project} Project * @typedef {import('./milestone.mjs').Milestone} Milestone */ /** * @typedef {Object} DecodedRepositoryName * @property {string} [base] * @property {string} [group] * @property {string} [repository] * @property {string} [branch] */ /** * @typedef {Object} MessageDestination * Endpoint to deliver log messages to. * @property {function(string):void} info * @property {function(string):void} debug * @property {function(string):void} warn * @property {function(string):void} error * @property {function(string):void} trace */ /** * @param {Object} [options] * @param {string} [options.url] * @param {MessageDestination} [options.messageDestination] * @property {MessageDestination} messageDestination * @property {string} url * @property {string} api */ export class BaseProvider extends BaseObject { /** * Prefix used to form environment variables. * 'GITHUB_' -> 'GITHUB_TOKEN' * @return {string} identifier for environment options */ static get instanceIdentifier(): string; /** * Extract options suitable for the constructor. * Form the given set of environment variables. * Object with the detected key value pairs is delivered. * @param {Object} [env] as from process.env * @param {string} instanceIdentifier part of variable name. * @return {Object|undefined} undefined if no suitable environment variables have been found */ static optionsFromEnvironment(env?: any, instanceIdentifier?: string): any | undefined; /** * Check if given options are sufficient to create a provider. * @param {Object} options * @return {boolean} true if options ar sufficient to construct a provider */ static areOptionsSufficcient(options: any): boolean; static get attributes(): { /** * Name of the provider. */ name: { env: string; type: string; isKey: boolean; writable: boolean; mandatory: boolean; private?: boolean; depends?: string; additionalAttributes: string[]; description?: string; default?: any; set?: Function; get?: Function; }; url: import("pacc").AttributeDefinition; description: import("pacc").AttributeDefinition; priority: import("pacc").AttributeDefinition; /** * To forward info/warn and error messages to */ messageDestination: { type: string; default: Console; writable: boolean; private: boolean; isKey: boolean; mandatory: boolean; depends?: string; additionalAttributes: string[]; description?: string; set?: Function; get?: Function; env?: string[] | string; }; }; /** * @typedef {Object} parsedName * */ /** * Creates a new provider for a given set of options. * @param {Object} options additional options * @param {string} [options.instanceIdentifier] name of the provider instance * @param {string} [options.description] * @param {Object} env taken from process.env * @return {BaseProvider|undefined} newly created provider or undefined if options are not sufficient to construct a provider */ static initialize(options: { instanceIdentifier?: string; description?: string; }, env: any): BaseProvider | undefined; get priority(): number; /** * @param {any} other * @return {boolean} true if other provider is the same as the receiver */ equals(other: any): boolean; /** * All supported base urls. * For github something like: * - git@github.com * - git://github.com * - git+ssh://github.com * - https://github.com * - git+https://github.com * By default we provide provider name with ':'. * @return {string[]} common base urls of all repositories */ get repositoryBases(): string[]; /** * Does the provider support the base name. * @param {string} [base] to be checked * @return {boolean} true if base is supported or base is undefined */ supportsBase(base?: string): boolean; /** * Bring a repository name into its normal form by removing any clutter. * Like .git suffix or #branch names. * @param {string} name * @param {boolean} forLookup * @return {string|undefined} normalized name */ normalizeRepositoryName(name: string, forLookup: boolean): string | undefined; /** * Bring a group name into its normal form by removing any clutter. * Like .git suffix or #branch names. * @param {string} name * @param {boolean} forLookup * @return {string|undefined} normalized name */ normalizeGroupName(name: string, forLookup: boolean): string | undefined; /** * Are repository names case sensitive. * Overwrite and return false if you want to have case insensitive repository lookup. * @return {boolean} true */ get areRepositoryNamesCaseSensitive(): boolean; /** * Are repositroy group names case sensitive. * Overwrite and return false if you want to have case insensitive group lookup. * @return {boolean} true */ get areGroupNamesCaseSensitive(): boolean; /** * Parses repository name and tries to split it into * base, group, repository and branch. * @param {string} [name] * @param {string} focus where lies the focus if only one path component is given * @returns {DecodedRepositoryName} result */ parseName(name?: string, focus?: string): DecodedRepositoryName; /** * Create a repository. * @param {string} name of group and repository * @param {Object} [options] * @returns {Promise<Repository>} */ createRepository(name: string, options?: any): Promise<Repository>; /** * List provider objects of a given type. * * @param {string} type name of the method to deliver typed iterator projects,milestones,hooks,repositories,branches,tags * @param {string[]} patterns group / repository filter * @return {AsyncIterable<Repository|PullRequest|Branch|Tag|Project|Milestone|Hook>} all matching repositories of the providers */ list(type: string, patterns: string[]): AsyncIterable<Repository | PullRequest | Branch | Tag | Project | Milestone | Hook>; /** * List projects. * @param {string[]|string} [patterns] * @return {AsyncIterable<Project>} all matching projects of the provider */ projects(patterns?: string[] | string): AsyncIterable<Project>; /** * List milestones. * @param {string[]|string} [patterns] * @return {AsyncIterable<Milestone>} all matching milestones of the provider */ milestones(patterns?: string[] | string): AsyncIterable<Milestone>; /** * List repositories. * @param {string[]|string} [patterns] * @return {AsyncIterable<Repository>} all matching repos of the provider */ repositories(patterns?: string[] | string): AsyncIterable<Repository>; /** * List branches. * @param {string[]|string} [patterns] * @return {AsyncIterable<Branch>} all matching branches of the provider */ branches(patterns?: string[] | string): AsyncIterable<Branch>; /** * List tags. * @param {string[]|string} [patterns] * @return {AsyncIterable<Tag>} all matching tags of the provider */ tags(patterns?: string[] | string): AsyncIterable<Tag>; /** * List hooks. * @param {string[]|string} [patterns] * @return {AsyncIterable<Hook>} all matching hooks of the provider */ hooks(patterns?: string[] | string): AsyncIterable<Hook>; /** * List pull requests. * @param {string[]|string} [patterns] * @return {AsyncIterable<PullRequest>} all matching pullRequests of the provider */ pullRequests(patterns?: string[] | string): AsyncIterable<PullRequest>; /** * Deliver the provider name. * @return {string} class name by default */ get name(): string; /** * We are our own provider. * @return {BaseProvider} this */ get provider(): BaseProvider; /** * List all defined entries from attributes. * @return {{name: string}} */ toJSON(): { name: string; }; initializeRepositories(): void; trace(...args: any[]): any; debug(...args: any[]): any; info(...args: any[]): any; warn(...args: any[]): any; error(...args: any[]): any; get repositoryGroupClass(): typeof RepositoryGroup; get hookClass(): typeof Hook; get repositoryClass(): typeof Repository; get branchClass(): typeof Branch; get tagClass(): typeof Tag; get pullRequestClass(): typeof PullRequest; } export type Project = import("./project.mjs").Project; export type Milestone = import("./milestone.mjs").Milestone; export type DecodedRepositoryName = { base?: string; group?: string; repository?: string; branch?: string; }; /** * Endpoint to deliver log messages to. */ export type MessageDestination = { info: (arg0: string) => void; debug: (arg0: string) => void; warn: (arg0: string) => void; error: (arg0: string) => void; trace: (arg0: string) => void; }; import { BaseObject } from "./base-object.mjs"; import { Repository } from "./repository.mjs"; import { PullRequest } from "./pull-request.mjs"; import { Branch } from "./branch.mjs"; import { Tag } from "./tag.mjs"; import { Hook } from "./hook.mjs"; import { RepositoryGroup } from "./repository-group.mjs";