bjira 0.0.9 → 0.0.13

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.
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ the maintainer of the project.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Andrea Marchesini <baku@bnode.dev>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -69,4 +69,4 @@ If you want to see some of them in the issue report, add them:
69
69
  bjira field add "Story Points"
70
70
  ```
71
71
 
72
- Any custom fields added to the list will be shown in the issue report (See `bjira issue`).
72
+ Any custom fields added to the list will be shown in the issue report (See `bjira show`).
package/aqtinstall.log ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bjira",
3
- "version": "0.0.9",
3
+ "version": "0.0.13",
4
4
  "description": "A simple jira CLI tool",
5
5
  "main": "src/index.js",
6
6
  "author": {
@@ -26,7 +26,9 @@
26
26
  "dependencies": {
27
27
  "commander": "^8.2.0",
28
28
  "execa": "^5.1.1",
29
+ "fuzzy": "^0.1.3",
29
30
  "inquirer": "^8.2.0",
31
+ "inquirer-autocomplete-prompt": "^1.4.0",
30
32
  "jira-client": "^6.22.0",
31
33
  "ora": "^6.0.1",
32
34
  "temp": "^0.9.4"
package/src/ask.js CHANGED
@@ -1,4 +1,12 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import inquirer from 'inquirer';
6
+ import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt';
7
+ import fuzzy from 'fuzzy';
8
+
9
+ inquirer.registerPrompt('autocomplete', inquirerAutocompletePrompt);
2
10
 
3
11
  class Ask {
4
12
  static async askString(message, defaultValue = undefined) {
@@ -44,11 +52,12 @@ class Ask {
44
52
 
45
53
  static async askList(message, list) {
46
54
  const answer = await inquirer.prompt([{
47
- type: 'list',
55
+ type: 'autocomplete',
48
56
  name: 'value',
49
57
  message,
50
- choices: list,
51
- filter: name => list.indexOf(name),
58
+ source: (answers, input) => fuzzy.filter(input || '', list, {
59
+ extract: el => el.name
60
+ }).map(el => el.original),
52
61
  }]);
53
62
  return answer.value;
54
63
  }
package/src/command.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  class Command {
2
6
  addOptions(program) {}
3
7
  };
package/src/comment.js CHANGED
@@ -1,9 +1,10 @@
1
- import execa from 'execa';
2
- import fs from 'fs';
3
- import temp from 'temp';
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
4
 
5
5
  import Command from './command.js';
6
6
  import Jira from './jira.js';
7
+ import Utils from './utils.js';
7
8
 
8
9
  class Comment extends Command {
9
10
  addOptions(program) {
@@ -11,33 +12,11 @@ class Comment extends Command {
11
12
  .description('Add a comment to an issue')
12
13
  .argument('<id>', 'The issue ID')
13
14
  .action(async id => {
14
- temp.track();
15
-
16
- let file;
17
- try {
18
- file = temp.openSync('jira');
19
- } catch (e) {
20
- console.log("Failed to open a temporary file");
21
- return;
22
- }
23
-
24
- const code = await new Promise(resolve => {
25
- const subprocess = execa(process.env.EDITOR, [file.path], {
26
- detached: true,
27
- stdio: 'inherit',
28
- });
29
-
30
- subprocess.on('error', () => resolve(-1));
31
- subprocess.on('close', resolve);
32
- });
33
-
34
- if (code !== 0) {
35
- console.log("Failed to run the app");
15
+ const comment = await Utils.writeInTempFile();
16
+ if (!comment === null) {
36
17
  return;
37
18
  }
38
19
 
39
- let comment = fs.readFileSync(file.path);
40
- comment = comment.toString().trim();
41
20
  if (comment === "") {
42
21
  console.log("No comment message");
43
22
  return;
package/src/create.js CHANGED
@@ -1,13 +1,20 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import color from 'chalk';
2
6
 
3
7
  import Ask from './ask.js';
4
8
  import Command from './command.js';
9
+ import Field from './field.js';
5
10
  import Jira from './jira.js';
6
11
  import Issue from './issue.js';
7
12
  import Project from './project.js';
13
+ import Query from './query.js';
8
14
  import Set from './set.js';
9
15
  import Sprint from './sprint.js';
10
16
  import User from './user.js';
17
+ import Utils from './utils.js';
11
18
 
12
19
  class Create extends Command {
13
20
  addOptions(program) {
@@ -17,9 +24,15 @@ class Create extends Command {
17
24
  const jira = new Jira(program);
18
25
 
19
26
  const project = await Project.pickProject(jira);
20
- const issueTypePos = await Ask.askList('Issue type:', project.issueTypes.map(issueType => issueType.name));
27
+ const issueType = await Ask.askList('Issue type:',
28
+ project.issueTypes.map(issueType => ({
29
+ name: issueType.name,
30
+ value: {
31
+ name: issueType.name,
32
+ id: issueType.id
33
+ }
34
+ })));
21
35
 
22
- // Create the issue object
23
36
  const newIssue = {
24
37
  fields: {
25
38
  project: {
@@ -27,21 +40,34 @@ class Create extends Command {
27
40
  },
28
41
  summary: await Ask.askString('Summary:', 'New Issue'),
29
42
  issuetype: {
30
- id: project.issueTypes[issueTypePos].id
43
+ id: issueType.id
31
44
  }
32
45
  }
33
46
  };
34
47
 
35
- const description = await Ask.askString('Description:');
36
- if (description) {
37
- newIssue.fields.description = description;
48
+ if (await Ask.askBoolean('Do you want to write a description?')) {
49
+ const description = await Utils.writeInTempFile();
50
+ if (description) {
51
+ newIssue.fields.description = description;
52
+ }
38
53
  }
39
54
 
40
- if (project.issueTypes[issueTypePos].name === 'Task') {
41
- const parentIssue = await Ask.askString('Please provide the epic:');
42
- if (parentIssue !== '') {
55
+ if (issueType.name !== 'Epic' &&
56
+ await Ask.askBoolean('Do you want to set a parent epic?')) {
57
+ const epics = await Query.runQuery(jira, `project = "${project.key}" and type = "epic"`);
58
+ if (!epics || epics.length === 0) {
59
+ console.log("No epics yet.");
60
+ } else {
61
+ const resultFields = await Field.listFields(jira);
62
+ epics.forEach(epic => Issue.replaceFields(epic, resultFields));
63
+
64
+ const parentKey = await Ask.askList('Choose the epic:',
65
+ epics.map(epic => ({
66
+ name: `${epic.key} - ${epic.fields['Summary']}`,
67
+ value: epic.key
68
+ })));
43
69
  newIssue.fields.parent = {
44
- key: parentIssue
70
+ key: parentKey
45
71
  };
46
72
  }
47
73
  }
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Table from './table.js';
2
6
 
3
7
  class ErrorHandler {
@@ -6,10 +10,23 @@ class ErrorHandler {
6
10
  head: ['Errors']
7
11
  });
8
12
 
9
- e.error.errorMessages.forEach(error => table.addRow([{
10
- color: "blue",
11
- text: error
12
- }]));
13
+ if (typeof e.error === "string") {
14
+ table.addRow([{
15
+ color: "blue",
16
+ text: e.error
17
+ }]);
18
+ } else if ("errorMessages" in e.error) {
19
+ e.error.errorMessages.forEach(error => table.addRow([{
20
+ color: "blue",
21
+ text: error
22
+ }]));
23
+ } else {
24
+ table.addRow([{
25
+ color: "blue",
26
+ text: e.error
27
+ }]);
28
+ }
29
+
13
30
  console.log(table.toString());
14
31
  }
15
32
 
package/src/field.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Ask from './ask.js';
2
6
  import Command from './command.js';
3
7
  import Jira from './jira.js';
@@ -121,7 +125,7 @@ class Field extends Command {
121
125
  };
122
126
  case 'string':
123
127
  return {
124
- value: Ask.askString(`${fieldName}:`), key: fieldData.key
128
+ value: await Ask.askString(`${fieldName}:`), key: fieldData.key
125
129
  };
126
130
  }
127
131
 
package/src/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
4
+ //
5
+ // SPDX-License-Identifier: MIT
6
+
3
7
  import program from 'commander';
4
8
  import fs from 'fs';
5
9
  import os from 'os';
package/src/init.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import color from 'chalk';
2
6
  import fs from 'fs';
3
7
 
package/src/issue.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Command from './command.js';
2
6
  import Field from './field.js';
3
7
  import Jira from './jira.js';
@@ -11,9 +15,9 @@ class Issue extends Command {
11
15
  }
12
16
 
13
17
  addOptions(program) {
14
- const cmd = program.command('issue')
18
+ const cmd = program.command('show')
15
19
  .description('Show an issue')
16
- .option('-C, --comments')
20
+ .option('-C, --comments', 'Show the comments too')
17
21
  .argument('<id>', 'The issue ID')
18
22
  .action(async id => {
19
23
  const jira = new Jira(program);
package/src/jira.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import jiraClient from 'jira-client';
2
6
  import fs from 'fs';
3
7
  import ora from 'ora';
package/src/preset.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Command from './command.js';
2
6
  import Jira from './jira.js';
3
7
  import Table from './table.js';
package/src/project.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Ask from './ask.js';
2
6
  import Command from './command.js';
3
7
  import Jira from './jira.js';
@@ -31,23 +35,38 @@ class Project extends Command {
31
35
  jira.apiRequest('/issue/createmeta'));
32
36
 
33
37
  meta.projects.sort((a, b) => {
34
- if (a.key === jira.latestProject) {
38
+ if (a.name < b.name) {
35
39
  return -1;
36
40
  }
37
41
 
38
- if (b.key === jira.latestProject) {
42
+ if (a.name > b.name) {
39
43
  return 1;
40
44
  }
41
45
 
42
- return a.name > b.name;
46
+ return 0;
43
47
  });
44
48
 
45
- const projectPos = await Ask.askList('Project:', meta.projects.map(project => project.name));
46
- const project = meta.projects[projectPos];
49
+ const projects = [];
50
+ if (jira.latestProject) {
51
+ const latestProject = meta.projects.find(project => project.key === jira.latestProject);
52
+ if (latestProject) {
53
+ projects.push({
54
+ name: `Latest: ${latestProject.name}`,
55
+ value: latestProject.key
56
+ });
57
+ }
58
+ }
59
+
60
+ meta.projects.forEach(project => projects.push({
61
+ name: project.name,
62
+ value: project.key
63
+ }));
47
64
 
48
- jira.latestProject = project.key;
65
+ const projectKey = await Ask.askList('Project:', projects);
66
+ jira.latestProject = projectKey;
49
67
  jira.syncConfig();
50
68
 
69
+ const project = meta.projects.find(project => project.key === projectKey);
51
70
  return {
52
71
  name: project.name,
53
72
  key: project.key,
package/src/query.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Command from './command.js';
2
6
  import ErrorHandler from './errorhandler.js';
3
7
  import Field from './field.js';
@@ -20,25 +24,7 @@ class Query extends Command {
20
24
  const opts = cmd.opts();
21
25
 
22
26
  const resultFields = await Field.listFields(jira);
23
-
24
- let expectedResult = opts.limit;
25
- let issues = [];
26
-
27
- while (issues.length < opts.limit) {
28
- const result = await jira.spin('Running query...',
29
- jira.api.searchJira(query, {
30
- startAt: issues.lengh,
31
- maxResults: opts.limit - issues.length
32
- }));
33
-
34
- if (result.warningMessages) {
35
- ErrorHandler.showWarningMessages(result.warningMessages);
36
- return;
37
- }
38
-
39
- issues = issues.concat(result.issues);
40
- if (issues.length >= result.total) break;
41
- }
27
+ const issues = await Query.runQuery(jira, query, opts.limit);
42
28
 
43
29
  Query.showIssues(jira, issues, resultFields);
44
30
  });
@@ -67,6 +53,26 @@ class Query extends Command {
67
53
 
68
54
  console.log(table.toString());
69
55
  }
56
+
57
+ static async runQuery(jira, query, expectedResult) {
58
+ let issues = [];
59
+ while (issues.length < (expectedResult === undefined ? issues.length + 1 : expectedResult)) {
60
+ const result = await jira.spin('Running query...',
61
+ jira.api.searchJira(query, {
62
+ startAt: issues.lengh,
63
+ maxResults: expectedResult - issues.length
64
+ }));
65
+
66
+ if (result.warningMessages) {
67
+ ErrorHandler.showWarningMessages(result.warningMessages);
68
+ return;
69
+ }
70
+
71
+ issues = issues.concat(result.issues);
72
+ if (issues.length >= result.total) break;
73
+ }
74
+ return issues;
75
+ }
70
76
  };
71
77
 
72
78
  export default Query;
package/src/run.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Command from './command.js';
2
6
  import ErrorHandler from './errorhandler.js';
3
7
  import Field from './field.js';
@@ -40,25 +44,7 @@ class Run extends Command {
40
44
  }
41
45
 
42
46
  const resultFields = await Field.listFields(jira);
43
-
44
- let expectedResult = opts.limit;
45
- let issues = [];
46
-
47
- while (issues.length < opts.limit) {
48
- const result = await jira.spin('Running query...',
49
- jira.api.searchJira(query, {
50
- startAt: issues.lengh,
51
- maxResults: opts.limit - issues.length
52
- }));
53
-
54
- if (result.warningMessages) {
55
- ErrorHandler.showWarningMessages(result.warningMessages);
56
- return;
57
- }
58
-
59
- issues = issues.concat(result.issues);
60
- if (issues.length >= result.total) break;
61
- }
47
+ const issues = await Query.runQuery(jira, query, opts.limit);
62
48
 
63
49
  Query.showIssues(jira, issues, resultFields);
64
50
  });
package/src/set.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Ask from './ask.js';
2
6
  import Command from './command.js';
3
7
  import Field from './field.js';
@@ -16,6 +20,23 @@ class Set extends Command {
16
20
  await Set.assignIssue(jira, id);
17
21
  });
18
22
 
23
+ setCmd.command('unassign')
24
+ .description('Unassign the issue')
25
+ .argument('<id>', 'The issue ID')
26
+ .action(async id => {
27
+ const jira = new Jira(program);
28
+
29
+ const issue = {
30
+ fields: {
31
+ assignee: {
32
+ accountId: null
33
+ }
34
+ }
35
+ }
36
+
37
+ await jira.spin('Updating the issue...', jira.api.updateIssue(id, issue));
38
+ });
39
+
19
40
  setCmd.command('status')
20
41
  .description('Change the status')
21
42
  .argument('<id>', 'The issue ID')
@@ -37,12 +58,16 @@ class Set extends Command {
37
58
  static async assignIssue(jira, id) {
38
59
  const userList = await User.pickUser(jira);
39
60
  const activeUsers = userList.filter(user => user.active);
40
- const assignee = await Ask.askList('Assignee:', activeUsers.map(user => user.displayName));
61
+ const assigneeId = await Ask.askList('Assignee:',
62
+ activeUsers.map(user => ({
63
+ name: user.displayName,
64
+ value: user.accountId
65
+ })));
41
66
 
42
67
  const issue = {
43
68
  fields: {
44
69
  assignee: {
45
- accountId: activeUsers[assignee].accountId
70
+ accountId: assigneeId
46
71
  }
47
72
  }
48
73
  }
@@ -69,10 +94,14 @@ class Set extends Command {
69
94
 
70
95
  static async setStatus(jira, id) {
71
96
  const transitionList = await jira.spin('Retrieving transitions...', jira.api.listTransitions(id));
72
- const transitionPos = await Ask.askList('Status:', transitionList.transitions.map(transition => transition.name));
97
+ const transitionId = await Ask.askList('Status:',
98
+ transitionList.transitions.map(transition => ({
99
+ name: transition.name,
100
+ value: transition.id
101
+ })));
73
102
  const transition = {
74
103
  transition: {
75
- id: transitionList.transitions[transitionPos].id
104
+ id: transitionId
76
105
  }
77
106
  };
78
107
 
package/src/sprint.js CHANGED
@@ -1,7 +1,17 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ import color from 'chalk';
6
+
1
7
  import Ask from './ask.js';
2
8
  import Command from './command.js';
9
+ import Field from './field.js';
10
+ import Issue from './issue.js';
3
11
  import Jira from './jira.js';
4
12
  import Project from './project.js';
13
+ import Table from './table.js';
14
+ import User from './user.js';
5
15
 
6
16
  class Sprint extends Command {
7
17
  addOptions(program) {
@@ -30,6 +40,108 @@ class Sprint extends Command {
30
40
  }
31
41
  }));
32
42
  });
43
+
44
+ const showCmd = sprintCmd.command('show')
45
+ .description('Show the sprint')
46
+ .option('-a, --all', 'Show all the users')
47
+ .action(async () => {
48
+ const jira = new Jira(program);
49
+ const data = await Sprint.pickSprint(jira);
50
+ if (data === null) {
51
+ console.log("No active sprints");
52
+ return;
53
+ }
54
+
55
+ const resultFields = await Field.listFields(jira);
56
+
57
+ let issues = [];
58
+ while (true) {
59
+ const results = await jira.spin('Retrieving issues...',
60
+ jira.api.getBoardIssuesForSprint(data.boardId, data.sprintId, issues.length));
61
+ issues = issues.concat(results.issues);
62
+ if (issues.length >= results.total) break;
63
+ }
64
+
65
+ if (issues.length === 0) {
66
+ console.log("No issues");
67
+ return;
68
+ }
69
+
70
+ const statuses = [];
71
+
72
+ const users = [];
73
+ issues.forEach(issue => {
74
+ issue = Issue.replaceFields(issue, resultFields);
75
+
76
+ const accountId = issue.fields['Assignee'] ? issue.fields['Assignee'].accountId : null;
77
+ let user = users.find(user => user.accountId === accountId);
78
+ if (!user) {
79
+ user = {
80
+ accountId,
81
+ displayName: issue.fields['Assignee']?.displayName,
82
+ user: issue.fields['Assignee'],
83
+ statuses: []
84
+ };
85
+ users.push(user);
86
+ }
87
+
88
+ if (!statuses.includes(issue.fields['Status'].name)) {
89
+ statuses.push(issue.fields['Status'].name);
90
+ }
91
+
92
+ let status = user.statuses.find(status => issue.fields['Status'].name === status.name);
93
+ if (!status) {
94
+ status = {
95
+ name: issue.fields['Status'].name,
96
+ issues: []
97
+ };
98
+ user.statuses.push(status);
99
+ }
100
+
101
+ status.issues.push(issue);
102
+ });
103
+
104
+ const currentUser = await jira.spin('Retrieving current user...', jira.api.getCurrentUser());
105
+ const transitionList = await jira.spin('Retrieving transitions...', jira.api.listTransitions(issues[0].id));
106
+
107
+ console.log('\n' + color.blue(data.sprintName) + '\n');
108
+
109
+ let filteredUsers;
110
+ if (showCmd.opts().all) {
111
+ filteredUsers = User.sortUsers(currentUser, users);
112
+ } else {
113
+ filteredUsers = [users.find(user => user.accountId === currentUser.accountId)];
114
+ }
115
+
116
+ filteredUsers.forEach(user => {
117
+ console.log(color.yellow(Issue.showUser(user.user)));
118
+
119
+ const maxIssues = Math.max(...user.statuses.map(status => status.issues.length));
120
+
121
+ const statuses = user.statuses.sort((a, b) => {
122
+ const posA = transitionList.transitions.findIndex(transition => transition.name === a.name);
123
+ const posB = transitionList.transitions.findIndex(transition => transition.name === b.name);
124
+ return posA - posB;
125
+ });
126
+
127
+ const table = new Table({
128
+ head: statuses.map(status => status.name),
129
+ });
130
+
131
+ for (let i = 0; i < maxIssues; ++i) {
132
+ const line = statuses.map(status => {
133
+ if (status.issues.length > i) {
134
+ return `${status.issues[i].key} ${status.issues[i].fields['Summary'].trim()}`
135
+ }
136
+ return ""
137
+ });
138
+ table.addRow(line);
139
+ }
140
+
141
+ console.log(table.toString() + '\n');
142
+ });
143
+
144
+ });
33
145
  }
34
146
 
35
147
  static async pickSprint(jira) {
@@ -38,34 +150,53 @@ class Sprint extends Command {
38
150
  jira.api.getAllBoards(undefined, undefined, undefined, undefined,
39
151
  project.key));
40
152
 
41
- const boardPos = await Ask.askList('Board:', boardList.values.map(board => board.name));
153
+ const boardId = await Ask.askList('Board:',
154
+ boardList.values.map(board => ({
155
+ name: board.name,
156
+ value: board.id
157
+ })));
42
158
 
43
159
  const sprintList = await jira.spin('Retrieving sprints...',
44
- jira.api.getAllSprints(boardList.values[boardPos].id));
160
+ jira.api.getAllSprints(boardId));
45
161
 
46
162
  const sprints = sprintList.values.filter(sprint => sprint.state === 'active' || sprint.state === 'future');
47
163
 
48
164
  if (sprints.length === 0) {
49
- return 0;
165
+ return null;
50
166
  }
51
167
 
52
168
  if (sprints.length > 1) {
53
- const sprintPos = await Ask.askList('Sprint:', sprints.map(sprint => sprint.name));
54
- return sprints[sprintPos].id;
169
+ const sprintData = await Ask.askList('Sprint:',
170
+ sprints.map(sprint => ({
171
+ name: sprint.name,
172
+ value: {
173
+ id: sprint.id,
174
+ name: sprint.name
175
+ }
176
+ })));
177
+ return {
178
+ boardId,
179
+ sprintId: sprintData.id,
180
+ sprintName: sprintData.name,
181
+ };
55
182
  }
56
183
 
57
- return sprints[0].id;
184
+ return {
185
+ boardId,
186
+ sprintId: sprints[0].id,
187
+ sprintName: sprints[0].name,
188
+ };
58
189
  }
59
190
 
60
191
  static async add(jira, id) {
61
- const sprintId = await Sprint.pickSprint(jira);
62
- if (sprintId === 0) {
192
+ const data = await Sprint.pickSprint(jira);
193
+ if (data === null) {
63
194
  console.log("No active sprints");
64
195
  return;
65
196
  }
66
197
 
67
198
  await jira.spin('Adding the issue to the sprint...',
68
- jira.apiAgileRequest(`/sprint/${sprintId}/issue`, {
199
+ jira.apiAgileRequest(`/sprint/${data.sprintId}/issue`, {
69
200
  method: 'POST',
70
201
  followAllRedirects: true,
71
202
  body: {
package/src/table.js CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import color from 'chalk';
2
6
 
3
7
  class Table {
package/src/user.js CHANGED
@@ -1,10 +1,17 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
1
5
  import Jira from './jira.js';
2
6
 
3
7
  class User {
4
8
  static async pickUser(jira) {
5
9
  const currentUser = await jira.spin('Retrieving current user...', jira.api.getCurrentUser());
6
10
  const userList = await jira.spin('Retrieving users...', jira.api.getUsers(0, 1000));
11
+ return User.sortUsers(currentUser, userList);
12
+ }
7
13
 
14
+ static sortUsers(currentUser, userList) {
8
15
  userList.sort((a, b) => {
9
16
  if (a.accountId === currentUser.accountId) {
10
17
  return -1;
@@ -14,7 +21,15 @@ class User {
14
21
  return 1;
15
22
  }
16
23
 
17
- return a.displayName > b.displayName;
24
+ if (a.displayName < b.displayName) {
25
+ return -1;
26
+ }
27
+
28
+ if (a.displayName > b.displayName) {
29
+ return 1;
30
+ }
31
+
32
+ return 0;
18
33
  });
19
34
 
20
35
  return userList;
package/src/utils.js ADDED
@@ -0,0 +1,46 @@
1
+ // SPDX-FileCopyrightText: 2021 Andrea Marchesini <baku@bnode.dev>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ import execa from 'execa';
6
+ import fs from 'fs';
7
+ import temp from 'temp';
8
+
9
+ class Utils {
10
+ static async writeInTempFile() {
11
+ temp.track();
12
+
13
+ if (!process.env.EDITOR) {
14
+ console.log("Please set 'EDITOR' env variable.");
15
+ return null;
16
+ }
17
+
18
+ let file;
19
+ try {
20
+ file = temp.openSync('jira');
21
+ } catch (e) {
22
+ console.log("Failed to open a temporary file");
23
+ return null;
24
+ }
25
+
26
+ const code = await new Promise(resolve => {
27
+ const subprocess = execa(process.env.EDITOR, [file.path], {
28
+ detached: true,
29
+ stdio: 'inherit',
30
+ });
31
+
32
+ subprocess.on('error', () => resolve(-1));
33
+ subprocess.on('close', resolve);
34
+ });
35
+
36
+ if (code !== 0) {
37
+ console.log("Failed to run the app");
38
+ return null;
39
+ }
40
+
41
+ let value = fs.readFileSync(file.path);
42
+ return value.toString().trim();
43
+ }
44
+ };
45
+
46
+ export default Utils;