11let GitHubApi = require ( "github" ) ;
22let Promise = require ( 'bluebird' ) ;
33
4- class GithubSync {
4+ /**
5+ * Simple wrapper around the github module issues function
6+ * @access public
7+ */
8+ export default class GithubIssuesLabelSync {
9+ /**
10+ * The GitHub issue label model
11+ * @typedef {Object } Label
12+ * @property {String } Label.name - The name of the label
13+ * @property {String } [Label.color] - The colour of the label
14+ * @property {String } [Label.status] - Once a label operation is complete this field gets updated
15+ */
16+
517 /**
618 * In order to work as an NPM module this class has to be called with specific parameters
719 * @example
@@ -22,173 +34,166 @@ class GithubSync {
2234 * };
2335 * let {user, repo, token, options} = config.github;
2436 * let labels = [];
25- * Array .from(JSON.parse(fs.readFileSync('./.issuesrc', 'utf8')).categories).forEach((category) => {
37+ * array .from(JSON.parse(fs.readFileSync('./.issuesrc', 'utf8')).categories).forEach((category) => {
2638 * category.labels.forEach((label) => {
2739 * label.name = `${category.name}: ${label.name}`;
2840 * labels.push(label);
2941 * });
3042 * });
31- * let githubSync = new (require('./lib/GithubSync '))(options, user, repo, token);
32- * @param {Object } options - GitHubApi connect options
33- * @param {string } user - GitHub repository user
34- * @param {string } repo - GitHub repository name
35- * @param {string } token - GitHub personal access token
43+ * let githubSync = new (require('./lib/LabelSync '))(options, user, repo, token);
44+ * @param {Object } [ options={}] - GitHubApi connect options
45+ * @param {String } user - GitHub repository user
46+ * @param {String } repo - GitHub repository name
47+ * @param {String } token - GitHub personal access token
3648 */
3749 constructor ( options = { } , user , repo , token ) {
3850 this . options = options ;
3951 this . user = user ;
4052 this . repo = repo ;
4153 this . token = token ;
4254 this . github = new GitHubApi ( this . options ) ;
43- /**
44- * Async calls to this.getLabels() get logged here
45- * @type {Array }
46- */
47- this . labels = [ ] ;
48- /**
49- * Async calls to this.deleteLabels() get logged here
50- * @type {Array }
51- */
55+ this . _labels = [ ] ;
5256 this . _deletedLabels = [ ] ;
53- /**
54- * Async calls to this.createLabels() get logged here
55- * @type {Array }
56- */
5757 this . _createdLabels = [ ] ;
5858
5959 this . authenticate ( ) ;
6060 }
6161
6262 /**
6363 * Get GitHubApi module connect options
64- * @returns {Object }
64+ * @type {Object }
6565 */
6666 get options ( ) {
6767 return this . _options ;
6868 }
6969
7070 /**
7171 * Get GitHub repository username
72- * @returns {String }
72+ * @type {String }
7373 */
7474 get user ( ) {
7575 return this . _user ;
7676 }
7777
7878 /**
7979 * Get GitHub repository name
80- * @returns {String }
80+ * @type {String }
8181 */
8282 get repo ( ) {
8383 return this . _repo ;
8484 }
8585
8686 /**
8787 * Get GitHub repository token
88- * @returns {String }
88+ * @type {String }
8989 */
9090 get token ( ) {
9191 return this . _token ;
9292 }
9393
9494 /**
9595 * Get GitHubApi module
96- * @returns {GitHubApi|module.exports }
96+ * @link github/Client
97+ * @type {github/Client|module.exports }
9798 */
9899 get github ( ) {
99100 return this . _github ;
100101 }
101102
102103 /**
103104 * Get GitHub repository labels
104- * @returns {Array }
105+ * @type {Array<GithubIssuesLabelSync.Label> }
105106 */
106107 get labels ( ) {
107108 return this . _labels ;
108109 }
109110
110111 /**
111112 * Get GitHubApi repository deleted labels
112- * @returns {Array }
113+ * @type {Array<GithubIssuesLabelSync.Label> }
113114 */
114115 get deletedLabels ( ) {
115116 return this . _deletedLabels ;
116117 }
117118
118119 /**
119120 * Get GitHubApi repository created labels
120- * @returns {Array }
121+ * @type {Array<GithubIssuesLabelSync.Label> }
121122 */
122123 get createdLabels ( ) {
123124 return this . _createdLabels ;
124125 }
125126
126127 /**
127128 * Set GitHubApi module connect options
128- * @param {Object } object
129+ * @type {Object }
130+ * @property {Boolean } [options.debug=false] - Get request information with each call
131+ * @property {Boolean } [options.followRedirects=false] - We don't need this for issues
132+ * @property {Promise } Promise - We are using bluebird promises peering with github api package
129133 */
130134 set options ( object ) {
131135 this . _options = object ;
132136 }
133137
134138 /**
135139 * Set GitHubApi repository username
136- * @param {String } repoUrlUser
140+ * @type {String }
137141 */
138142 set user ( repoUrlUser ) {
139143 this . _user = repoUrlUser ;
140144 }
141145
142146 /**
143147 * Set GitHubApi repository name
144- * @param {String } repoUrlName
148+ * @type {String }
145149 */
146150 set repo ( repoUrlName ) {
147151 this . _repo = repoUrlName ;
148152 }
149153
150154 /**
151155 * Set GitHubApi OAuth2 personal access token
152- * @param {String } personalAccessToken
156+ * @type {String }
153157 */
154158 set token ( personalAccessToken ) {
155159 this . _token = personalAccessToken ;
156160 }
157161
158162 /**
159163 * Set GitHubApi Client
160- * @param { GitHubApi |module.exports } Client
164+ * @type { github/Client |module.exports }
161165 */
162166 set github ( Client ) {
163167 this . _github = Client ;
164168 }
165169
166170 /**
167171 * Set GitHubApi repository labels
168- * @param {Array } labels
172+ * @type {Array<GithubIssuesLabelSync.Label> }
169173 */
170174 set labels ( labels ) {
171175 this . _labels = labels ;
172176 }
173177
174178 /**
175179 * Push GitHubApi repository deleted label
176- * @param { Object } label
180+ * @type { GithubIssuesLabelSync.Label }
177181 */
178182 set deletedLabel ( label ) {
179183 this . _deletedLabels . push ( label ) ;
180184 }
181185
182186 /**
183187 * Push GitHubApi repository created label
184- * @param { Object } label
188+ * @type { GithubIssuesLabelSync.Label }
185189 */
186190 set createdLabel ( label ) {
187191 this . _createdLabels . push ( label ) ;
188192 }
189193
190194 /**
191195 * We only do this once
196+ * @access private
192197 */
193198 authenticate ( ) {
194199 this . github . authenticate ( {
@@ -205,7 +210,7 @@ class GithubSync {
205210 * console.log(response);
206211 * });
207212 * @async
208- * @param {Boolean } meta
213+ * @param {Boolean } [ meta=false] - Get extended response information
209214 * @returns {Promise }
210215 */
211216 getLabels ( meta = false ) {
@@ -233,7 +238,8 @@ class GithubSync {
233238 * console.log(githubSync.createdLabels);
234239 * });
235240 * @async
236- * @param {Object } label
241+ * @param {GithubIssuesLabelSync.Label } label - The label we want to delete
242+ * @param {String } label.name - The label's name
237243 * @returns {Promise }
238244 */
239245 deleteLabel ( label ) {
@@ -266,7 +272,7 @@ class GithubSync {
266272 * console.log(githubSync.deletedLabels);
267273 * });
268274 * @async
269- * @param {Array } labels
275+ * @param {Array<GithubIssuesLabelSync.Label> } labels - The labels we want to delete
270276 * @returns {Promise }
271277 */
272278 deleteLabels ( labels ) {
@@ -285,7 +291,10 @@ class GithubSync {
285291 * console.log(githubSync.createdLabels);
286292 * });
287293 * @async
288- * @param {Object } label
294+ * @param {GithubIssuesLabelSync.Label } label - The label we want to create
295+ * @param {String } label.name - The label's name
296+ * @param {String } label.color - The label's colour
297+ * @param {String } label.status - Promise status of operation
289298 * @returns {Promise }
290299 */
291300 createLabel ( label ) {
@@ -324,7 +333,7 @@ class GithubSync {
324333 * console.log(githubSync.createdLabels);
325334 * });
326335 * @async
327- * @param {Array } labels
336+ * @param {Array<GithubIssuesLabelSync.Label> } labels - The labels we want to create
328337 * @returns {Promise }
329338 */
330339 createLabels ( labels ) {
@@ -363,8 +372,8 @@ class GithubSync {
363372 * console.log(githubSync.createdLabels);
364373 * });
365374 * @async
366- * @param {Array } labels
367- * @param {Boolean } purge
375+ * @param {Array<GithubIssuesLabelSync.Label> } labels - The labels we want to import
376+ * @param {Boolean } [ purge=false] - Wether to delete all existing tags on remote or not
368377 * @returns {Promise }
369378 */
370379 importLabels ( labels , purge = true ) {
@@ -373,5 +382,3 @@ class GithubSync {
373382 } ) ;
374383 }
375384}
376-
377- module . exports = GithubSync ;
0 commit comments