repository-provider
Advanced tools
Comparing version 7.0.0 to 7.0.1
1380
dist/provider.js
@@ -7,358 +7,604 @@ 'use strict'; | ||
function _AwaitValue(value) { | ||
this.wrapped = value; | ||
function notImplementedError() { | ||
return new Error("not implemented"); | ||
} | ||
function _AsyncGenerator(gen) { | ||
var front, back; | ||
/** | ||
* create properties from options and default options | ||
* @see Object.definedProperties() | ||
* @param {Object} properties where the properties will be stored | ||
* @param {Object} options | ||
* @param {Object} defaultOptions | ||
*/ | ||
function propertiesFromOptions(properties, options, defaultOptions) { | ||
Object.keys(defaultOptions).forEach(name => { | ||
properties[name] = { | ||
value: (options !== undefined && options[name]) || defaultOptions[name] | ||
}; | ||
}); | ||
} | ||
function send(key, arg) { | ||
return new Promise(function (resolve, reject) { | ||
var request = { | ||
key: key, | ||
arg: arg, | ||
resolve: resolve, | ||
reject: reject, | ||
next: null | ||
}; | ||
const IS_INITIALIZED = Symbol('isInitialized'); | ||
if (back) { | ||
back = back.next = request; | ||
} else { | ||
front = back = request; | ||
resume(key, arg); | ||
function OneTimeInititalizerMixin(base) { | ||
/** | ||
* enshures that _initialize() will be called only once | ||
*/ | ||
return class OneTimeInititalizer extends base { | ||
/** | ||
* async initialization. | ||
* Will execute _intitialize() only once | ||
* | ||
* @return {Promise<undefined>} | ||
*/ | ||
async initialize(...args) { | ||
if (this[IS_INITIALIZED] === true) { | ||
return; | ||
} | ||
}); | ||
} | ||
function resume(key, arg) { | ||
try { | ||
var result = gen[key](arg); | ||
var value = result.value; | ||
var wrappedAwait = value instanceof _AwaitValue; | ||
Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) { | ||
if (wrappedAwait) { | ||
resume("next", arg); | ||
return; | ||
} | ||
this[IS_INITIALIZED] = true; | ||
settle(result.done ? "return" : "normal", arg); | ||
}, function (err) { | ||
resume("throw", err); | ||
}); | ||
} catch (err) { | ||
settle("throw", err); | ||
await this._initialize(...args); | ||
} | ||
} | ||
function settle(type, value) { | ||
switch (type) { | ||
case "return": | ||
front.resolve({ | ||
value: value, | ||
done: true | ||
}); | ||
break; | ||
/** | ||
* @return {boolean} true is initialize() has been done | ||
*/ | ||
get isInitialized() { | ||
return this[IS_INITIALIZED] ? true : false; | ||
} | ||
}; | ||
} | ||
case "throw": | ||
front.reject(value); | ||
break; | ||
/** | ||
* Abstract branch | ||
* @see {@link Repository#addBranch} | ||
* @param {Repository} repository | ||
* @param {string} name | ||
* @param {Object} options | ||
* @property {Repository} repository | ||
* @property {Provider} provider | ||
* @property {string} name | ||
*/ | ||
const Branch = OneTimeInititalizerMixin( | ||
class Branch { | ||
/** | ||
* options | ||
*/ | ||
static get defaultOptions() { | ||
return {}; | ||
} | ||
default: | ||
front.resolve({ | ||
value: value, | ||
done: false | ||
}); | ||
break; | ||
constructor(repository, name = "master", options) { | ||
const properties = { | ||
name: { value: name }, | ||
repository: { value: repository } | ||
}; | ||
propertiesFromOptions( | ||
properties, | ||
options, | ||
this.constructor.defaultOptions | ||
); | ||
Object.defineProperties(this, properties); | ||
repository.addBranch(this); | ||
} | ||
front = front.next; | ||
/** | ||
* The provider we live in | ||
* @return {Provider} | ||
*/ | ||
get provider() { | ||
return this.repository.provider; | ||
} | ||
if (front) { | ||
resume(front.key, front.arg); | ||
} else { | ||
back = null; | ||
/** | ||
* Branch owner | ||
* By default we provide the repository owner | ||
* @see {@link Repository#owner} | ||
* @return {string} | ||
*/ | ||
get owner() { | ||
return this.repository.owner; | ||
} | ||
} | ||
this._invoke = send; | ||
/** | ||
* Repository and branch name combined | ||
* @return {string} 'repo#branch' | ||
*/ | ||
get fullName() { | ||
return `${this.repository.fullName}#${this.name}`; | ||
} | ||
if (typeof gen.return !== "function") { | ||
this.return = undefined; | ||
/** | ||
* Repository fullName and branch name combined. | ||
* But skipping the branch name if it is the default branch | ||
* @return {string} 'user/repo#branch' | ||
*/ | ||
get fullCondensedName() { | ||
return this.isDefault | ||
? this.repository.fullName | ||
: `${this.repository.fullName}#${this.name}`; | ||
} | ||
/** | ||
* Deliver repository and branch url combined | ||
* @return {string} 'repoUrl#branch' | ||
*/ | ||
get url() { | ||
return this.isDefault | ||
? this.repository.url | ||
: `${this.repository.url}#${this.name}`; | ||
} | ||
/** | ||
* Url of issue tracking system. | ||
* @see {@link Repository#issuesURL} | ||
* @return {string} as provided from the repository | ||
*/ | ||
get issuesURL() { | ||
return this.repository.issuesURL; | ||
} | ||
/** | ||
* Url of home page. | ||
* @see {@link Repository#homePageURL} | ||
* @return {string} as provided from the repository | ||
*/ | ||
get homePageURL() { | ||
return this.repository.homePageURL; | ||
} | ||
/** | ||
* Git branch ref name | ||
* @return {string} git ref of the branch | ||
*/ | ||
get ref() { | ||
return `refs/heads/${this.name}`; | ||
} | ||
/** | ||
* Are we the default branch | ||
* @return {boolean} true if name is 'master' | ||
*/ | ||
get isDefault() { | ||
return this.name === "master"; | ||
} | ||
/** | ||
* Delete the branch from the {@link Repository}. | ||
* @see {@link Repository#deleteBranch} | ||
* @return {Promise<undefined>} | ||
*/ | ||
async delete() { | ||
return this.repository.deleteBranch(this.name); | ||
} | ||
/** | ||
* Deliver file content from the head | ||
* @param {string} path | ||
* @return {Promise<Content>} content of a given file | ||
*/ | ||
async content(path) { | ||
throw new Error(`No such object '${path}'`); | ||
} | ||
/** | ||
* Commit files | ||
* @param {string} message commit message | ||
* @param {Content[]} updates file content to be commited | ||
* @param {Object} options | ||
* @return {Promise} | ||
*/ | ||
async commit(message, updates, options) { | ||
return notImplementedError(); | ||
} | ||
/** | ||
* Create a pull request | ||
* @param {Branch} toBranch | ||
* @param {string} message | ||
* @return {Promise<PullRequest>} | ||
*/ | ||
async createPullRequest(toBranch, message) { | ||
return notImplementedError(); | ||
} | ||
async addPullRequest(pullRequest) { | ||
return this.repository.addPullRequest(pullRequest); | ||
} | ||
async deletePullRequest(name) { | ||
return this.repository.deletePullRequest(name); | ||
} | ||
/** | ||
* By default we use the repository implementation. | ||
* @return {Class} as defined in the repository | ||
*/ | ||
get pullRequestClass() { | ||
return this.repository.pullRequestClass; | ||
} | ||
/** | ||
* Create a new {@link Branch} by cloning a given source branch | ||
* Simplay calls Repository.createBranch() with the receiver as source branch | ||
* @param {string} name | ||
* @param {Object} options | ||
* @return {Promise<Branch>} newly created branch (or already present old one with the same name) | ||
*/ | ||
async createBranch(name, options) { | ||
return this.repository.createBranch(name, this, options); | ||
} | ||
/** | ||
* List paths of the branch | ||
* @param {string[]} matchingPatterns | ||
* @return {string[]} all file names in the branch | ||
*/ | ||
async *list(matchingPatterns) {} | ||
/** | ||
* Value delivered from the provider | ||
* @see {@link Provider#rateLimitReached} | ||
* @return {boolean} providers rateLimitReached | ||
*/ | ||
get rateLimitReached() { | ||
return this.provider.rateLimitReached; | ||
} | ||
/** | ||
* forward to the Provider | ||
* @param {boolean} value | ||
*/ | ||
set rateLimitReached(value) { | ||
this.provider.rateLimitReached(value); | ||
} | ||
async _initialize() {} | ||
/** | ||
* Get sha of a ref | ||
* @param {string} ref | ||
* @return {string} sha of the ref | ||
*/ | ||
async refId(ref = this.ref) { | ||
return this.repository.refId(ref); | ||
} | ||
toString() { | ||
return this.fullCondensedName; | ||
} | ||
} | ||
} | ||
); | ||
if (typeof Symbol === "function" && Symbol.asyncIterator) { | ||
_AsyncGenerator.prototype[Symbol.asyncIterator] = function () { | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Abstract repository | ||
* @param {Owner} owner | ||
* @param {string} name (#branch) will be removed | ||
* @param {Object} options | ||
* @param {string} [options.description] human readable description | ||
* @param {string} [options.id] internal id | ||
* | ||
* @property {Owner} owner | ||
* @property {string} name without (#branch) | ||
* @property {string} [description] from options.description | ||
* @property {string} [id] from options.id | ||
* @property {Map<string,Branch>} branches | ||
* @property {Map<string,PullRequest>} pullRequests | ||
*/ | ||
const Repository = OneTimeInititalizerMixin( | ||
class Repository { | ||
/** | ||
* options | ||
*/ | ||
static get defaultOptions() { | ||
return { | ||
/** | ||
* the description of the repository content. | ||
* @return {string} | ||
*/ | ||
description: undefined, | ||
_AsyncGenerator.prototype.next = function (arg) { | ||
return this._invoke("next", arg); | ||
}; | ||
/** | ||
* unique id within the provider. | ||
* @return {string} | ||
*/ | ||
id: undefined | ||
}; | ||
} | ||
_AsyncGenerator.prototype.throw = function (arg) { | ||
return this._invoke("throw", arg); | ||
}; | ||
constructor(owner, name, options) { | ||
name = name.replace(/#.*$/, ""); | ||
_AsyncGenerator.prototype.return = function (arg) { | ||
return this._invoke("return", arg); | ||
}; | ||
const properties = { | ||
name: { value: name }, | ||
owner: { value: owner }, | ||
_branches: { value: new Map() }, | ||
_pullRequests: { value: new Map() } | ||
}; | ||
function _wrapAsyncGenerator(fn) { | ||
return function () { | ||
return new _AsyncGenerator(fn.apply(this, arguments)); | ||
}; | ||
} | ||
propertiesFromOptions( | ||
properties, | ||
options, | ||
this.constructor.defaultOptions | ||
); | ||
function notImplementedError() { | ||
return new Error("not implemented"); | ||
} | ||
function propertiesFromOptions(properties, options, defaultOptions) { | ||
Object.keys(defaultOptions).forEach(name => { | ||
properties[name] = { | ||
value: options !== undefined && options[name] || defaultOptions[name] | ||
}; | ||
}); | ||
} | ||
Object.defineProperties(this, properties); | ||
} | ||
const IS_INITIALIZED = Symbol('isInitialized'); | ||
function OneTimeInititalizerMixin(base) { | ||
return class OneTimeInititalizer extends base { | ||
async initialize(...args) { | ||
if (this[IS_INITIALIZED] === true) { | ||
return; | ||
} | ||
this[IS_INITIALIZED] = true; | ||
await this._initialize(...args); | ||
/** | ||
* full repository name within the provider | ||
* @return {string} full repo name | ||
*/ | ||
get fullName() { | ||
return this.name; | ||
} | ||
get isInitialized() { | ||
return this[IS_INITIALIZED] ? true : false; | ||
/** | ||
* the owners provider | ||
* @return {Provider} | ||
*/ | ||
get provider() { | ||
return this.owner.provider; | ||
} | ||
}; | ||
} | ||
const Branch = OneTimeInititalizerMixin(class Branch { | ||
static get defaultOptions() { | ||
return {}; | ||
} | ||
constructor(repository, name = "master", options) { | ||
const properties = { | ||
name: { | ||
value: name | ||
}, | ||
repository: { | ||
value: repository | ||
/** | ||
* Lookup content form the head of the default branch | ||
* {@link Branch#content} | ||
* @return {Content} | ||
*/ | ||
async content(...args) { | ||
return (await this.defaultBranch).content(...args); | ||
} | ||
/** | ||
* urls to access the repo | ||
* @return {string[]} | ||
*/ | ||
get urls() { | ||
return []; | ||
} | ||
/** | ||
* preffered url to access the repo | ||
* @return {string} | ||
*/ | ||
get url() { | ||
return this.urls[0]; | ||
} | ||
/** | ||
* the url of issue tracking system. | ||
* @return {string} | ||
*/ | ||
get issuesURL() { | ||
return undefined; | ||
} | ||
/** | ||
* the url of home page. | ||
* @return {string} | ||
*/ | ||
get homePageURL() { | ||
return undefined; | ||
} | ||
/** | ||
* Name without owner | ||
* @return {string} name | ||
*/ | ||
get condensedName() { | ||
return this.name; | ||
} | ||
/** | ||
* Lookup branch by name | ||
* @param {string} name | ||
* @return {Promise<Branch>} | ||
*/ | ||
async branch(name, options) { | ||
await this.initialize(); | ||
return this._branches.get(name); | ||
} | ||
/** | ||
* Lookup the default branch | ||
* @return {Promise<Branch>} 'master' branch | ||
*/ | ||
get defaultBranch() { | ||
return this.branch("master"); | ||
} | ||
/** | ||
* @return {Promise<Map>} of all branches | ||
*/ | ||
async branches() { | ||
await this.initialize(); | ||
return this._branches; | ||
} | ||
/** | ||
* Create a new {@link Branch} by cloning a given source branch | ||
* @param {string} name | ||
* @param {Branch} source branch defaults to master | ||
* @param {Object} options | ||
* @return {Promise<Branch>} newly created branch (or already present old one with the same name) | ||
*/ | ||
async createBranch(name, source, options) { | ||
await this.initialize(); | ||
let branch = this._branches.get(name); | ||
if (branch === undefined) { | ||
branch = await this._createBranch(name, source === undefined ? await this.defaultBranch : source, options); | ||
this._branches.set(branch.name, branch); | ||
} | ||
}; | ||
propertiesFromOptions(properties, options, this.constructor.defaultOptions); | ||
Object.defineProperties(this, properties); | ||
repository.addBranch(this); | ||
} | ||
get provider() { | ||
return this.repository.provider; | ||
} | ||
get owner() { | ||
return this.repository.owner; | ||
} | ||
get fullName() { | ||
return `${this.repository.fullName}#${this.name}`; | ||
} | ||
get fullCondensedName() { | ||
return this.isDefault ? this.repository.fullName : `${this.repository.fullName}#${this.name}`; | ||
} | ||
get url() { | ||
return this.isDefault ? this.repository.url : `${this.repository.url}#${this.name}`; | ||
} | ||
get issuesURL() { | ||
return this.repository.issuesURL; | ||
} | ||
get homePageURL() { | ||
return this.repository.homePageURL; | ||
} | ||
get ref() { | ||
return `refs/heads/${this.name}`; | ||
} | ||
get isDefault() { | ||
return this.name === "master"; | ||
} | ||
async delete() { | ||
return this.repository.deleteBranch(this.name); | ||
} | ||
async content(path) { | ||
throw new Error(`No such object '${path}'`); | ||
} | ||
async commit(message, updates, options) { | ||
return notImplementedError(); | ||
} | ||
async createPullRequest(toBranch, message) { | ||
return notImplementedError(); | ||
} | ||
async addPullRequest(pullRequest) { | ||
return this.repository.addPullRequest(pullRequest); | ||
} | ||
async deletePullRequest(name) { | ||
return this.repository.deletePullRequest(name); | ||
} | ||
get pullRequestClass() { | ||
return this.repository.pullRequestClass; | ||
} | ||
async createBranch(name, options) { | ||
return this.repository.createBranch(name, this, options); | ||
} | ||
list(matchingPatterns) { | ||
return _wrapAsyncGenerator(function* () {})(); | ||
} | ||
get rateLimitReached() { | ||
return this.provider.rateLimitReached; | ||
} | ||
set rateLimitReached(value) { | ||
this.provider.rateLimitReached(value); | ||
} | ||
async _initialize() {} | ||
async refId(ref = this.ref) { | ||
return this.repository.refId(ref); | ||
} | ||
toString() { | ||
return this.fullCondensedName; | ||
} | ||
}); | ||
const Repository = OneTimeInititalizerMixin(class Repository { | ||
static get defaultOptions() { | ||
return { | ||
description: undefined, | ||
id: undefined | ||
}; | ||
} | ||
constructor(owner, name, options) { | ||
name = name.replace(/#.*$/, ""); | ||
const properties = { | ||
name: { | ||
value: name | ||
}, | ||
owner: { | ||
value: owner | ||
}, | ||
_branches: { | ||
value: new Map() | ||
}, | ||
_pullRequests: { | ||
value: new Map() | ||
} | ||
}; | ||
propertiesFromOptions(properties, options, this.constructor.defaultOptions); | ||
Object.defineProperties(this, properties); | ||
} | ||
get fullName() { | ||
return this.name; | ||
} | ||
get provider() { | ||
return this.owner.provider; | ||
} | ||
async content(...args) { | ||
return (await this.defaultBranch).content(...args); | ||
} | ||
get urls() { | ||
return []; | ||
} | ||
get url() { | ||
return this.urls[0]; | ||
} | ||
get issuesURL() { | ||
return undefined; | ||
} | ||
get homePageURL() { | ||
return undefined; | ||
} | ||
get condensedName() { | ||
return this.name; | ||
} | ||
async branch(name, options) { | ||
await this.initialize(); | ||
return this._branches.get(name); | ||
} | ||
get defaultBranch() { | ||
return this.branch("master"); | ||
} | ||
async branches() { | ||
await this.initialize(); | ||
return this._branches; | ||
} | ||
async createBranch(name, source, options) { | ||
await this.initialize(); | ||
let branch = this._branches.get(name); | ||
if (branch === undefined) { | ||
branch = await this._createBranch(name, source === undefined ? await this.defaultBranch : source, options); | ||
return branch; | ||
} | ||
/** | ||
* Create a new {@link Branch} by cloning a given source branch | ||
* All repository implementations must provide a repository._createBranch() to handle the real branch creation. | ||
* This methos MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal class methods only. | ||
* Internal branch creation does not call repository.initialize() | ||
* @param {string} name | ||
* @param {Branch} source branch defaults to master | ||
* @param {Object} options | ||
* @return {Promise<Branch>} newly created branch | ||
*/ | ||
async _createBranch(name, source, options) { | ||
return new this.branchClass(this, name, options); | ||
} | ||
/** | ||
* Delete a {@link Branch} | ||
* @param {string} name | ||
* @return {Promise<undefined>} | ||
*/ | ||
async deleteBranch(name) { | ||
this._branches.delete(name); | ||
} | ||
/** | ||
* Add a branch | ||
* @param {Branch} branch | ||
* @return {Promise<undefined>} | ||
*/ | ||
async addBranch(branch) { | ||
this._branches.set(branch.name, branch); | ||
} | ||
return branch; | ||
} | ||
async _createBranch(name, source, options) { | ||
return new this.branchClass(this, name, options); | ||
} | ||
async deleteBranch(name) { | ||
this._branches.delete(name); | ||
} | ||
async addBranch(branch) { | ||
this._branches.set(branch.name, branch); | ||
} | ||
async delete() { | ||
return this.owner.deleteRepository(this.name); | ||
} | ||
async createPullRequest(name, source, options) { | ||
await this.initialize(); | ||
let pr = this._pullRequests.get(name); | ||
if (pr === undefined) { | ||
pr = await this._createPullRequest(name, source, options); | ||
this._pullRequests.set(pr.name, pr); | ||
/** | ||
* Delete the repository from the {@link Provider}. | ||
* {@link Provider#deleteRepository} | ||
* @return {Promise<undefined>} | ||
*/ | ||
async delete() { | ||
return this.owner.deleteRepository(this.name); | ||
} | ||
return pr; | ||
async createPullRequest(name, source, options) { | ||
await this.initialize(); | ||
let pr = this._pullRequests.get(name); | ||
if (pr === undefined) { | ||
pr = await this._createPullRequest(name, source, options); | ||
this._pullRequests.set(pr.name, pr); | ||
} | ||
return pr; | ||
} | ||
async _createPullRequest(name, source, options) { | ||
return new this.pullRequestClass(name, source, this, options); | ||
} | ||
/** | ||
* Deliver all {@link PullRequest}s | ||
* @return {Promise<Map>} of all pull requests | ||
*/ | ||
async pullRequests() { | ||
await this.initialize(); | ||
return this._pullRequests; | ||
} | ||
/** | ||
* The @{link PullRequest} for a given name | ||
* @param {string} name | ||
* @return {Promise<PullRequest>} | ||
*/ | ||
async pullRequest(name) { | ||
return this._pullRequests.get(name); | ||
} | ||
/** | ||
* Add a pull request | ||
* @param {PullRequest} pullRequest | ||
* @return {Promise} | ||
*/ | ||
async addPullRequest(pullRequest) { | ||
this._pullRequests.set(pullRequest.name, pullRequest); | ||
} | ||
/** | ||
* Delete a {@link PullRequest} | ||
* @param {string} name | ||
* @return {Promise} | ||
*/ | ||
async deletePullRequest(name) { | ||
this._pullRequests.delete(name); | ||
} | ||
/** | ||
* @return {string} providers type | ||
*/ | ||
get type() { | ||
return this.owner.type; | ||
} | ||
/** | ||
* Get sha of a ref | ||
* @param {string} ref | ||
* @return {string} sha of the ref | ||
*/ | ||
async refId(ref) { | ||
return undefined; | ||
} | ||
/** | ||
* Value delivered from the provider | ||
* @return {boolean} providers rateLimitReached | ||
*/ | ||
get rateLimitReached() { | ||
return this.provider.rateLimitReached; | ||
} | ||
/** | ||
* forward to the Provider | ||
* @param {boolean} value | ||
*/ | ||
set rateLimitReached(value) { | ||
this.provider.rateLimitReached(value); | ||
} | ||
async _initialize() {} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get repositoryClass() { | ||
return this.provider.repositoryClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get pullRequestClass() { | ||
return this.provider.pullRequestClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get branchClass() { | ||
return this.provider.branchClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get contentClass() { | ||
return this.provider.contentClass; | ||
} | ||
toString() { | ||
return this.name; | ||
} | ||
} | ||
async _createPullRequest(name, source, options) { | ||
return new this.pullRequestClass(name, source, this, options); | ||
} | ||
async pullRequests() { | ||
await this.initialize(); | ||
return this._pullRequests; | ||
} | ||
async pullRequest(name) { | ||
return this._pullRequests.get(name); | ||
} | ||
async addPullRequest(pullRequest) { | ||
this._pullRequests.set(pullRequest.name, pullRequest); | ||
} | ||
async deletePullRequest(name) { | ||
this._pullRequests.delete(name); | ||
} | ||
get type() { | ||
return this.owner.type; | ||
} | ||
async refId(ref) { | ||
return undefined; | ||
} | ||
get rateLimitReached() { | ||
return this.provider.rateLimitReached; | ||
} | ||
set rateLimitReached(value) { | ||
this.provider.rateLimitReached(value); | ||
} | ||
async _initialize() {} | ||
get repositoryClass() { | ||
return this.provider.repositoryClass; | ||
} | ||
get pullRequestClass() { | ||
return this.provider.pullRequestClass; | ||
} | ||
get branchClass() { | ||
return this.provider.branchClass; | ||
} | ||
get contentClass() { | ||
return this.provider.contentClass; | ||
} | ||
toString() { | ||
return this.name; | ||
} | ||
}); | ||
); | ||
@@ -375,2 +621,17 @@ const {Readable} = stream; | ||
/** | ||
* Representation of one file or directory entry | ||
* All paths are asolute (no leading '/') and build with '/' | ||
* @property {string} path file name inside of the repository | ||
* @property {string|Buffer|Stream} content | ||
* @property {string} type type of the content | ||
* @property {string} mode file permissions | ||
* @property {string} sha sha of the content | ||
* | ||
* @param {string} path file name inside of the repository | ||
* @param {string|Buffer|Stream} content | ||
* @param {string} type type of the content | ||
* @param {string} mode file permissions | ||
* @param {string} sha sha of the content | ||
*/ | ||
class Content { | ||
@@ -380,13 +641,22 @@ static get TYPE_BLOB() { | ||
} | ||
static get TYPE_TREE() { | ||
return "tree"; | ||
} | ||
constructor(path, content = undefined, type = Content.TYPE_BLOB, mode = "100644", sha) { | ||
constructor( | ||
path, | ||
content = undefined, | ||
type = Content.TYPE_BLOB, | ||
mode = "100644", | ||
sha | ||
) { | ||
if (path[0] === "/" || path.indexOf("\\") >= 0) { | ||
throw new TypeError(`Paths should not contain leading '/' or any '\\': ${path}`); | ||
throw new TypeError( | ||
`Paths should not contain leading '/' or any '\\': ${path}` | ||
); | ||
} | ||
Object.defineProperties(this, { | ||
path: { | ||
value: path | ||
}, | ||
path: { value: path }, | ||
content: { | ||
@@ -408,16 +678,25 @@ get() { | ||
}, | ||
type: { | ||
value: type | ||
}, | ||
mode: { | ||
value: mode | ||
} | ||
type: { value: type }, | ||
mode: { value: mode } | ||
}); | ||
} | ||
/** | ||
* @return {boolean} true if content represents a directory | ||
*/ | ||
get isDirectory() { | ||
return this.type === Content.TYPE_TREE; | ||
} | ||
/** | ||
* @return {boolean} true if content represents a blob (plain old file) | ||
*/ | ||
get isFile() { | ||
return this.type === Content.TYPE_BLOB; | ||
} | ||
/** | ||
* Deliver content as string | ||
* @return {string} content | ||
*/ | ||
toString() { | ||
@@ -427,10 +706,20 @@ if (typeof this.content === "string" || this.content instanceof String) { | ||
} | ||
if (Buffer.isBuffer(this.content)) { | ||
return this.content.toString("utf8"); | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Deliver content as stream | ||
* @return {ReadableStream} content | ||
*/ | ||
async getReadStream() { | ||
return this.content instanceof stream.Stream ? this.content : toReadableStream(this.content); | ||
return this.content instanceof stream.Stream | ||
? this.content | ||
: toReadableStream(this.content); | ||
} | ||
toJSON() { | ||
@@ -444,6 +733,18 @@ return { | ||
} | ||
/** | ||
* compare against other content | ||
* @param {Content} other | ||
* @return {boolean} true if other describes the same content | ||
*/ | ||
equals(other) { | ||
if (other === undefined || this.path !== other.path || this.type !== other.type || this.mode !== other.mode) { | ||
if ( | ||
other === undefined || | ||
this.path !== other.path || | ||
this.type !== other.type || | ||
this.mode !== other.mode | ||
) { | ||
return false; | ||
} | ||
if (Buffer.isBuffer(this.content)) { | ||
@@ -454,5 +755,12 @@ if (Buffer.isBuffer(other.content)) { | ||
} | ||
return this.toString() === other.toString(); | ||
} | ||
} | ||
/** | ||
* Create empty content (file) | ||
* @param {string} path | ||
* @return {Content} | ||
*/ | ||
function emptyContent(path, options) { | ||
@@ -462,26 +770,72 @@ return new Content(path, ""); | ||
/** | ||
* Abstract pull request | ||
* {@link Repository#addPullRequest} | ||
* @param {Branch} source | ||
* @param {Branch} destination | ||
* @param {string} name | ||
* @param {Object} options | ||
* @param {string} [options.title] | ||
* @param {string} [options.state] | ||
* @param {boolean} [options.merged] | ||
* @param {boolean} [options.locked] | ||
* @property {string} name | ||
* @property {Branch} source | ||
* @property {Branch} destination | ||
* @property {string} [title] | ||
* @property {string} [state] | ||
* @property {boolean} [merged] | ||
* @property {boolean} [locked] | ||
*/ | ||
class PullRequest { | ||
static get defaultOptions() { | ||
return { | ||
/** | ||
* internal id. | ||
* @return {string} | ||
*/ | ||
id: undefined, | ||
/** | ||
* the one line description of the pull request. | ||
* @return {string} | ||
*/ | ||
title: undefined, | ||
/** | ||
* the description of the pull request. | ||
* @return {string} | ||
*/ | ||
body: undefined, | ||
/** | ||
* state of the pull request. | ||
* @return {string} | ||
*/ | ||
state: undefined, | ||
/** | ||
* locked state of the pull request. | ||
* @return {boolean} | ||
*/ | ||
locked: false, | ||
/** | ||
* merged state of the pull request. | ||
* @return {boolean} | ||
*/ | ||
merged: false | ||
}; | ||
} | ||
constructor(source, destination, name, options) { | ||
const properties = { | ||
name: { | ||
value: name | ||
}, | ||
source: { | ||
value: source | ||
}, | ||
destination: { | ||
value: destination | ||
} | ||
name: { value: name }, | ||
source: { value: source }, | ||
destination: { value: destination } | ||
}; | ||
propertiesFromOptions(properties, options, this.constructor.defaultOptions); | ||
let merged = properties.merged.value; | ||
@@ -496,2 +850,3 @@ properties.merged = { | ||
}; | ||
let state = properties.state.value; | ||
@@ -506,23 +861,48 @@ properties.state = { | ||
}; | ||
Object.defineProperties(this, properties); | ||
destination.addPullRequest(this); | ||
} | ||
get repository() { | ||
return this.destination.repository; | ||
} | ||
/** | ||
* @return {Provider} | ||
*/ | ||
get provider() { | ||
return this.destination.provider; | ||
} | ||
/** | ||
* Delete the pull request from the {@link Repository}. | ||
* @see {@link Repository#deletePullRequest} | ||
* @return {Promise} | ||
*/ | ||
async delete() { | ||
return this.destination.deletePullRequest(this.name); | ||
} | ||
/** | ||
* Merge the pull request | ||
*/ | ||
async merge() { | ||
return notImplementedError(); | ||
} | ||
/** | ||
* Decline the pull request | ||
*/ | ||
async decline() { | ||
return notImplementedError(); | ||
} | ||
toString() { | ||
return `${this.name}: ${this.title}, state: ${this.state}, merged: ${this.merged}`; | ||
return `${this.name}: ${this.title}, state: ${this.state}, merged: ${ | ||
this.merged | ||
}`; | ||
} | ||
toJSON() { | ||
@@ -540,89 +920,194 @@ return { | ||
const Owner = OneTimeInititalizerMixin(class Owner { | ||
static get defaultOptions() { | ||
return {}; | ||
} | ||
constructor() { | ||
Object.defineProperties(this, { | ||
repositories: { | ||
value: new Map() | ||
/** | ||
* Collection of repositories | ||
* @property {Map<string,Repository>} repositories | ||
*/ | ||
const Owner = OneTimeInititalizerMixin( | ||
class Owner { | ||
/** | ||
* options | ||
*/ | ||
static get defaultOptions() { | ||
return {}; | ||
} | ||
constructor() { | ||
Object.defineProperties(this, { | ||
repositories: { value: new Map() } | ||
}); | ||
} | ||
/** | ||
* @return {Class} repository class used by the Provider | ||
*/ | ||
get repositoryClass() { | ||
return Repository; | ||
} | ||
/** | ||
* @return {Class} branch class used by the Provider | ||
*/ | ||
get branchClass() { | ||
return Branch; | ||
} | ||
/** | ||
* @return {Class} content class used by the Provider | ||
*/ | ||
get contentClass() { | ||
return Content; | ||
} | ||
/** | ||
* @return {Class} pull request class used by the Provider | ||
*/ | ||
get pullRequestClass() { | ||
return PullRequest; | ||
} | ||
/** | ||
* Delete a repository | ||
* @param {string} name | ||
* @return {Promise<undefined>} | ||
*/ | ||
async deleteRepository(name) { | ||
await this.initialize(); | ||
this.repositories.delete(name); | ||
} | ||
/** | ||
* Lookup a repository | ||
* @param {string} name of the repository may contain a #branch | ||
* @return {Promise<Repository>} | ||
*/ | ||
async repository(name, options) { | ||
if (name === undefined) { | ||
return undefined; | ||
} | ||
}); | ||
} | ||
get repositoryClass() { | ||
return Repository; | ||
} | ||
get branchClass() { | ||
return Branch; | ||
} | ||
get contentClass() { | ||
return Content; | ||
} | ||
get pullRequestClass() { | ||
return PullRequest; | ||
} | ||
async deleteRepository(name) { | ||
await this.initialize(); | ||
this.repositories.delete(name); | ||
} | ||
async repository(name, options) { | ||
if (name === undefined) { | ||
return undefined; | ||
const [repoName, branchName] = name.split(/#/); | ||
await this.initialize(); | ||
return this.repositories.get(repoName); | ||
} | ||
const [repoName, branchName] = name.split(/#/); | ||
await this.initialize(); | ||
return this.repositories.get(repoName); | ||
} | ||
async createRepository(name, options) { | ||
await this.initialize(); | ||
const repository = new this.repositoryClass(this, name, options); | ||
this.repositories.set(repository.name, repository); | ||
return repository; | ||
} | ||
async branch(name, options) { | ||
if (name === undefined) { | ||
return undefined; | ||
/** | ||
* Create a new repository | ||
* @param {string} name | ||
* @param {Object} options | ||
* @return {Promise<Repository>} | ||
*/ | ||
async createRepository(name, options) { | ||
await this.initialize(); | ||
const repository = new this.repositoryClass(this, name, options); | ||
this.repositories.set(repository.name, repository); | ||
return repository; | ||
} | ||
const [repoName, branchName] = name.split(/#/); | ||
const repository = await this.repository(repoName); | ||
if (repository === undefined) { | ||
return undefined; | ||
/** | ||
* Lookup a branch | ||
* First lookup repository then the branch | ||
* If no branch was specified then the default branch will be delivered. | ||
* @see {@link Repository#defaultBranch} | ||
* @param {string} name with optional branch name as '#myBranchName' | ||
* @return {Promise<Branch|undefined>} | ||
*/ | ||
async branch(name, options) { | ||
if (name === undefined) { | ||
return undefined; | ||
} | ||
const [repoName, branchName] = name.split(/#/); | ||
const repository = await this.repository(repoName); | ||
if (repository === undefined) { | ||
return undefined; | ||
} | ||
return branchName === undefined | ||
? repository.defaultBranch | ||
: repository.branch(branchName); | ||
} | ||
return branchName === undefined ? repository.defaultBranch : repository.branch(branchName); | ||
/** | ||
* Deliver the repository type | ||
* @return {string} 'git' | ||
*/ | ||
get type() { | ||
return "git"; | ||
} | ||
async _initialize() {} | ||
} | ||
get type() { | ||
return "git"; | ||
} | ||
async _initialize() {} | ||
}); | ||
); | ||
/** | ||
* Abstract repository as a collection | ||
* @param {Provider} provider | ||
* @param {string} name of the group | ||
* @param {Object} options | ||
* @param {string} [options.description] human readable description | ||
* @param {string} [options.id] internal id | ||
* | ||
* @property {Provider} provider | ||
* @property {string} name | ||
*/ | ||
class RepositoryGroup extends Owner { | ||
static get defaultOptions() { | ||
return Object.assign({}, super.defaultOptions, { | ||
/** | ||
* the description of the repository group. | ||
* @return {string} | ||
*/ | ||
description: undefined, | ||
/** | ||
* unique id within the provider. | ||
* @return {string} | ||
*/ | ||
id: undefined | ||
}); | ||
} | ||
constructor(provider, name, options) { | ||
super(); | ||
const properties = { | ||
name: { | ||
value: name | ||
}, | ||
provider: { | ||
value: provider | ||
} | ||
name: { value: name }, | ||
provider: { value: provider } | ||
}; | ||
propertiesFromOptions(properties, options, this.constructor.defaultOptions); | ||
Object.defineProperties(this, properties); | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get repositoryClass() { | ||
return this.provider.repositoryClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get branchClass() { | ||
return this.provider.branchClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get contentClass() { | ||
return this.provider.contentClass; | ||
} | ||
/** | ||
* By default we use the providers implementation. | ||
* @return {Class} as defined in the provider | ||
*/ | ||
get pullRequestClass() { | ||
@@ -633,25 +1118,58 @@ return this.provider.pullRequestClass; | ||
/** | ||
* Base repository provider acts as a source of repositories | ||
* @param {Object} options | ||
* @property {Map<string,RepositoryGroup>} repositoryGroups | ||
* @property {Object} config | ||
*/ | ||
class Provider extends Owner { | ||
/** | ||
* Default configuration options | ||
* @return {Object} | ||
*/ | ||
static get defaultOptions() { | ||
return {}; | ||
} | ||
/** | ||
* Extract options suitable for the constructor | ||
* form the given set of environment variables | ||
* @param {Object} env | ||
* @return {Object} undefined if no suitable environment variables have been found | ||
*/ | ||
static optionsFromEnvironment(env) { | ||
return undefined; | ||
} | ||
/** | ||
* Pepare configuration by mixing together defaultOptions with actual options | ||
* @param {Object} config raw config | ||
* @return {Object} combined options | ||
*/ | ||
static options(config) { | ||
return Object.assign(this.defaultOptions, config); | ||
} | ||
constructor(options) { | ||
super(); | ||
const properties = { | ||
config: { | ||
// TODO ret rid of config | ||
value: this.constructor.options(options) | ||
}, | ||
repositoryGroups: { | ||
value: new Map() | ||
} | ||
repositoryGroups: { value: new Map() } | ||
}; | ||
propertiesFromOptions(properties, options, this.constructor.defaultOptions); | ||
Object.defineProperties(this, properties); | ||
} | ||
/** | ||
* Lookup a repository group | ||
* @param {string} name of the group | ||
* @param {Object} options | ||
* @return {Promise<RepositoryGroup>} | ||
*/ | ||
async repositoryGroup(name, options) { | ||
@@ -664,2 +1182,9 @@ if (name === undefined) { | ||
} | ||
/** | ||
* Create a new repository group | ||
* @param {string} name | ||
* @param {Object} options | ||
* @return {Promise<RepositoryGroup>} | ||
*/ | ||
async createRepositoryGroup(name, options) { | ||
@@ -672,8 +1197,18 @@ await this.initialize(); | ||
} | ||
/** | ||
* Lookup a repository in the provider and all of its repository groups | ||
* @param {string} name of the repository | ||
* @param {Object} options | ||
* @return {Promise<Repository>} | ||
*/ | ||
async repository(name, options) { | ||
await this.initialize(); | ||
const r = await super.repository(name, options); | ||
if (r !== undefined) { | ||
return r; | ||
} | ||
for (const p of this.repositoryGroups.values()) { | ||
@@ -685,10 +1220,21 @@ const r = await p.repository(name, options); | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Lookup a branch in the provider and all of its repository groups | ||
* @param {string} name of the branch | ||
* @param {Object} options | ||
* @return {Promise<Branch>} | ||
*/ | ||
async branch(name, options) { | ||
await this.initialize(); | ||
const r = await super.branch(name, options); | ||
if (r !== undefined) { | ||
return r; | ||
} | ||
for (const p of this.repositoryGroups.values()) { | ||
@@ -700,16 +1246,38 @@ const r = await p.branch(name, options); | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* @return {Class} repository group class used by the Provider | ||
*/ | ||
get repositoryGroupClass() { | ||
return RepositoryGroup; | ||
} | ||
/** | ||
* Is our rate limit reached. | ||
* By default we have no rate limit | ||
* @return {boolean} always false | ||
*/ | ||
get rateLimitReached() { | ||
return false; | ||
} | ||
/** | ||
* Deliver the provider name | ||
* @return {string} class name by default | ||
*/ | ||
get name() { | ||
return this.constructor.name; | ||
} | ||
/** | ||
* we are our own provider | ||
* @return {Provider} this | ||
*/ | ||
get provider() { | ||
return this; | ||
} | ||
toString() { | ||
@@ -716,0 +1284,0 @@ return this.name; |
{ | ||
"name": "repository-provider", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"publishConfig": { | ||
@@ -8,3 +8,3 @@ "access": "public" | ||
"main": "dist/provider.js", | ||
"module": "src/provider.js", | ||
"module": "src/provider.mjs", | ||
"description": "abstract interface to git repository providers like github bitbucket", | ||
@@ -23,11 +23,9 @@ "keywords": [ | ||
"scripts": { | ||
"cover": "nyc --temp-directory build/nyc ava", | ||
"cover": "c8 --temp-directory build/coverage ava && c8 report -r lcov --temp-directory build/coverage", | ||
"test": "ava", | ||
"pretest": "rollup -c tests/rollup.config.js", | ||
"precover": "rollup -c tests/rollup.config.js", | ||
"posttest": "npm run prepare && markdown-doctest", | ||
"docs": "documentation readme src/provider.js --section=API", | ||
"docs": "documentation readme src/provider.mjs --section=API", | ||
"semantic-release": "semantic-release", | ||
"prepare": "rollup -c", | ||
"lint": "documentation lint src/provider.js", | ||
"lint": "documentation lint src/provider.mjs", | ||
"travis-deploy-once": "travis-deploy-once" | ||
@@ -39,21 +37,18 @@ }, | ||
"devDependencies": { | ||
"@babel/plugin-proposal-async-generator-functions": "^7.1.0", | ||
"ava": "^1.0.0-rc.1", | ||
"ava": "^1.0.0-rc.2", | ||
"documentation": "^8.1.2", | ||
"markdown-doctest": "^0.9.1", | ||
"nyc": "^13.1.0", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup": "^0.67.1", | ||
"rollup-plugin-cleanup": "^3.0.0", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-executable": "^1.3.0", | ||
"rollup-plugin-istanbul": "^2.0.1", | ||
"rollup-plugin-json": "^3.1.0", | ||
"rollup-plugin-multi-entry": "^2.0.2", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"semantic-release": "^15.10.7", | ||
"travis-deploy-once": "^5.0.9" | ||
"semantic-release": "^15.12.0", | ||
"travis-deploy-once": "^5.0.9", | ||
"c8": "^3.2.1", | ||
"esm": "^3.0.84" | ||
}, | ||
"engines": { | ||
"node": ">=10.10" | ||
"node": ">=10.13" | ||
}, | ||
@@ -72,21 +67,13 @@ "repository": { | ||
"files": [ | ||
"build/*-test.js" | ||
"tests/*-test.js", | ||
"tests/*-test.mjs" | ||
], | ||
"require": [ | ||
"babel-register" | ||
"esm" | ||
], | ||
"extensions": [ | ||
"js", | ||
"mjs" | ||
] | ||
}, | ||
"nyc": { | ||
"include": [ | ||
"build/*-test.js", | ||
"src/**/*.js" | ||
], | ||
"reporter": [ | ||
"lcov" | ||
], | ||
"report-dir": "./build/coverage" | ||
}, | ||
"xo": { | ||
"space": true | ||
}, | ||
"template": { | ||
@@ -93,0 +80,0 @@ "repository": { |
345
README.md
@@ -66,51 +66,2 @@ [![npm](https://img.shields.io/npm/v/repository-provider.svg)](https://www.npmjs.com/package/repository-provider) | ||
- [Parameters](#parameters-6) | ||
- [Branch](#branch-1) | ||
- [Parameters](#parameters-7) | ||
- [Properties](#properties-1) | ||
- [defaultOptions](#defaultoptions-1) | ||
- [defaultOptions](#defaultoptions-2) | ||
- [defaultOptions](#defaultoptions-3) | ||
- [OneTimeInititalizer](#onetimeinititalizer) | ||
- [Owner](#owner) | ||
- [Properties](#properties-2) | ||
- [Repository](#repository-1) | ||
- [Parameters](#parameters-8) | ||
- [Properties](#properties-3) | ||
- [description](#description) | ||
- [description](#description-1) | ||
- [id](#id) | ||
- [id](#id-1) | ||
- [id](#id-2) | ||
- [PullRequest](#pullrequest) | ||
- [Parameters](#parameters-9) | ||
- [Properties](#properties-4) | ||
- [provider](#provider-2) | ||
- [delete](#delete) | ||
- [merge](#merge) | ||
- [decline](#decline) | ||
- [title](#title) | ||
- [body](#body) | ||
- [state](#state) | ||
- [locked](#locked) | ||
- [merged](#merged) | ||
- [RepositoryGroup](#repositorygroup-1) | ||
- [Parameters](#parameters-10) | ||
- [Properties](#properties-5) | ||
- [repositoryClass](#repositoryclass) | ||
- [branchClass](#branchclass) | ||
- [contentClass](#contentclass) | ||
- [pullRequestClass](#pullrequestclass) | ||
- [Content](#content) | ||
- [Parameters](#parameters-11) | ||
- [Properties](#properties-6) | ||
- [isDirectory](#isdirectory) | ||
- [isFile](#isfile) | ||
- [toString](#tostring) | ||
- [getReadStream](#getreadstream) | ||
- [equals](#equals) | ||
- [Parameters](#parameters-12) | ||
- [emptyContent](#emptycontent) | ||
- [Parameters](#parameters-13) | ||
- [propertiesFromOptions](#propertiesfromoptions) | ||
- [Parameters](#parameters-14) | ||
@@ -129,3 +80,3 @@ ## Provider | ||
- `repositoryGroups` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [RepositoryGroup](#repositorygroup)>** | ||
- `repositoryGroups` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), RepositoryGroup>** | ||
- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
@@ -142,3 +93,3 @@ | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[RepositoryGroup](#repositorygroup)>** | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<RepositoryGroup>** | ||
@@ -154,3 +105,3 @@ ### createRepositoryGroup | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[RepositoryGroup](#repositorygroup)>** | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<RepositoryGroup>** | ||
@@ -166,3 +117,3 @@ ### repository | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Repository](#repository)>** | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<Repository>** | ||
@@ -178,3 +129,3 @@ ### branch | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Branch](#branch)>** | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<Branch>** | ||
@@ -231,288 +182,2 @@ ### repositoryGroupClass | ||
## Branch | ||
- **See: [Repository#addBranch](Repository#addBranch)** | ||
Abstract branch | ||
### Parameters | ||
- `repository` **[Repository](#repository)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
### Properties | ||
- `repository` **[Repository](#repository)** | ||
- `provider` **[Provider](#provider)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## defaultOptions | ||
options | ||
## defaultOptions | ||
options | ||
## defaultOptions | ||
options | ||
## OneTimeInititalizer | ||
enshures that \_initialize() will be called only once | ||
## Owner | ||
Collection of repositories | ||
### Properties | ||
- `repositories` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Repository](#repository)>** | ||
## Repository | ||
Abstract repository | ||
### Parameters | ||
- `owner` **[Owner](#owner)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (#branch) will be removed | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `options.description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable description | ||
- `options.id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** internal id | ||
### Properties | ||
- `owner` **[Owner](#owner)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** without (#branch) | ||
- `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** from options.description | ||
- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** from options.id | ||
- `branches` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Branch](#branch)>** | ||
- `pullRequests` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [PullRequest](#pullrequest)>** | ||
## description | ||
the description of the repository content. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## description | ||
the description of the repository group. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## id | ||
unique id within the provider. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## id | ||
internal id. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## id | ||
unique id within the provider. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## PullRequest | ||
Abstract pull request | ||
[Repository#addPullRequest](Repository#addPullRequest) | ||
### Parameters | ||
- `source` **[Branch](#branch)** | ||
- `destination` **[Branch](#branch)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `options.title` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** | ||
- `options.state` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** | ||
- `options.merged` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** | ||
- `options.locked` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** | ||
### Properties | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `source` **[Branch](#branch)** | ||
- `destination` **[Branch](#branch)** | ||
- `title` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** | ||
- `state` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** | ||
- `merged` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** | ||
- `locked` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** | ||
### provider | ||
Returns **[Provider](#provider)** | ||
### delete | ||
- **See: [Repository#deletePullRequest](Repository#deletePullRequest)** | ||
Delete the pull request from the [Repository](#repository). | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** | ||
### merge | ||
Merge the pull request | ||
### decline | ||
Decline the pull request | ||
## title | ||
the one line description of the pull request. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## body | ||
the description of the pull request. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## state | ||
state of the pull request. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## locked | ||
locked state of the pull request. | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** | ||
## merged | ||
merged state of the pull request. | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** | ||
## RepositoryGroup | ||
**Extends Owner** | ||
Abstract repository as a collection | ||
### Parameters | ||
- `provider` **[Provider](#provider)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of the group | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `options.description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable description | ||
- `options.id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** internal id | ||
### Properties | ||
- `provider` **[Provider](#provider)** | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
### repositoryClass | ||
By default we use the providers implementation. | ||
Returns **Class** as defined in the provider | ||
### branchClass | ||
By default we use the providers implementation. | ||
Returns **Class** as defined in the provider | ||
### contentClass | ||
By default we use the providers implementation. | ||
Returns **Class** as defined in the provider | ||
### pullRequestClass | ||
By default we use the providers implementation. | ||
Returns **Class** as defined in the provider | ||
## Content | ||
Representation of one file or directory entry | ||
All paths are asolute (no leading '/') and build with '/' | ||
### Parameters | ||
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file name inside of the repository | ||
- `content` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html) \| [Stream](https://nodejs.org/api/stream.html))** (optional, default `undefined`) | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of the content (optional, default `Content.TYPE_BLOB`) | ||
- `mode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file permissions (optional, default `"100644"`) | ||
- `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sha of the content | ||
### Properties | ||
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file name inside of the repository | ||
- `content` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html) \| [Stream](https://nodejs.org/api/stream.html))** | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of the content | ||
- `mode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file permissions | ||
- `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sha of the content | ||
### isDirectory | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if content represents a directory | ||
### isFile | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if content represents a blob (plain old file) | ||
### toString | ||
Deliver content as string | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** content | ||
### getReadStream | ||
Deliver content as stream | ||
Returns **ReadableStream** content | ||
### equals | ||
compare against other content | ||
#### Parameters | ||
- `other` **[Content](#content)** | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other describes the same content | ||
## emptyContent | ||
Create empty content (file) | ||
### Parameters | ||
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `options` | ||
Returns **[Content](#content)** | ||
## propertiesFromOptions | ||
- **See: Object.definedProperties()** | ||
create properties from options and default options | ||
### Parameters | ||
- `properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** where the properties will be stored | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `defaultOptions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
# install | ||
@@ -519,0 +184,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13
2240
69458
187
1