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/project.js DELETED
@@ -1,88 +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 _inquirer = _interopRequireDefault(require("inquirer"));
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
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
- class Project extends _command.default {
27
- addOptions(program) {
28
- const cmd = program.command("project").description("Do things related to projects");
29
- cmd.command("list").description("Show the list of projects").action(async () => {
30
- const jira = new _jira.default(program);
31
- const projects = await jira.spin("Loading projects...", jira.api.listProjects());
32
- const table = new _cliTable.default({
33
- chars: jira.tableChars,
34
- head: ['Key', 'Name']
35
- });
36
- projects.forEach(project => table.push([_chalk.default.blue(project.key), project.name]));
37
- console.log(table.toString());
38
- });
39
- }
40
-
41
- static async pickProject(jira) {
42
- const meta = await jira.spin('Retrieving metadata...', jira.apiRequest('/issue/createmeta'));
43
- meta.projects.sort((a, b) => {
44
- if (a.key === jira.latestProject) {
45
- return -1;
46
- }
47
-
48
- if (b.key === jira.latestProject) {
49
- return 1;
50
- }
51
-
52
- return a.name > b.name;
53
- });
54
- const projectNames = [];
55
- const projectKeys = [];
56
- const issueTypes = [];
57
- meta.projects.forEach(project => {
58
- projectNames.push(project.name);
59
- projectKeys.push(project.key);
60
- issueTypes.push(project.issuetypes);
61
- });
62
- const projectQuestion = [{
63
- type: 'list',
64
- name: 'project',
65
- message: 'Project:',
66
- choices: projectNames,
67
- filter: name => {
68
- const pos = projectNames.indexOf(name);
69
- return {
70
- pos,
71
- name,
72
- key: projectKeys[pos]
73
- };
74
- }
75
- }];
76
- const projectAnswer = await _inquirer.default.prompt(projectQuestion);
77
- jira.latestProject = projectAnswer.project.key;
78
- jira.syncConfig();
79
- return _objectSpread({
80
- issueTypes: issueTypes[projectAnswer.project.pos]
81
- }, projectAnswer.project);
82
- }
83
-
84
- }
85
-
86
- ;
87
- var _default = Project;
88
- exports.default = _default;
package/dist/query.js DELETED
@@ -1,83 +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 Query extends _command.default {
25
- addOptions(program) {
26
- const cmd = program.command('query').description('Run a query').argument('<query>', 'The query').option('-l, --limit <limit>', `Set the query limit. Default ${DEFAULT_QUERY_LIMIT}`, DEFAULT_QUERY_LIMIT).action(async query => {
27
- const jira = new _jira.default(program);
28
- const opts = cmd.opts();
29
- let resultFields;
30
-
31
- try {
32
- resultFields = await _field.default.listFields(jira);
33
- } catch (e) {
34
- _errorhandler.default.showError(jira, e);
35
-
36
- return;
37
- }
38
-
39
- let expectedResult = opts.limit;
40
- let issues = [];
41
-
42
- while (issues.length < opts.limit) {
43
- let result;
44
-
45
- try {
46
- result = await jira.spin('Running query...', jira.api.searchJira(query, {
47
- startAt: issues.lengh,
48
- maxResults: opts.limit - issues.length
49
- }));
50
- } catch (e) {
51
- _errorhandler.default.showError(jira, e);
52
-
53
- return;
54
- }
55
-
56
- if (result.warningMessages) {
57
- _errorhandler.default.showWarningMessages(result.warningMessages);
58
-
59
- return;
60
- }
61
-
62
- issues = issues.concat(result.issues);
63
- if (issues.length >= result.total) break;
64
- }
65
-
66
- Query.showIssues(jira, issues, resultFields);
67
- });
68
- }
69
-
70
- static showIssues(jira, issues, fields) {
71
- const table = new _cliTable.default({
72
- chars: jira.tableChars,
73
- head: ['Key', 'Status', 'Type', 'Summary']
74
- });
75
- issues.forEach(issue => table.push([_chalk.default.blue(issue.key), _chalk.default.green(issue.fields.status.name), _chalk.default.green(issue.fields.issuetype.name), issue.fields.summary]));
76
- console.log(table.toString());
77
- }
78
-
79
- }
80
-
81
- ;
82
- var _default = Query;
83
- exports.default = _default;
package/dist/run.js DELETED
@@ -1,104 +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
- var _query = _interopRequireDefault(require("./query.js"));
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- const DEFAULT_QUERY_LIMIT = 20;
25
-
26
- class Run extends _command.default {
27
- addOptions(program) {
28
- const cmd = program.command('run').description('Run a preset').argument('<name>', 'The preset name').option('-l, --limit <limit>', `Set the query limit. Default ${DEFAULT_QUERY_LIMIT}`, DEFAULT_QUERY_LIMIT).action(async name => {
29
- const jira = new _jira.default(program);
30
- const opts = cmd.opts();
31
-
32
- if (!(name in jira.config.presets)) {
33
- console.log('This preset does not exist');
34
- return;
35
- }
36
-
37
- let query = jira.config.presets[name];
38
-
39
- for (let i = 2; i < program.args.length; ++i) {
40
- const arg = program.args[i];
41
-
42
- if (!query.includes("$$$")) {
43
- console.log("Too many aguments for this query");
44
- return;
45
- }
46
-
47
- query = query.replace('$$$', this.escape(arg));
48
- }
49
-
50
- if (query.includes("$$$")) {
51
- console.log("More arguments are needed");
52
- return;
53
- }
54
-
55
- let resultFields;
56
-
57
- try {
58
- resultFields = await _field.default.listFields(jira);
59
- } catch (e) {
60
- _errorhandler.default.showError(jira, e);
61
-
62
- return;
63
- }
64
-
65
- let expectedResult = opts.limit;
66
- let issues = [];
67
-
68
- while (issues.length < opts.limit) {
69
- let result;
70
-
71
- try {
72
- result = await jira.spin('Running query...', jira.api.searchJira(query, {
73
- startAt: issues.lengh,
74
- maxResults: opts.limit - issues.length
75
- }));
76
- } catch (e) {
77
- _errorhandler.default.showError(jira, e);
78
-
79
- return;
80
- }
81
-
82
- if (result.warningMessages) {
83
- _errorhandler.default.showWarningMessages(result.warningMessages);
84
-
85
- return;
86
- }
87
-
88
- issues = issues.concat(result.issues);
89
- if (issues.length >= result.total) break;
90
- }
91
-
92
- _query.default.showIssues(jira, issues, resultFields);
93
- });
94
- }
95
-
96
- escape(str) {
97
- return str.replace(/\"/g, '\\\"');
98
- }
99
-
100
- }
101
-
102
- ;
103
- var _default = Run;
104
- exports.default = _default;
package/dist/set.js DELETED
@@ -1,137 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _inquirer = _interopRequireDefault(require("inquirer"));
9
-
10
- var _command = _interopRequireDefault(require("./command.js"));
11
-
12
- var _field = _interopRequireDefault(require("./field.js"));
13
-
14
- var _jira = _interopRequireDefault(require("./jira.js"));
15
-
16
- var _errorhandler = _interopRequireDefault(require("./errorhandler.js"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
- class Set extends _command.default {
27
- addOptions(program) {
28
- const setCmd = program.command('set').description('Update fields in an issue');
29
- setCmd.command('assignee').description('Assign the issue to somebody').argument('<id>', 'The issue ID').action(async id => {
30
- const jira = new _jira.default(program);
31
- const userList = await User.pickUser(jira);
32
- const userNames = [];
33
- const userIds = [];
34
- userList.forEach(user => {
35
- if (user.active) {
36
- userNames.push(user.displayName);
37
- userIds.push(user.accountId);
38
- }
39
- });
40
- const assigneeQuestion = [{
41
- type: 'list',
42
- name: 'assignee',
43
- message: 'Assignee:',
44
- choices: userNames,
45
- filter: name => {
46
- const pos = userNames.indexOf(name);
47
- return {
48
- pos,
49
- name,
50
- id: userIds[pos]
51
- };
52
- }
53
- }];
54
- const assigneeAnswer = await _inquirer.default.prompt(assigneeQuestion);
55
- const issue = {
56
- fields: {
57
- assignee: {
58
- accountId: assigneeAnswer.assignee.id
59
- }
60
- }
61
- };
62
-
63
- try {
64
- await jira.spin('Updating the issue...', jira.api.updateIssue(id, issue));
65
- } catch (e) {
66
- _errorhandler.default.showError(jira, e);
67
- }
68
- });
69
- setCmd.command('status').description('Change the status').argument('<id>', 'The issue ID').action(async id => {
70
- const jira = new _jira.default(program);
71
- const transitionList = await jira.spin('Retrieving transitions...', jira.api.listTransitions(id));
72
- const transitionNames = [];
73
- const transitionIds = [];
74
- transitionList.transitions.forEach(transition => {
75
- transitionNames.push(transition.name);
76
- transitionIds.push(transition.id);
77
- });
78
- const transitionQuestion = [{
79
- type: 'list',
80
- name: 'transition',
81
- message: 'Status:',
82
- choices: transitionNames,
83
- filter: name => {
84
- const pos = transitionNames.indexOf(name);
85
- return {
86
- pos,
87
- name,
88
- id: transitionIds[pos]
89
- };
90
- }
91
- }];
92
- const transitionAnswer = await _inquirer.default.prompt(transitionQuestion);
93
- const transition = {
94
- transition: {
95
- id: transitionAnswer.transition.id
96
- }
97
- };
98
-
99
- try {
100
- await jira.spin('Updating the issue...', jira.api.transitionIssue(id, transition));
101
- } catch (e) {
102
- _errorhandler.default.showError(jira, e);
103
- }
104
- });
105
- setCmd.command('custom').description('Set a custom field').argument('<field>', 'The field name').argument('<id>', 'The issue ID').action(async (fieldName, id) => {
106
- const jira = new _jira.default(program);
107
- const fieldData = await _field.default.getFieldDataIfSupported(jira, fieldName);
108
-
109
- if (!fieldData) {
110
- console.log("Unsupported field type");
111
- return;
112
- }
113
-
114
- const question = [{
115
- type: fieldData.type,
116
- name: 'value',
117
- message: `${fieldName}:`
118
- }];
119
- const answer = await _inquirer.default.prompt(question);
120
- const data = {};
121
- data[fieldData.key] = answer.value;
122
-
123
- try {
124
- await jira.spin('Updating the issue...', jira.api.updateIssue(id, {
125
- fields: _objectSpread({}, data)
126
- }));
127
- } catch (e) {
128
- _errorhandler.default.showError(jira, e);
129
- }
130
- });
131
- }
132
-
133
- }
134
-
135
- ;
136
- var _default = Set;
137
- exports.default = _default;
package/dist/sprint.js DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _inquirer = _interopRequireDefault(require("inquirer"));
9
-
10
- var _cliTable = _interopRequireDefault(require("cli-table3"));
11
-
12
- var _command = _interopRequireDefault(require("./command.js"));
13
-
14
- var _jira = _interopRequireDefault(require("./jira.js"));
15
-
16
- var _errorhandler = _interopRequireDefault(require("./errorhandler.js"));
17
-
18
- var _project = _interopRequireDefault(require("./project.js"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- class Sprint extends _command.default {
23
- addOptions(program) {
24
- const sprintCmd = program.command('sprint').description('Play with sprints');
25
- sprintCmd.command('add').description('Add an issue to a sprint').argument('<id>', 'The issue ID').action(async id => {
26
- const jira = new _jira.default(program);
27
- const sprintId = await Sprint.pickSprint(jira);
28
-
29
- if (sprintId === 0) {
30
- console.log("No active sprints");
31
- return;
32
- }
33
-
34
- try {
35
- await jira.spin('Adding the issue to the sprint...', jira.apiAgileRequest(`/sprint/${sprintId}/issue`, {
36
- method: 'POST',
37
- followAllRedirects: true,
38
- body: {
39
- issues: [id]
40
- }
41
- }));
42
- } catch (e) {
43
- _errorhandler.default.showError(jira, e);
44
- }
45
- });
46
- sprintCmd.command('remove').description('Remove an issue from a sprint').argument('<id>', 'The issue ID').action(async id => {
47
- const jira = new _jira.default(program);
48
-
49
- try {
50
- await jira.spin('Adding the issue to the sprint...', jira.apiAgileRequest("/backlog/issue", {
51
- method: 'POST',
52
- followAllRedirects: true,
53
- body: {
54
- issues: [id]
55
- }
56
- }));
57
- } catch (e) {
58
- _errorhandler.default.showError(jira, e);
59
- }
60
- });
61
- }
62
-
63
- static async pickSprint(jira) {
64
- const project = await _project.default.pickProject(jira);
65
- const boardList = await jira.spin('Retrieving boards...', jira.api.getAllBoards(undefined, undefined, undefined, undefined, project.key));
66
- const boardNames = [];
67
- const boardIds = [];
68
- boardList.values.forEach(board => {
69
- boardNames.push(board.name);
70
- boardIds.push(board.id);
71
- });
72
- const boardQuestion = [{
73
- type: 'list',
74
- name: 'board',
75
- message: 'Board:',
76
- choices: boardNames,
77
- filter: name => {
78
- const pos = boardNames.indexOf(name);
79
- return {
80
- pos,
81
- name,
82
- id: boardIds[pos]
83
- };
84
- }
85
- }];
86
- const boardAnswer = await _inquirer.default.prompt(boardQuestion);
87
- const sprintList = await jira.spin('Retrieving sprints...', jira.api.getAllSprints(boardAnswer.board.id));
88
- const sprintNames = [];
89
- const sprintIds = [];
90
- sprintList.values.forEach(sprint => {
91
- if (sprint.state === 'active' || sprint.state === 'future') {
92
- sprintNames.push(sprint.name);
93
- sprintIds.push(sprint.id);
94
- }
95
- });
96
-
97
- if (sprintNames.length === 0) {
98
- return 0;
99
- }
100
-
101
- let sprintId = sprintIds[0];
102
-
103
- if (sprintNames.length > 1) {
104
- const sprintQuestion = [{
105
- type: 'list',
106
- name: 'sprint',
107
- message: 'Board:',
108
- choices: sprintNames,
109
- filter: name => {
110
- const pos = sprintNames.indexOf(name);
111
- return {
112
- pos,
113
- name,
114
- id: sprintIds[pos]
115
- };
116
- }
117
- }];
118
- const sprintAnswer = await _inquirer.default.prompt(sprintQuestion);
119
- sprintId = sprintAnswer.sprint.id;
120
- }
121
-
122
- return sprintId;
123
- }
124
-
125
- }
126
-
127
- ;
128
- var _default = Sprint;
129
- exports.default = _default;
package/dist/user.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _jira = _interopRequireDefault(require("./jira.js"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- class User {
13
- static async pickUser(jira) {
14
- const currentUser = await jira.spin('Retrieving current user...', jira.api.getCurrentUser());
15
- const userList = await jira.spin('Retrieving users...', jira.api.getUsers(0, 1000));
16
- userList.sort((a, b) => {
17
- if (a.accountId === currentUser.accountId) {
18
- return -1;
19
- }
20
-
21
- if (b.accountId === currentUser.accountId) {
22
- return 1;
23
- }
24
-
25
- return a.displayName > b.displayName;
26
- });
27
- return userList;
28
- }
29
-
30
- }
31
-
32
- ;
33
- var _default = User;
34
- exports.default = _default;