Skip to content

Commit df80a23

Browse files
Merge pull request #7 from samuellawrentz/release/develop
Added option to copy ticket summary
2 parents a42e6bd + 441f049 commit df80a23

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jira-git-commit-helper",
33
"displayName": "JIRA Git Commit Helper",
44
"description": "This helps to create commit messages based on JIRA tickets assigned to you",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"publisher": "SamuelLawrentz",
77
"repository": {
88
"type": "git",

src/activate.js

+35-33
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { default: axios } = require('axios');
55
const vscode = require('vscode');
66
const Cache = require('vscode-cache');
77
const { recentlySelectedSeperator, TicktetSeparator, CONSTANTS } = require('./constants');
8+
const { getCommitMessageString } = require('./utils');
89

910

1011
/**
@@ -15,44 +16,44 @@ async function activate(context) {
1516

1617
const setDetails = vscode.commands.registerCommand('jira-git-commit-helper.setUserDetails', async () => {
1718
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.');
3334

3435

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);
3839

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+
})
4849
context.subscriptions.push(setDetails);
4950
// register a command to open the commit message editor
5051
const commitMessageEditor = vscode.commands.registerCommand('jira-git-commit-helper.createCommitMessage', async () => {
5152
const secrets = await context.secrets.get(CONSTANTS.storageKeys.auth)
5253
if (!secrets) {
5354
vscode.window.showErrorMessage('No JIRA credentials found')
5455
vscode.commands.executeCommand('jira-git-commit-helper.setUserDetails')
55-
return
56+
return
5657
}
5758

5859
// check if git extension is installed and enabled
@@ -75,8 +76,8 @@ async function activate(context) {
7576
try {
7677
const cachedIssues = await issuesCache.get(CONSTANTS.storageKeys.tickets);
7778
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+
8081
if (cachedIssues) return cachedIssues;
8182
// get list of tickets assigned to current user from JIRA using axios
8283
const { data: { issues } } = await axios.get(CONSTANTS.url(baseUrl), {
@@ -93,7 +94,7 @@ async function activate(context) {
9394
console.log(e);
9495
}
9596
});
96-
if(!Array.isArray(jiraTickets))
97+
if (!Array.isArray(jiraTickets))
9798
return vscode.window.showErrorMessage('Not able to find valid tickets. Use reset command to reset your information and try again.');
9899

99100
// Store jira tickets in cache and set expiration to 30 mins in seconds
@@ -155,7 +156,7 @@ async function activate(context) {
155156
// Store selected jira tickets in cache and set expiration to 3 days in seconds
156157
if (!selectedTicket.isManual)
157158
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) : '';
159160
});
160161

161162
context.subscriptions.push(commitMessageEditor);
@@ -170,7 +171,8 @@ async function activate(context) {
170171

171172
context.subscriptions.push(resetToken);
172173

173-
if (!secrets)
174+
const auth = await context.secrets.get(CONSTANTS.storageKeys.auth)
175+
if (!auth)
174176
vscode.commands.executeCommand('jira-git-commit-helper.setUserDetails')
175177
}
176178

src/constants.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@ const CONSTANTS = {
33
{ label: '$(add) Enter ticket number manually', action: 'enter-manually' },
44
{ label: '$(refresh) Fetch latest tickets', action: 'refresh' },
55
],
6-
types: ['🐞 Bug Fix', '⏫ Updates', '🔧 Optimization', '🧹 Clean up', '📋 Chore', '⚪ Temp', '📒 Documentation', '🔂 Revert'],
6+
types: [
7+
{
8+
label: '$(copy) Use ticket summary as commit message',
9+
action: 'copy-summary'
10+
},
11+
'🐞 Bug Fix',
12+
'⏫ Updates',
13+
'🔧 Optimization',
14+
'🧹 Clean up',
15+
'📋 Chore',
16+
'⚪ Temp',
17+
'📒 Documentation',
18+
'🔂 Revert'
19+
],
720
url: (baseURL) => `${baseURL.replace(/\/$/, '')}/rest/api/latest/search/?jql=updated >= -20d AND assignee in (currentUser()) order by updated DESC&maxResults=15`,
821
strings: {
922
usernamePlaceholder: 'Enter your JIRA email (eg: [email protected])',
1023
tokenPlaceholder: 'Enter your JIRA API token',
1124
ticketPlaceholder: 'Select the ticket',
1225
manualTicketPlaceholder: 'Enter ticket number manually (e.g. CNTO-1234)',
13-
typePlaceholder: 'Select type of the changes',
26+
typePlaceholder: 'Select type of the changes (optional)',
1427
fetchingTickets: 'Fetching JIRA tickets...',
1528
baseUrlPlaceholder: 'Enter your JIRA base URL (e.g. https://company.atlassian.net)',
1629
},

src/utils.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// A collection of utility functions
2+
3+
function getCommitMessageString(ticketID, type, ticketSummary) {
4+
// If copy-summary action is selected, return the ticket summary with the ticket ID
5+
// else return the ticket ID with the type of change
6+
if(type && typeof type === 'object' && type.action === 'copy-summary') return `(${ticketID}) - ${ticketSummary}`;
7+
return `(${ticketID}) ${type || ''}: `;
8+
}
9+
10+
// require exports
11+
module.exports = {
12+
getCommitMessageString
13+
}
14+
15+

0 commit comments

Comments
 (0)