bjira 0.0.3 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/field.js DELETED
@@ -1,158 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _cliTable = _interopRequireDefault(require("cli-table3"));
11
-
12
- var _command = _interopRequireDefault(require("./command.js"));
13
-
14
- var _errorhandler = _interopRequireDefault(require("./errorhandler.js"));
15
-
16
- var _jira = _interopRequireDefault(require("./jira.js"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- class Field extends _command.default {
21
- addOptions(program) {
22
- const cmd = program.command("field").description("Do things related to issue fields");
23
- cmd.command("listall").description("Show the list of fields").action(async () => {
24
- const jira = new _jira.default(program);
25
- let resultFields;
26
-
27
- try {
28
- resultFields = await Field.listFields(jira);
29
- } catch (e) {
30
- _errorhandler.default.showError(jira, e);
31
-
32
- return;
33
- }
34
-
35
- const table = new _cliTable.default({
36
- chars: jira.tableChars,
37
- head: ['Name', 'Supported', 'Type']
38
- });
39
- resultFields.forEach(field => {
40
- var _field$schema, _field$schema2;
41
-
42
- const supported = Field.isSupported((_field$schema = field.schema) === null || _field$schema === void 0 ? void 0 : _field$schema.type);
43
- table.push([_chalk.default.blue(field.name), supported, supported ? (_field$schema2 = field.schema) === null || _field$schema2 === void 0 ? void 0 : _field$schema2.type : ""]);
44
- });
45
- console.log(table.toString());
46
- });
47
- cmd.command("add").description("Add a custom field to be shown").argument('<field>', 'The field name').action(async fieldName => {
48
- var _fieldData$schema;
49
-
50
- const jira = new _jira.default(program);
51
- let resultFields;
52
-
53
- try {
54
- resultFields = await Field.listFields(jira);
55
- } catch (e) {
56
- _errorhandler.default.showError(jira, e);
57
-
58
- return;
59
- }
60
-
61
- const fieldData = resultFields.find(field => field.name === fieldName);
62
-
63
- if (!fieldData) {
64
- console.log("Unknown field.");
65
- return;
66
- }
67
-
68
- if (!Field.isSupported((_fieldData$schema = fieldData.schema) === null || _fieldData$schema === void 0 ? void 0 : _fieldData$schema.type)) {
69
- console.log("Unsupported field.");
70
- return;
71
- }
72
-
73
- jira.addField(fieldName);
74
- jira.syncConfig();
75
- console.log('Config file succesfully updated');
76
- });
77
- cmd.command("remove").description("Remove a custom field").argument('<field>', 'The field name').action(async fieldName => {
78
- const jira = new _jira.default(program);
79
-
80
- if (!jira.fields.includes(fieldName)) {
81
- console.log("Unknown field.");
82
- return;
83
- }
84
-
85
- jira.removeField(fieldName);
86
- jira.syncConfig();
87
- console.log('Config file succesfully updated');
88
- });
89
- cmd.command("list").description("List the supported custom field").action(async () => {
90
- const jira = new _jira.default(program);
91
- const table = new _cliTable.default({
92
- chars: jira.tableChars,
93
- head: ['Name']
94
- });
95
- jira.fields.forEach(fieldName => table.push([_chalk.default.blue(fieldName)]));
96
- console.log(table.toString());
97
- });
98
- }
99
-
100
- static async listFields(jira) {
101
- return await jira.spin('Retrieving the fields...', jira.api.listFields());
102
- }
103
-
104
- static isSupported(fieldType) {
105
- return ["string", "number"].includes(fieldType);
106
- }
107
-
108
- static async getFieldDataIfSupported(jira, fieldName) {
109
- var _fieldData$schema2;
110
-
111
- let resultFields;
112
-
113
- try {
114
- resultFields = await Field.listFields(jira);
115
- } catch (e) {
116
- _errorhandler.default.showError(jira, e);
117
-
118
- return null;
119
- }
120
-
121
- let fieldData;
122
- resultFields.forEach(field => {
123
- if (field.name === fieldName) fieldData = field;
124
- });
125
-
126
- if (!fieldData) {
127
- console.log(`Unable to find the field "${fieldName}"`);
128
- return null;
129
- }
130
-
131
- if (!Field.isSupported((_fieldData$schema2 = fieldData.schema) === null || _fieldData$schema2 === void 0 ? void 0 : _fieldData$schema2.type)) {
132
- console.log("Unsupported field");
133
- return null;
134
- }
135
-
136
- let type;
137
-
138
- switch (fieldData.schema.type) {
139
- case 'number':
140
- type = 'number';
141
- break;
142
-
143
- case 'string':
144
- type = 'input';
145
- break;
146
- }
147
-
148
- return {
149
- type,
150
- key: fieldData.key
151
- };
152
- }
153
-
154
- }
155
-
156
- ;
157
- var _default = Field;
158
- exports.default = _default;
package/dist/index.js DELETED
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = _interopRequireDefault(require("commander"));
5
-
6
- var _fs = _interopRequireDefault(require("fs"));
7
-
8
- var _os = _interopRequireDefault(require("os"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _comment = _interopRequireDefault(require("./comment.js"));
13
-
14
- var _create = _interopRequireDefault(require("./create.js"));
15
-
16
- var _field = _interopRequireDefault(require("./field.js"));
17
-
18
- var _init = _interopRequireDefault(require("./init.js"));
19
-
20
- var _issue = _interopRequireDefault(require("./issue.js"));
21
-
22
- var _preset = _interopRequireDefault(require("./preset.js"));
23
-
24
- var _project = _interopRequireDefault(require("./project.js"));
25
-
26
- var _query = _interopRequireDefault(require("./query.js"));
27
-
28
- var _run = _interopRequireDefault(require("./run.js"));
29
-
30
- var _set = _interopRequireDefault(require("./set.js"));
31
-
32
- var _sprint = _interopRequireDefault(require("./sprint.js"));
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
- const DEFAULT_CONFIG_FILE = _path.default.join(_os.default.homedir(), ".jira.json");
37
-
38
- const commands = [new _comment.default(), new _create.default(), new _field.default(), new _init.default(), new _issue.default(), new _preset.default(), new _project.default(), new _query.default(), new _run.default(), new _set.default(), new _sprint.default()];
39
- /*
40
- const pjson = JSON.parse(fs.readFileSync(new URL("../package.json",
41
- import.meta.url)));
42
- program.version(pjson.version);
43
- */
44
-
45
- _commander.default.option('-c, --config <file>', `config file`, DEFAULT_CONFIG_FILE);
46
-
47
- commands.forEach(command => command.addOptions(_commander.default));
48
-
49
- _commander.default.parseAsync(process.argv);
package/dist/init.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _inquirer = _interopRequireDefault(require("inquirer"));
11
-
12
- var _fs = _interopRequireDefault(require("fs"));
13
-
14
- var _command = _interopRequireDefault(require("./command.js"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- class Init extends _command.default {
19
- addOptions(program) {
20
- program.command('init').description('Create the initial config file').action(async () => {
21
- const opts = program.opts();
22
- const questions = [{
23
- type: ' input',
24
- name: 'host',
25
- message: 'Provide your jira host:',
26
- default: 'example.atlassian.net'
27
- }, {
28
- type: 'input',
29
- name: 'username',
30
- message: 'Please provide your jira username:'
31
- }, {
32
- type: 'password',
33
- name: 'password',
34
- message: 'API token:'
35
- }, {
36
- type: 'confirm',
37
- name: 'protocol',
38
- message: 'Enable HTTPS Protocol?'
39
- }];
40
- const answers = await _inquirer.default.prompt(questions);
41
- const config = {
42
- jira: {
43
- protocol: answers.protocol ? 'https' : 'http',
44
- host: answers.host.trim(),
45
- username: answers.username.trim(),
46
- password: answers.password.trim(),
47
- apiVersion: '2',
48
- strictSSL: true
49
- },
50
- presets: {}
51
- };
52
-
53
- _fs.default.writeFileSync(opts.config, JSON.stringify(config, null, 2), 'utf8');
54
-
55
- console.log(`Config file succesfully created in: ${_chalk.default.green(opts.config)}`);
56
- });
57
- }
58
-
59
- }
60
-
61
- ;
62
- var _default = Init;
63
- exports.default = _default;
package/dist/issue.js DELETED
@@ -1,176 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _cliTable = _interopRequireDefault(require("cli-table3"));
11
-
12
- var _command = _interopRequireDefault(require("./command.js"));
13
-
14
- var _errorhandler = _interopRequireDefault(require("./errorhandler.js"));
15
-
16
- var _field = _interopRequireDefault(require("./field.js"));
17
-
18
- var _jira = _interopRequireDefault(require("./jira.js"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const DEFAULT_QUERY_LIMIT = 20;
23
-
24
- class Issue extends _command.default {
25
- static url(jira, id) {
26
- return `${jira.config.jira.protocol}://${jira.config.jira.host}/browse/${id}`;
27
- }
28
-
29
- addOptions(program) {
30
- const cmd = program.command('issue').description('Show an issue').option('-C, --comments').argument('<id>', 'The issue ID').action(async id => {
31
- var _issue$fields$Sprint;
32
-
33
- const jira = new _jira.default(program);
34
- let resultFields;
35
-
36
- try {
37
- resultFields = await _field.default.listFields(jira);
38
- } catch (e) {
39
- _errorhandler.default.showError(jira, e);
40
-
41
- return;
42
- }
43
-
44
- let result;
45
-
46
- try {
47
- result = await jira.spin('Running query...', jira.api.findIssue(id));
48
- } catch (e) {
49
- _errorhandler.default.showError(jira, e);
50
-
51
- return;
52
- }
53
-
54
- const issue = Issue.replaceFields(result, resultFields);
55
- let epicIssue = null;
56
-
57
- if (issue.fields['Epic Link']) {
58
- const epicResult = await jira.spin('Fetching the epic issue...', jira.api.findIssue(issue.fields['Epic Link']));
59
- epicIssue = Issue.replaceFields(epicResult, resultFields);
60
- }
61
-
62
- const table = new _cliTable.default({
63
- chars: jira.tableChars
64
- });
65
- table.push({
66
- 'Summary': issue.fields['Summary'].trim()
67
- }, {
68
- 'URL:': _chalk.default.blue(Issue.url(jira, id))
69
- }, {
70
- 'Status': _chalk.default.green(issue.fields['Status'].name)
71
- }, {
72
- 'Type': issue.fields['Issue Type'].name
73
- }, {
74
- 'Project': issue.fields['Project'].name + ' (' + issue.fields['Project'].key + ')'
75
- }, {
76
- 'Reporter': this.showUser(issue.fields['Reporter'])
77
- }, {
78
- 'Assignee': this.showUser(issue.fields['Assignee'])
79
- }, {
80
- 'Priority': issue.fields['Priority'].name
81
- }, {
82
- 'Epic Link': this.showEpicIssue(epicIssue)
83
- }, {
84
- 'Labels': issue.fields['Labels'].join(', ')
85
- }, {
86
- 'Sprint': (_issue$fields$Sprint = issue.fields['Sprint']) === null || _issue$fields$Sprint === void 0 ? void 0 : _issue$fields$Sprint.map(sprint => this.showSprint(sprint)).join(', ')
87
- });
88
- jira.fields.forEach(fieldName => {
89
- const data = {};
90
- data[fieldName] = issue.fields[fieldName] || "unset";
91
- table.push(data);
92
- });
93
- table.push({
94
- '': ''
95
- }, {
96
- 'Created on': issue.fields['Created']
97
- }, {
98
- 'Updated on': issue.fields['Updated']
99
- }, {
100
- '': ''
101
- }, {
102
- 'Description': issue.fields['Description']
103
- }, {
104
- '': ''
105
- }, {
106
- 'Comments': issue.fields['Comment'].total
107
- });
108
-
109
- if (cmd.opts().comments) {
110
- issue.fields['Comment'].comments.forEach(comment => {
111
- table.push({
112
- '': ''
113
- }, {
114
- 'Comment': _chalk.default.yellow(comment.id)
115
- }, {
116
- 'Author': this.showUser(comment.author)
117
- }, {
118
- 'Created on': comment['Created']
119
- }, {
120
- 'Updated on': comment['Updated']
121
- }, {
122
- 'Body': comment.body
123
- });
124
- });
125
- }
126
-
127
- console.log(table.toString());
128
- });
129
- }
130
-
131
- static replaceFields(obj, fields) {
132
- if (Array.isArray(obj)) {
133
- obj.forEach((o, pos) => {
134
- obj[o] = Issue.replaceFields(o, fields);
135
- });
136
- } else if (obj && typeof obj === "object") {
137
- Object.keys(obj).forEach(key => {
138
- if (obj[key] === null) {
139
- delete obj[key];
140
- return;
141
- }
142
-
143
- obj[key] = Issue.replaceFields(obj[key], fields);
144
- const field = fields.find(f => f.key == key);
145
-
146
- if (field) {
147
- obj[field.name] = obj[key];
148
- delete obj[key];
149
- }
150
- });
151
- }
152
-
153
- return obj;
154
- }
155
-
156
- showUser(user) {
157
- if (!user) return "(null)";
158
- let str = user.displayName;
159
- if (user.emailAddress) str += ` (${_chalk.default.yellow(user.emailAddress)})`;
160
- return str;
161
- }
162
-
163
- showEpicIssue(issue) {
164
- if (!issue) return "";
165
- return `${_chalk.default.blue(issue.key)} (${_chalk.default.yellow(issue.fields['Summary'].trim())})`;
166
- }
167
-
168
- showSprint(sprint) {
169
- return `${_chalk.default.blue(sprint.name)} (${_chalk.default.yellow(sprint.state)})`;
170
- }
171
-
172
- }
173
-
174
- ;
175
- var _default = Issue;
176
- exports.default = _default;
package/dist/jira.js DELETED
@@ -1,116 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _jiraClient = _interopRequireDefault(require("jira-client"));
9
-
10
- var _fs = _interopRequireDefault(require("fs"));
11
-
12
- var _ora = _interopRequireDefault(require("ora"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- class Jira {
17
- constructor(program) {
18
- const opts = program.opts();
19
- this.configFile = opts.config;
20
-
21
- if (!_fs.default.existsSync(this.configFile)) {
22
- console.log(`Config file ${this.configFile} does not exist.`);
23
- process.exit();
24
- return;
25
- }
26
-
27
- this._config = JSON.parse(_fs.default.readFileSync(this.configFile));
28
- this._jiraClient = new _jiraClient.default(this._config.jira);
29
- }
30
-
31
- get latestProject() {
32
- return this._config.latestProject || null;
33
- }
34
-
35
- set latestProject(latestProject) {
36
- this._config.latestProject = latestProject;
37
- }
38
-
39
- addField(fieldName) {
40
- if (!Array.isArray(this._config.fields)) this._config.fields = [];
41
-
42
- this._config.fields.push(fieldName);
43
- }
44
-
45
- removeField(fieldName) {
46
- if (!Array.isArray(this._config.fields) || this._config.fields.indexOf(fieldName) === -1) return;
47
-
48
- this._config.fields.splice(this._config.fields.indexOf(fieldName), 1);
49
- }
50
-
51
- get fields() {
52
- return this._config.fields || [];
53
- }
54
-
55
- get api() {
56
- return this._jiraClient;
57
- }
58
-
59
- get config() {
60
- return this._config;
61
- }
62
-
63
- get tableChars() {
64
- return {
65
- 'top': ' ',
66
- 'top-mid': '',
67
- 'top-left': '',
68
- 'top-right': '',
69
- 'bottom': ' ',
70
- 'bottom-mid': '',
71
- 'bottom-left': '',
72
- 'bottom-right': '',
73
- 'left': ' ',
74
- 'left-mid': '',
75
- 'mid': '',
76
- 'mid-mid': '',
77
- 'right': '',
78
- 'right-mid': '',
79
- 'middle': ' '
80
- };
81
- }
82
-
83
- async spin(msg, promise) {
84
- const spinner = (0, _ora.default)(msg).start();
85
-
86
- try {
87
- const result = await promise;
88
- return result;
89
- } catch (e) {
90
- throw e;
91
- } finally {
92
- spinner.stop();
93
- }
94
- }
95
-
96
- apiRequest(path, options = {}) {
97
- return this.api.doRequest(this.api.makeRequestHeader(this.api.makeUri({
98
- pathname: path
99
- }), options));
100
- }
101
-
102
- apiAgileRequest(path, options = {}) {
103
- return this.api.doRequest(this.api.makeRequestHeader(this.api.makeAgileUri({
104
- pathname: path
105
- }), options));
106
- }
107
-
108
- syncConfig() {
109
- _fs.default.writeFileSync(this.configFile, JSON.stringify(this.config, null, 2), 'utf8');
110
- }
111
-
112
- }
113
-
114
- ;
115
- var _default = Jira;
116
- exports.default = _default;
package/dist/preset.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _inquirer = _interopRequireDefault(require("inquirer"));
11
-
12
- var _cliTable = _interopRequireDefault(require("cli-table3"));
13
-
14
- var _command = _interopRequireDefault(require("./command.js"));
15
-
16
- var _jira = _interopRequireDefault(require("./jira.js"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- class Preset extends _command.default {
21
- addOptions(program) {
22
- const presetCmd = program.command('preset').description('Touch preset queries');
23
- presetCmd.command('create').description('create a new preset').argument('<name>', 'the name of the preset (use $$$ for variables)').argument('<query>', 'the query').action(async (name, query) => {
24
- const jira = new _jira.default(program);
25
-
26
- if (name in jira.config.presets) {
27
- console.log('This preset already exists');
28
- return;
29
- }
30
-
31
- jira.config.presets[name] = query;
32
- jira.syncConfig();
33
- console.log('Config file succesfully updated');
34
- });
35
- presetCmd.command('remove').description('remove a preset').argument('<name>', 'the name of the preest').action(async name => {
36
- const jira = new _jira.default(program);
37
- delete jira.config.presets[name];
38
- jira.syncConfig();
39
- console.log('Config file succesfully updated');
40
- });
41
- presetCmd.command('list').description('list the presets').action(async () => {
42
- const jira = new _jira.default(program);
43
- const table = new _cliTable.default({
44
- chars: jira.tableChars,
45
- head: ['Name', 'Query']
46
- });
47
- Object.keys(jira.config.presets).forEach(key => table.push([_chalk.default.blue(key), _chalk.default.green(jira.config.presets[key])]));
48
- console.log(table.toString());
49
- });
50
- }
51
-
52
- }
53
-
54
- ;
55
- var _default = Preset;
56
- exports.default = _default;