Skip to content

Commit 43f1256

Browse files
committed
⚡ worked on board commands
1 parent c704e3c commit 43f1256

File tree

3 files changed

+89
-86
lines changed

3 files changed

+89
-86
lines changed

src/api/board.js

+46-49
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,58 @@
22
* JIRA APIS related to jira board
33
*/
44

5-
// authentication
65
const fuzzy = require('fuzzy');
7-
const open = require('open');
86
const inquirer = require('inquirer');
97
const autocompletePrompt = require('inquirer-autocomplete-prompt');
10-
11-
const jira = require('../authentication');
12-
8+
const authenticate = require('../authentication');
139
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.....');
1414

1515
let names = [];
1616
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+
},
5049

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+
}
6259
};

src/commands/boards.js

+34-28
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,42 @@
33
*/
44
const program = require('commander');
55
const { openMyboard } = require('../operations/boards');
6-
6+
const board = require('../api/board');
77
exports.loadBoardCommands = () => {
8-
const openBoardCommand = program
9-
.command('board')
10-
.description('jira board activity')
11-
.action(() => {
12-
// show the available board commands
13-
openBoardCommand.help();
14-
});
8+
const openBoardCommand = program
9+
.command('board')
10+
.description('jira board activity')
11+
.action(() => {
12+
// show the available board commands
13+
openBoardCommand.help();
14+
});
1515

16-
/**
17-
* Opens The JIRA Board that You had Set as Default with your assigned tasks.
18-
*/
19-
openBoardCommand.command('mine')
20-
.description('Opens your default JIRA board with with your assigned tasks')
21-
.action(() => {
22-
openMyboard(true);
23-
});
16+
/**
17+
* Opens The JIRA Board that You had Set as Default with your assigned tasks.
18+
*/
19+
openBoardCommand
20+
.command('mine')
21+
.description(
22+
'Opens your default JIRA board with with your assigned tasks'
23+
)
24+
.action(() => {
25+
openMyboard(true);
26+
});
2427

25-
openBoardCommand.command('show')
26-
.description('Opens The JIRA Board that You had Set as Default.')
27-
.action(() => {
28-
openMyboard(false);
29-
});
28+
openBoardCommand
29+
.command('show')
30+
.description('Opens The JIRA Board that You had Set as Default.')
31+
.action(() => {
32+
openMyboard(false);
33+
});
3034

31-
// Set Your Default JIRA Board so that you can open it directly
32-
openBoardCommand.command('set <boardname>')
33-
.description('Set Your Default JIRA Board')
34-
.action(() => {
35-
// select from the default board if present
36-
// if not then open board with selected my profile
37-
});
35+
// Set Your Default JIRA Board so that you can open it directly
36+
openBoardCommand
37+
.command('set')
38+
.description('Set Your Default JIRA Board')
39+
.action(answers => {
40+
board.getBoards();
41+
// select from the default board if present
42+
// if not then open board with selected my profile
43+
});
3844
};

src/operations/boards.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const print = require('../utility/console');
44

55
/**
66
* Open the default set JIRA RAPID BOARD
7-
*/
7+
*/
88
exports.openMyboard = (myprofile = false) => {
9-
const boardId = config.getConfig('myjiraboard');
10-
const accountId = myprofile ? config.getConfig('accountId') : null;
11-
if (boardId) {
12-
const url = boardURL(boardId, accountId);
13-
openURL(url);
14-
} else {
15-
print.printError('No board found! Please select a default board.');
16-
}
9+
const boardId = config.getConfig('defaultJiraBoard');
10+
const accountId = myprofile ? config.getConfig('accountId') : null;
11+
if (boardId) {
12+
const url = boardURL(boardId, accountId);
13+
openURL(url);
14+
} else {
15+
print.printError('No board found! Please select a default board.');
16+
}
1717
};

0 commit comments

Comments
 (0)