Skip to content

Commit be5a708

Browse files
Release 0.2.0
1 parent c36047a commit be5a708

File tree

9 files changed

+237
-121
lines changed

9 files changed

+237
-121
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [v0.2.0](https://github.com/seegno/github-labels/tree/v0.2.0) (2018-06-25)
4+
[Full Changelog](https://github.com/seegno/github-labels/compare/v0.1.1...v0.2.0)
5+
6+
**Merged pull requests:**
7+
8+
- Update eslint dependencies [\#45](https://github.com/seegno/github-labels/pull/45) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
9+
- Fix lint-staged configuration [\#44](https://github.com/seegno/github-labels/pull/44) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
10+
- Remove node 4 support [\#43](https://github.com/seegno/github-labels/pull/43) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
11+
- Update program options [\#42](https://github.com/seegno/github-labels/pull/42) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
12+
- Add list command [\#40](https://github.com/seegno/github-labels/pull/40) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
13+
- Add pre-commit dependency [\#39](https://github.com/seegno/github-labels/pull/39) ([nunorafaelrocha](https://github.com/nunorafaelrocha))
14+
315
## [v0.1.1](https://github.com/seegno/github-labels/tree/v0.1.1) (2017-08-20)
416
[Full Changelog](https://github.com/seegno/github-labels/compare/v0.1.0...v0.1.1)
517

dist/bin/labels.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
var _copyFromRepoCommand = require('../commands/copy-from-repo-command');
55

6+
var _listCommand = require('../commands/list-command');
7+
68
var _updateCommand = require('../commands/update-command');
79

810
var _package = require('../../package.json');
@@ -17,9 +19,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1719
* Program options.
1820
*/
1921

22+
_yargs2.default // eslint-disable-line no-unused-expressions
23+
.usage('Usage: $0 [options]').env('GITHUB_LABELS').command(['*', 'update'], 'Update repository labels', _updateCommand.updateConfig, _updateCommand.update).command('copy', 'Copy labels from repository', _copyFromRepoCommand.copyFromRepoConfig, _copyFromRepoCommand.copyFromRepo).command('list', 'List labels from repository', _listCommand.listConfig, _listCommand.list).help('h').alias('h', 'help').version('version', 'Version', _package.version).alias('V', 'version').wrap(null).argv;
24+
2025
/**
2126
* Module dependencies.
22-
*/
23-
24-
_yargs2.default // eslint-disable-line no-unused-expressions
25-
.usage('Usage: $0 [options]').env('GITHUB_LABELS').command(['*', 'update'], 'Update repository labels', _updateCommand.updateConfig, _updateCommand.update).command('copy', 'Copy labels from repository', _copyFromRepoCommand.copyFromRepoConfig, _copyFromRepoCommand.copyFromRepo).help('h').alias('h', 'help').version('version', 'Version', _package.version).alias('V', 'version').wrap(null).argv;
27+
*/

dist/client.js

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ Object.defineProperty(exports, "__esModule", {
55
});
66

77
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8-
/**
9-
* Module dependencies.
10-
*/
118

129
var _lodash = require('lodash');
1310

1411
var _github = require('github');
1512

1613
var _github2 = _interopRequireDefault(_github);
1714

18-
var _bluebird = require('bluebird');
19-
20-
var _bluebird2 = _interopRequireDefault(_bluebird);
21-
2215
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2316

24-
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new _bluebird2.default(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return _bluebird2.default.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
17+
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
18+
19+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
20+
/**
21+
* Module dependencies.
22+
*/
2523

2624
/**
2725
* GitHub configuration.
@@ -35,6 +33,20 @@ const config = {
3533
version: '3.0.0'
3634
};
3735

36+
/**
37+
* Get repository owner and name and include a validation.
38+
*/
39+
40+
const getRepositoryOptions = repository => {
41+
const [owner, repo] = repository.split('/');
42+
43+
if (!owner || !repo) {
44+
throw new Error('Malformed repository option');
45+
}
46+
47+
return { owner, repo };
48+
};
49+
3850
/**
3951
* Export `Client`.
4052
*/
@@ -45,36 +57,30 @@ class Client {
4557
* Constructor.
4658
*/
4759

48-
constructor({ owner, repo, options }) {
49-
this.github = new _github2.default(_extends({}, config, options));
50-
this.owner = owner;
51-
this.repo = repo;
60+
constructor(_ref) {
61+
let { token } = _ref,
62+
options = _objectWithoutProperties(_ref, ['token']);
5263

53-
_bluebird2.default.promisifyAll(this.github.issues);
54-
_bluebird2.default.promisifyAll(this.github);
55-
}
56-
57-
/**
58-
* Authenticate.
59-
*/
64+
this.github = new _github2.default(_extends({}, config, options));
6065

61-
authenticate(token) {
6266
this.github.authenticate({ token, type: 'oauth' });
6367
}
6468

6569
/**
6670
* Create a new label with given `name` and `color`.
6771
*/
6872

69-
createLabel(name, color) {
73+
createLabel(repository, name, color) {
7074
var _this = this;
7175

7276
return _asyncToGenerator(function* () {
73-
return yield _this.github.issues.createLabelAsync({
77+
const { owner, repo } = getRepositoryOptions(repository);
78+
79+
return yield _this.github.issues.createLabel({
7480
color,
7581
name,
76-
owner: _this.owner,
77-
repo: _this.repo
82+
owner,
83+
repo
7884
});
7985
})();
8086
}
@@ -83,40 +89,42 @@ class Client {
8389
* Create or update a label with given `name`.
8490
*/
8591

86-
createOrUpdateLabel(name, color) {
92+
createOrUpdateLabel(repository, name, color) {
8793
var _this2 = this;
8894

8995
return _asyncToGenerator(function* () {
9096
let label = false;
9197

9298
try {
93-
label = yield _this2.getLabel(name);
99+
label = yield _this2.getLabel(repository, name);
94100
} catch (err) {
95101
if (!(0, _lodash.has)(err, 'code') || (0, _lodash.get)(err, 'code') !== 404) {
96102
throw err;
97103
}
98104
}
99105

100106
if (label) {
101-
return yield _this2.updateLabel(name, color);
107+
return yield _this2.updateLabel(repository, name, color);
102108
}
103109

104-
return yield _this2.createLabel(name, color);
110+
return yield _this2.createLabel(repository, name, color);
105111
})();
106112
}
107113

108114
/**
109115
* Delete label by given `name`.
110116
*/
111117

112-
deleteLabel(name) {
118+
deleteLabel(repository, name) {
113119
var _this3 = this;
114120

115121
return _asyncToGenerator(function* () {
116-
return yield _this3.github.issues.deleteLabelAsync({
122+
const { owner, repo } = getRepositoryOptions(repository);
123+
124+
return yield _this3.github.issues.deleteLabel({
117125
name,
118-
owner: _this3.owner,
119-
repo: _this3.repo
126+
owner,
127+
repo
120128
});
121129
})();
122130
}
@@ -125,13 +133,15 @@ class Client {
125133
* Get all repo labels.
126134
*/
127135

128-
getLabels() {
136+
getLabels(repository) {
129137
var _this4 = this;
130138

131139
return _asyncToGenerator(function* () {
132-
const result = yield _this4.github.issues.getLabelsAsync({
133-
owner: _this4.owner,
134-
repo: _this4.repo
140+
const { owner, repo } = getRepositoryOptions(repository);
141+
142+
const result = yield _this4.github.issues.getLabels({
143+
owner,
144+
repo
135145
});
136146

137147
return result.data;
@@ -142,14 +152,16 @@ class Client {
142152
* Get label by given `name`.
143153
*/
144154

145-
getLabel(name) {
155+
getLabel(repository, name) {
146156
var _this5 = this;
147157

148158
return _asyncToGenerator(function* () {
149-
return yield _this5.github.issues.getLabelAsync({
159+
const { owner, repo } = getRepositoryOptions(repository);
160+
161+
return yield _this5.github.issues.getLabel({
150162
name,
151-
owner: _this5.owner,
152-
repo: _this5.repo
163+
owner,
164+
repo
153165
});
154166
})();
155167
}
@@ -158,16 +170,18 @@ class Client {
158170
* Update an existing label with given `color`.
159171
*/
160172

161-
updateLabel(name, color) {
173+
updateLabel(repository, name, color) {
162174
var _this6 = this;
163175

164176
return _asyncToGenerator(function* () {
165-
return yield _this6.github.issues.updateLabelAsync({
177+
const { owner, repo } = getRepositoryOptions(repository);
178+
179+
return yield _this6.github.issues.updateLabel({
166180
color,
167181
name,
168182
oldname: name,
169-
owner: _this6.owner,
170-
repo: _this6.repo
183+
owner,
184+
repo
171185
});
172186
})();
173187
}
@@ -176,28 +190,29 @@ class Client {
176190
* Set labels.
177191
*/
178192

179-
setLabels(labels) {
193+
setLabels(repository, labels) {
180194
var _this7 = this;
181195

182196
return _asyncToGenerator(function* () {
183-
const current = yield _this7.getLabels();
197+
const current = yield _this7.getLabels(repository);
184198

185199
// Delete current labels that are not included in the wanted labels.
186200
const deprecated = (0, _lodash.differenceBy)(current, labels, 'name');
187201

188-
for (const _ref of deprecated) {
189-
const { name } = _ref;
202+
for (const _ref2 of deprecated) {
203+
const { name } = _ref2;
190204

191-
yield _this7.deleteLabel(name);
205+
yield _this7.deleteLabel(repository, name);
192206
}
193207

194208
// Create or update wanted labels.
195-
for (const _ref2 of labels) {
196-
const { color, name } = _ref2;
209+
for (const _ref3 of labels) {
210+
const { color, name } = _ref3;
197211

198-
yield _this7.createOrUpdateLabel(name, color);
212+
yield _this7.createOrUpdateLabel(repository, name, color);
199213
}
200214
})();
201215
}
216+
202217
}
203218
exports.default = Client;

dist/commands/copy-from-repo-command.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,16 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
1414
let copyFromRepo = exports.copyFromRepo = (() => {
1515
var _ref = _asyncToGenerator(function* (args) {
1616
const questions = {
17-
sourceOwner: {
18-
message: 'What is the source owner name?',
19-
name: 'sourceOwner',
17+
source: {
18+
message: 'What is the source repository name? (ex. seegno/github-labels)',
19+
name: 'source',
2020
validate: function (input) {
2121
return !!input;
2222
}
2323
},
24-
sourceRepo: {
25-
message: 'What is the source repository name?',
26-
name: 'sourceRepo',
27-
validate: function (input) {
28-
return !!input;
29-
}
30-
},
31-
targetOwner: {
32-
message: 'What is the target owner name?',
33-
name: 'targetOwner',
34-
validate: function (input) {
35-
return !!input;
36-
}
37-
},
38-
targetRepo: {
39-
message: 'What is the target repository name?',
40-
name: 'targetRepo',
24+
target: {
25+
message: 'What is the target repository name? (ex. seegno/github-labels)',
26+
name: 'target',
4127
validate: function (input) {
4228
return !!input;
4329
}
@@ -57,9 +43,13 @@ let copyFromRepo = exports.copyFromRepo = (() => {
5743
console.log('Copying labels from repo...'); // eslint-disable-line no-console
5844
console.log(_prettyjson2.default.render((0, _lodash.pick)(options, (0, _lodash.keys)((0, _lodash.pickBy)(questions))))); // eslint-disable-line no-console
5945

60-
yield (0, _.copyLabelsFromRepo)(options);
46+
try {
47+
yield (0, _.copyLabelsFromRepo)(options);
6148

62-
return console.log('Copy completed!'); // eslint-disable-line no-console
49+
console.log('Copy completed!'); // eslint-disable-line no-console
50+
} catch (e) {
51+
console.error(e.message); // eslint-disable-line no-console
52+
}
6353
});
6454

6555
return function copyFromRepo(_x) {
@@ -93,5 +83,5 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
9383
*/
9484

9585
function copyFromRepoConfig(yargs) {
96-
yargs.option('sourceOwner', { demand: false, describe: 'Source repository owner', type: 'string' }).option('sourceRepo', { demand: false, describe: 'Source repository name', type: 'string' }).option('targetOwner', { demand: false, describe: 'Target repository owner', type: 'string' }).option('targetRepo', { demand: false, describe: 'Target repository name', type: 'string' }).option('token', { demand: true, describe: 'GitHub authentication token', type: 'string' }).example('$0 --owner foo --repo bar --sourceOwner qux --sourceRepo corge --token foobar');
86+
yargs.option('source', { demand: false, describe: 'Source repository name (ex. seegno/github-labels)', type: 'string' }).option('target', { demand: false, describe: 'Target repository name (ex. seegno/github-labels)', type: 'string' }).option('token', { demand: true, describe: 'GitHub authentication token', type: 'string' }).example('$0 --source foo/bar --target qux/corge --token foobar');
9787
}

0 commit comments

Comments
 (0)