Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Commit 266b00f

Browse files
committed
feat(ci): added esdoc documentation generation, travis generation, auto deployment
hosted on https://github-issues-label-sync-package.superleap.xyz closes #10
1 parent 81584fc commit 266b00f

5 files changed

Lines changed: 96 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,4 @@ $RECYCLE.BIN/
214214
jsx/
215215
material-ui/
216216
svg/
217+
.publish/

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ before_install:
1515
- npm i -g gulp
1616
- npm i -g bithound
1717
before_script:
18+
- if (( "${TRAVIS_NODE_VERSION}" >= 6 )) && [ "$TRAVIS_BRANCH" = "master" ]; then export COVERAGE_REPORT=true; fi;
1819
- npm prune
1920
after_success:
2021
- npm run semantic-release
22+
- npm run deploy
2123
branches:
2224
except:
2325
- /^v\d+\.\d+\.\d+$/

gulpfile.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
"use strict";
2+
var paths = {
3+
"pkg": "./package.json",
4+
"docs": `./build/docs`
5+
};
6+
var fs = require('fs');
27
var exec = require('child_process').exec;
38
var path = require('path');
9+
var pkg = require('read-package-json');
410
var gulp = require('gulp');
511
var nsp = require('gulp-nsp');
12+
var esdoc = require("gulp-esdoc");
13+
var ghPages = require("gulp-gh-pages");
614

715
gulp.task('nsp', function (cb) {
816
nsp({package: path.resolve('package.json')}, cb);
@@ -19,4 +27,32 @@ gulp.task('bithound', function () {
1927
});
2028
});
2129

30+
gulp.task('doc', function (cb) {
31+
var config = {
32+
"destination": paths.docs,
33+
"title": "GitHub Issues Label Sync Module"
34+
};
35+
36+
return gulp.src('./lib')
37+
.pipe(esdoc(config));
38+
});
39+
40+
gulp.task('predeploy', ['doc'], function () {
41+
pkg(paths.pkg, console.log, true, function (error, data) {
42+
var pkgName = data.name;
43+
var pkgUser = data.repository.url.match(/github\.com\/([^\/]+)\//i)[1];
44+
45+
return fs.writeFile(`${paths.docs}/CNAME`, `${pkgName}-package.${pkgUser}.xyz`);
46+
});
47+
});
48+
49+
gulp.task('deploy', ['predeploy'], function () {
50+
if (!process.env.COVERAGE_REPORT) {
51+
return;
52+
}
53+
54+
return gulp.src(`${paths.docs}/**/*`)
55+
.pipe(ghPages());
56+
});
57+
2258
gulp.task('prepublish', ['nsp', 'bithound']);

lib/LabelSync.js

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
let GitHubApi = require("github");
22
let 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;

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"scripts": {
99
"test": "",
10+
"deploy": "gulp deploy",
1011
"prepublish": "gulp prepublish",
1112
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
1213
},
@@ -38,16 +39,20 @@
3839
"bithound": "^1.3.0",
3940
"commitizen": "^2.8.2",
4041
"cz-conventional-changelog": "^1.1.6",
42+
"esdoc": "^0.4.7",
4143
"gulp": "^3.9.1",
4244
"gulp-codecov": "^2.0.2",
45+
"gulp-esdoc": "^0.2.0",
4346
"gulp-eslint": "^3.0.1",
4447
"gulp-exclude-gitignore": "^1.0.0",
48+
"gulp-gh-pages": "^0.5.4",
4549
"gulp-istanbul": "^1.0.0",
4650
"gulp-mocha": "^2.2.0",
4751
"gulp-nsp": "^2.4.1",
4852
"gulp-plumber": "^1.1.0",
4953
"mocha": "^2.5.3",
5054
"nsp": "^2.5.0",
55+
"read-package-json": "^2.0.4",
5156
"semantic-release": "^6.3.0"
5257
},
5358
"config": {

0 commit comments

Comments
 (0)