-
Notifications
You must be signed in to change notification settings - Fork 0
/
Organization.mjs
121 lines (109 loc) · 4.65 KB
/
Organization.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @file
* @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
* @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
* Github.js is freely distributable.
*/
import Requestable from './Requestable.mjs';
/**
* Organization encapsulates the functionality to create repositories in organizations
*/
class Organization extends Requestable {
/**
* Create a new Organization
* @param {string} organization - the name of the organization
* @param {Requestable.auth} [auth] - information required to authenticate to Github
* @param {string} [apiBase=https://api.github.com] - the base Github API URL
*/
constructor(organization, auth, apiBase) {
super(auth, apiBase);
this.__name = organization;
}
/**
* Create a repository in an organization
* @see https://developer.github.com/v3/repos/#create
* @param {Object} options - the repository definition
* @param {Requestable.callback} [cb] - will receive the created repository
* @return {Promise} - the promise for the http request
*/
createRepo(options, cb) {
return this._request('POST', `/orgs/${this.__name}/repos`, options, cb);
}
/**
* List the repositories in an organization
* @see https://developer.github.com/v3/repos/#list-organization-repositories
* @param {Requestable.callback} [cb] - will receive the list of repositories
* @return {Promise} - the promise for the http request
*/
getRepos(cb) {
let requestOptions = this._getOptionsWithDefaults({direction: 'desc'});
return this._requestAllPages(`/orgs/${this.__name}/repos`, requestOptions, cb);
}
/**
* Query if the user is a member or not
* @param {string} username - the user in question
* @param {Requestable.callback} [cb] - will receive true if the user is a member
* @return {Promise} - the promise for the http request
*/
isMember(username, cb) {
return this._request204or404(`/orgs/${this.__name}/members/${username}`, null, cb);
}
/**
* List the users who are members of the company
* @see https://developer.github.com/v3/orgs/members/#members-list
* @param {object} options - filtering options
* @param {string} [options.filter=all] - can be either `2fa_disabled` or `all`
* @param {string} [options.role=all] - can be one of: `all`, `admin`, or `member`
* @param {Requestable.callback} [cb] - will receive the list of users
* @return {Promise} - the promise for the http request
*/
listMembers(options, cb) {
return this._request('GET', `/orgs/${this.__name}/members`, options, cb);
}
/**
* List the Teams in the Organization
* @see https://developer.github.com/v3/orgs/teams/#list-teams
* @param {Requestable.callback} [cb] - will receive the list of teams
* @return {Promise} - the promise for the http request
*/
getTeams(cb) {
return this._requestAllPages(`/orgs/${this.__name}/teams`, undefined, cb);
}
/**
* Create a team
* @see https://developer.github.com/v3/orgs/teams/#create-team
* @param {object} options - Team creation parameters
* @param {string} options.name - The name of the team
* @param {string} [options.description] - Team description
* @param {string} [options.repo_names] - Repos to add the team to
* @param {string} [options.privacy=secret] - The level of privacy the team should have. Can be either one
* of: `secret`, or `closed`
* @param {Requestable.callback} [cb] - will receive the created team
* @return {Promise} - the promise for the http request
*/
createTeam(options, cb) {
return this._request('POST', `/orgs/${this.__name}/teams`, options, cb);
}
/**
* Get information about all projects
* @see https://developer.github.com/v3/projects/#list-organization-projects
* @param {Requestable.callback} [cb] - will receive the list of projects
* @return {Promise} - the promise for the http request
*/
listProjects(cb) {
return this._requestAllPages(`/orgs/${this.__name}/projects`, {AcceptHeader: 'inertia-preview'}, cb);
}
/**
* Create a new project
* @see https://developer.github.com/v3/repos/projects/#create-a-project
* @param {Object} options - the description of the project
* @param {Requestable.callback} cb - will receive the newly created project
* @return {Promise} - the promise for the http request
*/
createProject(options, cb) {
options = options || {};
options.AcceptHeader = 'inertia-preview';
return this._request('POST', `/orgs/${this.__name}/projects`, options, cb);
}
}
export default Organization;