Skip to content

Commit e69a9c8

Browse files
committed
Issue API fixes
1 parent 6884847 commit e69a9c8

File tree

3 files changed

+146
-217
lines changed

3 files changed

+146
-217
lines changed

src/api/IssueApis.js

+131-217
Original file line numberDiff line numberDiff line change
@@ -3,235 +3,149 @@
33
*/
44
const open = require('open');
55
const Configstore = require('configstore');
6-
//const authenticate = require('../authentication');
6+
const authService = require('../services/AuthServices');
77
const util = require('../utility/utils');
88
const consoleApi = require('../utility/console');
9-
109
const configStore = new Configstore('jiraconfig');
1110

1211
module.exports = {
13-
/**
14-
* @param issueKey = {}
15-
* Note that this object must contain EITHER an issueId or issueKey
16-
* issueKey - 'TEST-12' or issueId
17-
*/
18-
// getIssue(issueKey, callback) {
19-
// authenticate
20-
// .currentUser()
21-
// .issue.getIssue(issueKey, (error, success) => {
22-
// const data = success || error;
23-
// return callback(data);
24-
// });
25-
// },
26-
// /**
27-
// * Opens the issue in the default browser
28-
// * hostname/browse/issuekey
29-
// * @issueKey
30-
// */
31-
// openIssue(issueKey) {
32-
// const hostName = util.getHostName();
33-
// const URL = `https://${hostName}/browse/${issueKey}`;
34-
// open(URL);
35-
// },
36-
// /**
37-
// * this method opens the issues for the given project key
38-
// *
39-
// * @param {*} projectKey
40-
// */
41-
// openProjectIssues(projectKey) {
42-
// const hostName = util.getHostName();
43-
// const URL = `https://${hostName}/projects/${projectKey}/issues`;
44-
// open(URL);
45-
// },
12+
/**
13+
* this method opens the issues for the given project key
14+
* @param {*} projectKey
15+
*/
16+
openProjectIssues(projectKey) {
17+
const hostName = util.getHostName();
18+
const URL = `https://${hostName}/jira/software/c/projects/${projectKey}/issues`;
19+
open(URL);
20+
},
4621
// /**
4722
// * A method return array of transtions available for the specific issues
4823
// * @param options.issuekey isssue keys to which this
4924
// * @param {*} options
5025
// */
51-
// getTranstions(issueKey, cb) {
52-
// // const key = issueKey.split('-')[0];
53-
// // const spinner = util.spinner({
54-
// // text: 'Fetching available transtions...',
55-
// // spinner: 'earth'
56-
// // });
57-
// issueKey = 'OHEA'
58-
// //spinner.start();
59-
// authenticate
60-
// .jiraConnector()
61-
// .project.getStatuses('OHEA' , (error, success) => {
62-
// console.log("error",error )
63-
// console.log("success",success )
64-
// // const availableTranstions = [];
65-
// // if (success) {
66-
// // spinner.stop();
67-
// // success.transitions.map(t => {
68-
// // availableTranstions.push({ name: t.name, value: t.id });
69-
// // });
70-
// // configStore.set(key, availableTranstions);
71-
// // return cb(availableTranstions);
72-
// // }
73-
// // if (error) {
74-
// // spinner.stop();
75-
// // cb(error.errorMessages[0]);
76-
// // }
77-
// });
78-
// },
79-
// /**
80-
// * This method changes the status of the issue
81-
// *
82-
// * @param{String} object.transtion - id to which issue transtion will happen
83-
// * @param{String} object.issueKey - issuekey for which issue transtion happen
84-
// * @param {*} object
85-
// */
86-
// changeStatus(object) {
87-
// const spinner = util.spinner('Changing status...');
88-
// spinner.start();
89-
// authenticate
90-
// .currentUser()
91-
// .issue.transitionIssue(object, (error, success) => {
92-
// if (success) {
93-
// const key = object.issueKey.split('-')[0];
94-
// const transitionName = configStore.get(key).filter(el => {
95-
// if (el.value === object.transition) {
96-
// return el.name;
97-
// }
98-
// });
99-
// const message = `${consoleApi.chalkRed(
100-
// object.issueKey
101-
// )} is transitioned to ${consoleApi.chalkGreen(
102-
// transitionName[0].name
103-
// )}`;
104-
// spinner.stop();
105-
// console.log(message);
106-
// }
107-
// if (error) {
108-
// spinner.stop();
109-
// consoleApi.printError(error);
110-
// }
111-
// });
112-
// },
113-
// assignIssue(issueKey, accountId, username) {
114-
// const options = {
115-
// issueKey,
116-
// accountId
117-
// };
118-
// const spinner = util.spinner(
119-
// `Assigning the issue ${issueKey} to ${username}`
120-
// );
121-
// spinner.start();
122-
// authenticate
123-
// .currentUser()
124-
// .issue.assignIssue(options, (error, success) => {
125-
// if (success || error) {
126-
// spinner.stop();
127-
// }
128-
// if (error) {
129-
// consoleApi.printError('Issue Cannnot be assigned');
130-
// }
131-
// if (success) {
132-
// const message = `Issue ${consoleApi.chalkRed(
133-
// issueKey
134-
// )} ${consoleApi.chalkGreen(
135-
// 'is assigned to'
136-
// )} ${consoleApi.printbgCyan(username)}`;
137-
// consoleApi.printInfo(message);
138-
// }
139-
// });
140-
// },
141-
// /**
142-
// * Assign the issue to self i.e logged in user
143-
// * @param issueKey
144-
// * @param {*} issueKey
145-
// */
146-
// assignSelf(issueKey) {
147-
// const accountId = configStore.get('accountId');
148-
// const username = configStore.get('username');
149-
// module.exports.assignIssue(issueKey, accountId, username);
150-
// },
26+
27+
assignIssue(issueKey, accountId, username) {
28+
const options = {
29+
issueKey,
30+
accountId
31+
};
32+
const spinner = util.spinner(
33+
`Assigning the issue ${issueKey} to ${username}`
34+
);
35+
spinner.start();
36+
authService.jiraConnector()
37+
.issue.assignIssue(options, (error, success) => {
38+
if (success || error) {
39+
spinner.stop();
40+
}
41+
if (error) {
42+
consoleApi.printError('Issue Cannnot be assigned');
43+
}
44+
if (success) {
45+
const message = `Issue ${consoleApi.chalkRed(
46+
issueKey
47+
)} ${consoleApi.chalkGreen(
48+
'is assigned to'
49+
)} ${consoleApi.printbgCyan(username)}`;
50+
consoleApi.printInfo(message);
51+
}
52+
});
53+
},
54+
/**
55+
* Assign the issue to self i.e logged in user
56+
* @param issueKey
57+
* @param {*} issueKey
58+
*/
59+
assignSelf(issueKey) {
60+
const accountId = configStore.get('accountId');
61+
const username = configStore.get('displayName');
62+
module.exports.assignIssue(issueKey, accountId, username);
63+
},
15164
// /**
15265
// * Get the issue statuses of project for the given issue
15366
// * @param {*} issueKey
15467
// */
155-
// getStoredTranstions(issueKey, cb) {
156-
// const key = issueKey.split('-')[0];
157-
// const keyPresent = configStore.get(key);
158-
// if (!keyPresent) {
159-
// module.exports.getTranstions(issueKey, data => cb(data));
160-
// } else {
161-
// const transitions = configStore.get(key);
162-
// return cb(transitions);
163-
// }
164-
// },
165-
// // ------------------------------COMMENTS RELATED FUNCTIONS------------------>
166-
// /** Add comment to the issue
167-
// * { issueKey: 'SFMAC-19', comment: 'some comment'"}
168-
// * @param {*} options
169-
// */
170-
// addComment(options) {
171-
// const spinner = util.spinner('Posting your comment. Please wait');
172-
// spinner.start();
173-
// authenticate
174-
// .currentUser()
175-
// .issue.addComment(options, (error, response) => {
176-
// if (response) {
177-
// spinner.stop();
178-
// consoleApi.printInfo('Comment added successfully');
179-
// }
180-
// if (error) {
181-
// spinner.stop();
182-
// consoleApi.printError('No issue with mentioned key found');
183-
// }
184-
// });
185-
// },
186-
// /**
187-
// * Get all the comments for the specific issue
188-
// * @param {*} issueKey
189-
// */
190-
// getComments(issueKey) {
191-
// const spinner = util.spinner({
192-
// text: 'Fetching data...',
193-
// spinner: 'earth'
194-
// });
195-
// spinner.start();
196-
// authenticate
197-
// .currentUser()
198-
// .issue.getComments({ issueKey }, (error, response) => {
199-
// if (response) {
200-
// spinner.stop();
201-
// if (response.comments.length === 0) {
202-
// consoleApi.printInfo('No Comments Found');
203-
// } else {
204-
// response.comments.map(comment => {
205-
// console.log(
206-
// `${comment.id} ${consoleApi.chalkGreen(
207-
// comment.author.displayName.split(' ')[0]
208-
// )} ${comment.body} \n`
209-
// );
210-
// });
211-
// }
212-
// }
213-
// });
214-
// },
215-
// /*
216-
// * Delete the comment for the given issueKey
217-
// * @param {string} [opts.issueKey] The Key of the issue. EX: JWR-3
218-
// * @param {string} opts.commentId The id of the comment.
219-
// * @param {*} opts
220-
// */
221-
// deleteComment(opts) {
222-
// const spinner = util.spinner('Deleting comment .....');
223-
// spinner.start();
224-
// authenticate
225-
// .currentUser()
226-
// .issue.deleteComment(opts, (error, response) => {
227-
// if (error) {
228-
// spinner.stop();
229-
// consoleApi.printError('Error while deleting the comment');
230-
// }
231-
// if (response) {
232-
// spinner.stop();
233-
// consoleApi.printInfo('Comment deleted');
234-
// }
235-
// });
236-
// }
68+
69+
getStoredTranstions(issueKey, cb) {
70+
const key = issueKey.split('-')[0];
71+
const keyPresent = configStore.get(key);
72+
if (!keyPresent) {
73+
module.exports.getTranstions(issueKey, data => cb(data));
74+
} else {
75+
const transitions = configStore.get(key);
76+
return cb(transitions);
77+
}
78+
},
79+
// ------------------------------COMMENTS RELATED FUNCTIONS------------------>
80+
/**
81+
* Add comment to the issue
82+
* * { issueKey: 'SFMAC-19', comment: 'some comment'"}
83+
* @param {*} options
84+
*/
85+
addComment(options) {
86+
const spinner = util.spinner('Posting your comment. Please wait');
87+
spinner.start();
88+
authService.jiraConnector()
89+
.issue.addComment(options, (error, response) => {
90+
if (response) {
91+
spinner.stop();
92+
consoleApi.printInfo('Comment added successfully');
93+
}
94+
if (error) {
95+
spinner.stop();
96+
consoleApi.printError('No issue with mentioned key found');
97+
}
98+
});
99+
},
100+
101+
/**
102+
* Get all the comments for the specific issue
103+
* @param {*} issueKey
104+
*/
105+
getComments(issueKey) {
106+
const spinner = util.spinner({
107+
text: 'Fetching data...',
108+
spinner: 'earth'
109+
});
110+
spinner.start();
111+
authService.jiraConnector()
112+
.issue.getComments({ issueKey }, (error, response) => {
113+
if (response) {
114+
spinner.stop();
115+
if (response.comments.length === 0) {
116+
consoleApi.printInfo('No Comments Found');
117+
} else {
118+
response.comments.map(comment => {
119+
console.log(
120+
`${comment.id} ${consoleApi.chalkGreen(
121+
comment.author.displayName.split(' ')[0]
122+
)} ${comment.body} \n`
123+
);
124+
});
125+
}
126+
}
127+
});
128+
},
129+
/**
130+
* * Delete the comment for the given issueKey
131+
* @param {string} [opts.issueKey] The Key of the issue. EX: JWR-3
132+
* @param {string} opts.commentId The id of the comment.
133+
* @param {*} opts
134+
*/
135+
136+
deleteComment(opts) {
137+
const spinner = util.spinner('Deleting comment .....');
138+
spinner.start();
139+
authService.jiraConnector()
140+
.issue.deleteComment(opts, (error, response) => {
141+
if (error) {
142+
spinner.stop();
143+
consoleApi.printError('Error while deleting the comment');
144+
}
145+
if (response) {
146+
spinner.stop();
147+
consoleApi.printInfo('Comment deleted');
148+
}
149+
});
150+
}
237151
};

src/commands/Tasks.js

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ exports.loadTasksCommands = () => {
4646
assignTask.searchUser(key);
4747
});
4848

49+
// open issue
50+
openTasksCommands
51+
.command('assign-me')
52+
.argument('<KEY>', 'Task key to assign')
53+
.description('Assign Issue to Self(logged in user')
54+
.action(key => {
55+
taskOperation.assignToSelf(key)
56+
});
57+
4958
// open issue
5059
openTasksCommands
5160
.command('open')
@@ -54,4 +63,5 @@ exports.loadTasksCommands = () => {
5463
.action(key => {
5564
taskOperation.openTask(key);
5665
});
66+
5767
};

0 commit comments

Comments
 (0)