|
2 | 2 | * JIRA APIS related to jira board
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -// authentication |
6 | 5 | const fuzzy = require('fuzzy');
|
7 |
| -const open = require('open'); |
8 | 6 | const inquirer = require('inquirer');
|
9 | 7 | const autocompletePrompt = require('inquirer-autocomplete-prompt');
|
10 |
| - |
11 |
| -const jira = require('../authentication'); |
12 |
| - |
| 8 | +const authenticate = require('../authentication'); |
13 | 9 | inquirer.registerPrompt('autocomplete', autocompletePrompt);
|
| 10 | +const store = require('../store'); |
| 11 | +const log = require('../utility/console'); |
| 12 | +const util = require('../utility/utils'); |
| 13 | +const spinner = util.spinner('Fetching boards.....'); |
14 | 14 |
|
15 | 15 | let names = [];
|
16 | 16 | module.exports = {
|
17 |
| - async openBoard(boardId) { |
18 |
| - await open( |
19 |
| - `https://technine.atlassian.net/secure/RapidBoard.jspa?rapidView=${boardId}`, |
20 |
| - ); |
21 |
| - }, |
22 |
| - |
23 |
| - getBoards() { |
24 |
| - jira.currentUser().board.getAllBoards({}, (err, response) => { |
25 |
| - if (response) { |
26 |
| - names = response.values.map((el) => el.name); |
27 |
| - inquirer |
28 |
| - .prompt([ |
29 |
| - { |
30 |
| - type: 'autocomplete', |
31 |
| - name: 'name', |
32 |
| - message: 'Please search for the board you want to open', |
33 |
| - source: module.exports.searchProjects, |
34 |
| - pageSize: 5, |
35 |
| - }, |
36 |
| - ]) |
37 |
| - .then((answers) => { |
38 |
| - // assign the issue to selected user |
39 |
| - |
40 |
| - const boardId = response.values.filter( |
41 |
| - (el) => el.name === answers.name, |
42 |
| - )?.[0]?.id; |
43 |
| - module.exports.openBoard(boardId); |
44 |
| - }); |
45 |
| - } else { |
46 |
| - console.log('---', err); |
47 |
| - } |
48 |
| - }); |
49 |
| - }, |
| 17 | + getBoards() { |
| 18 | + spinner.start(); |
| 19 | + authenticate.jiraConnector().board.getAllBoards({}, (err, response) => { |
| 20 | + if (response) { |
| 21 | + spinner.stop(); |
| 22 | + names = response.values.map(el => el.name); |
| 23 | + inquirer |
| 24 | + .prompt([ |
| 25 | + { |
| 26 | + type: 'autocomplete', |
| 27 | + name: 'name', |
| 28 | + message: |
| 29 | + 'Please search for the board you want to open', |
| 30 | + source: module.exports.searchProjects, |
| 31 | + pageSize: 6 |
| 32 | + } |
| 33 | + ]) |
| 34 | + .then(answers => { |
| 35 | + // assign the issue to selected user |
| 36 | + const boardId = response.values.filter( |
| 37 | + el => el.name === answers.name |
| 38 | + )?.[0]?.id; |
| 39 | + if (boardId) { |
| 40 | + util.setConfig({ defaultJiraBoard: boardId }); |
| 41 | + } |
| 42 | + log.printInfo('Your default board is set'); |
| 43 | + }); |
| 44 | + } else { |
| 45 | + console.log('---', err); |
| 46 | + } |
| 47 | + }); |
| 48 | + }, |
50 | 49 |
|
51 |
| - searchProjects(answers, input) { |
52 |
| - input = input || ''; |
53 |
| - return new Promise((resolve) => { |
54 |
| - setTimeout(() => { |
55 |
| - const fuzzyResult = fuzzy.filter(input, names); |
56 |
| - resolve( |
57 |
| - fuzzyResult.map((el) => el.original), |
58 |
| - ); |
59 |
| - }, 300); |
60 |
| - }); |
61 |
| - }, |
| 50 | + searchProjects(answers, input) { |
| 51 | + input = input || ''; |
| 52 | + return new Promise(resolve => { |
| 53 | + setTimeout(() => { |
| 54 | + const fuzzyResult = fuzzy.filter(input, names); |
| 55 | + resolve(fuzzyResult.map(el => el.original)); |
| 56 | + }, 300); |
| 57 | + }); |
| 58 | + } |
62 | 59 | };
|
0 commit comments