@@ -5,6 +5,7 @@ const { default: axios } = require('axios');
5
5
const vscode = require ( 'vscode' ) ;
6
6
const Cache = require ( 'vscode-cache' ) ;
7
7
const { recentlySelectedSeperator, TicktetSeparator, CONSTANTS } = require ( './constants' ) ;
8
+ const { getCommitMessageString } = require ( './utils' ) ;
8
9
9
10
10
11
/**
@@ -15,44 +16,44 @@ async function activate(context) {
15
16
16
17
const setDetails = vscode . commands . registerCommand ( 'jira-git-commit-helper.setUserDetails' , async ( ) => {
17
18
const secrets = await context . secrets . get ( CONSTANTS . storageKeys . auth )
18
- // check if auth is already stored in the secrets
19
- // if not, prompt for username and password
20
- if ( ! secrets ) {
21
-
22
- //get password from username and password
23
- const username = await vscode . window . showInputBox ( {
24
- placeHolder : CONSTANTS . strings . usernamePlaceholder ,
25
- ignoreFocusOut : true ,
26
- } ) ;
27
- const password = await vscode . window . showInputBox ( {
28
- placeHolder : CONSTANTS . strings . tokenPlaceholder ,
29
- password : true ,
30
- ignoreFocusOut : true ,
31
- } ) ;
32
- if ( ! username || ! password ) return vscode . window . showInformationMessage ( 'Username and Token are required.' ) ;
19
+ // check if auth is already stored in the secrets
20
+ // if not, prompt for username and password
21
+ if ( ! secrets ) {
22
+
23
+ //get password from username and password
24
+ const username = await vscode . window . showInputBox ( {
25
+ placeHolder : CONSTANTS . strings . usernamePlaceholder ,
26
+ ignoreFocusOut : true ,
27
+ } ) ;
28
+ const password = await vscode . window . showInputBox ( {
29
+ placeHolder : CONSTANTS . strings . tokenPlaceholder ,
30
+ password : true ,
31
+ ignoreFocusOut : true ,
32
+ } ) ;
33
+ if ( ! username || ! password ) return vscode . window . showInformationMessage ( 'Username and Token are required.' ) ;
33
34
34
35
35
- // store the auth in the secrets as base64 encoded string
36
- const auth = Buffer . from ( `${ username } :${ password } ` ) . toString ( 'base64' ) ;
37
- await context . secrets . store ( CONSTANTS . storageKeys . auth , auth ) ;
36
+ // store the auth in the secrets as base64 encoded string
37
+ const auth = Buffer . from ( `${ username } :${ password } ` ) . toString ( 'base64' ) ;
38
+ await context . secrets . store ( CONSTANTS . storageKeys . auth , auth ) ;
38
39
39
- // get the base url from the user
40
- const baseUrl = await vscode . window . showInputBox ( {
41
- placeHolder : CONSTANTS . strings . baseUrlPlaceholder ,
42
- ignoreFocusOut : true ,
43
- } ) ;
44
- if ( ! baseUrl ) return ;
45
- await context . secrets . store ( CONSTANTS . storageKeys . baseUrl , baseUrl ) ;
46
- } else vscode . window . showInformationMessage ( 'Data already present, please run "JIRA Commit Message: Clear Stored data" to clear.' ) ;
47
- } )
40
+ // get the base url from the user
41
+ const baseUrl = await vscode . window . showInputBox ( {
42
+ placeHolder : CONSTANTS . strings . baseUrlPlaceholder ,
43
+ ignoreFocusOut : true ,
44
+ } ) ;
45
+ if ( ! baseUrl ) return ;
46
+ await context . secrets . store ( CONSTANTS . storageKeys . baseUrl , baseUrl ) ;
47
+ } else vscode . window . showInformationMessage ( 'Data already present, please run "JIRA Commit Message: Clear Stored data" to clear.' ) ;
48
+ } )
48
49
context . subscriptions . push ( setDetails ) ;
49
50
// register a command to open the commit message editor
50
51
const commitMessageEditor = vscode . commands . registerCommand ( 'jira-git-commit-helper.createCommitMessage' , async ( ) => {
51
52
const secrets = await context . secrets . get ( CONSTANTS . storageKeys . auth )
52
53
if ( ! secrets ) {
53
54
vscode . window . showErrorMessage ( 'No JIRA credentials found' )
54
55
vscode . commands . executeCommand ( 'jira-git-commit-helper.setUserDetails' )
55
- return
56
+ return
56
57
}
57
58
58
59
// check if git extension is installed and enabled
@@ -75,8 +76,8 @@ async function activate(context) {
75
76
try {
76
77
const cachedIssues = await issuesCache . get ( CONSTANTS . storageKeys . tickets ) ;
77
78
const baseUrl = await context . secrets . get ( CONSTANTS . storageKeys . baseUrl ) ;
78
- if ( ! baseUrl ) return vscode . window . showErrorMessage ( 'No JIRA base URL found' )
79
-
79
+ if ( ! baseUrl ) return vscode . window . showErrorMessage ( 'No JIRA base URL found' )
80
+
80
81
if ( cachedIssues ) return cachedIssues ;
81
82
// get list of tickets assigned to current user from JIRA using axios
82
83
const { data : { issues } } = await axios . get ( CONSTANTS . url ( baseUrl ) , {
@@ -93,7 +94,7 @@ async function activate(context) {
93
94
console . log ( e ) ;
94
95
}
95
96
} ) ;
96
- if ( ! Array . isArray ( jiraTickets ) )
97
+ if ( ! Array . isArray ( jiraTickets ) )
97
98
return vscode . window . showErrorMessage ( 'Not able to find valid tickets. Use reset command to reset your information and try again.' ) ;
98
99
99
100
// Store jira tickets in cache and set expiration to 30 mins in seconds
@@ -155,7 +156,7 @@ async function activate(context) {
155
156
// Store selected jira tickets in cache and set expiration to 3 days in seconds
156
157
if ( ! selectedTicket . isManual )
157
158
issuesCache . put ( CONSTANTS . storageKeys . selectedIssues , [ selectedTicket , ...recentlySelectedIssues ] . slice ( 0 , 4 ) , 3 * 24 * 60 * 60 )
158
- repos [ 0 ] . inputBox . value = selectedTicket && selectedTicket . detail ? `( ${ selectedTicket . detail } ) ${ selectedType || '' } : ` : '' ;
159
+ repos [ 0 ] . inputBox . value = selectedTicket && selectedTicket . detail ? getCommitMessageString ( selectedTicket . detail , selectedType , selectedTicket . label ) : '' ;
159
160
} ) ;
160
161
161
162
context . subscriptions . push ( commitMessageEditor ) ;
@@ -170,7 +171,8 @@ async function activate(context) {
170
171
171
172
context . subscriptions . push ( resetToken ) ;
172
173
173
- if ( ! secrets )
174
+ const auth = await context . secrets . get ( CONSTANTS . storageKeys . auth )
175
+ if ( ! auth )
174
176
vscode . commands . executeCommand ( 'jira-git-commit-helper.setUserDetails' )
175
177
}
176
178
0 commit comments