diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f25ebfc Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index 12505f2..02b7998 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,33 @@ The extension can be configured through the following settings: The extension will get the configuration when its first activated. If you change the configuration, you need to reload the window to make it work. - `jiraCommitMessage.baseURL`: The URL of your JIRA instance, e.g. `https://mycompany.atlassian.net`. -- `jiraCommitMessage.username`: The email/username to use for the JIRA API. +- `jiraCommitMessage.username`: The email to use for the JIRA API, e.g `name@yourcompany.com` - `jiraCommitMessage.token`: The API token to use for the JIRA API. You can generate one in your JIRA profile settings. (See [here](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) for more information.) +## Note +If you want to clear the token or username or password, run the command - `JIRA Commit Message: Clear Stored data` from the command palette. This will clear the token and other creds. + +You can start over again by running the command - `JIRA Commit Message: Enter User Details for the JIRA API` from the command palette.palette + +## Available Commands +The following are the available commands for this extension. +```json + "commands": [ + { + "command": "jira-git-commit-helper.createCommitMessage", + "title": "JIRA Commit Message: Create Commit Message" + }, + { + "command": "jira-git-commit-helper.resetToken", + "title": "JIRA Commit Message: Clear Stored data" + }, + { + "command": "jira-git-commit-helper.setUserDetails", + "title": "JIRA Commit Message: Enter User Details for the JIRA API" + } + ] +``` + ## Usage When creating a new Git commit, the extension will automatically retrieve the details of the currently assigned JIRA ticket and insert them into the commit message template. The commit message will then be pre-filled with the JIRA ticket information, which can be edited as necessary. @@ -36,6 +60,8 @@ To activate the extension, open the command palette (Ctrl+Shift+P) and select "J - Select the type of commit you are making from the list of available commit types. - Enter a commit message and press Enter to create the commit. +> Note: This extension does not store any of your data locally. It is stored within VSCode Extension Cache and hence you can never access the username, token or URL directly. It can be set and unset only via the available commands. + ## Contributing If you wish to contribute to this extension, please follow the steps below: diff --git a/package.json b/package.json index 90ae1db..6d60456 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jira-git-commit-helper", "displayName": "JIRA Git Commit Helper", "description": "This helps to create commit messages based on JIRA tickets assigned to you", - "version": "0.0.3", + "version": "1.0.0", "publisher": "SamuelLawrentz", "repository": { "type": "git", @@ -38,7 +38,11 @@ }, { "command": "jira-git-commit-helper.resetToken", - "title": "JIRA Commit Message: Reset Username & Token" + "title": "JIRA Commit Message: Clear Stored data" + }, + { + "command": "jira-git-commit-helper.setUserDetails", + "title": "JIRA Commit Message: Enter User Details for the JIRA API" } ] }, diff --git a/src/activate.js b/src/activate.js index bcb39b3..531493b 100644 --- a/src/activate.js +++ b/src/activate.js @@ -6,47 +6,54 @@ const vscode = require('vscode'); const Cache = require('vscode-cache'); const { recentlySelectedSeperator, TicktetSeparator, CONSTANTS } = require('./constants'); + /** * @param {vscode.ExtensionContext} context */ async function activate(context) { - const secrets = await context.secrets.get(CONSTANTS.storageKeys.auth) let issuesCache = new Cache(context); - // check if auth is already stored in the secrets - // if not, prompt for username and password - if (!secrets) { - - //get password from username and password - const username = await vscode.window.showInputBox({ - placeHolder: CONSTANTS.strings.usernamePlaceholder, - ignoreFocusOut: true, - }); - const password = await vscode.window.showInputBox({ - placeHolder: CONSTANTS.strings.tokenPlaceholder, - password: true, - ignoreFocusOut: true, - }); - if (!username || !password) return; - + const setDetails = vscode.commands.registerCommand('jira-git-commit-helper.setUserDetails', async () => { + const secrets = await context.secrets.get(CONSTANTS.storageKeys.auth) + // check if auth is already stored in the secrets + // if not, prompt for username and password + if (!secrets) { + + //get password from username and password + const username = await vscode.window.showInputBox({ + placeHolder: CONSTANTS.strings.usernamePlaceholder, + ignoreFocusOut: true, + }); + const password = await vscode.window.showInputBox({ + placeHolder: CONSTANTS.strings.tokenPlaceholder, + password: true, + ignoreFocusOut: true, + }); + if (!username || !password) return vscode.window.showInformationMessage('Username and Token are required.'); - // store the auth in the secrets as base64 encoded string - const auth = Buffer.from(`${username}:${password}`).toString('base64'); - await context.secrets.store(CONSTANTS.storageKeys.auth, auth); - // get the base url from the user - const baseUrl = await vscode.window.showInputBox({ - placeHolder: CONSTANTS.strings.baseUrlPlaceholder, - ignoreFocusOut: true, - }); - if (!baseUrl) return; - await context.secrets.store(CONSTANTS.storageKeys.baseUrl, baseUrl); - } + // store the auth in the secrets as base64 encoded string + const auth = Buffer.from(`${username}:${password}`).toString('base64'); + await context.secrets.store(CONSTANTS.storageKeys.auth, auth); + // get the base url from the user + const baseUrl = await vscode.window.showInputBox({ + placeHolder: CONSTANTS.strings.baseUrlPlaceholder, + ignoreFocusOut: true, + }); + if (!baseUrl) return; + await context.secrets.store(CONSTANTS.storageKeys.baseUrl, baseUrl); + } else vscode.window.showInformationMessage('Data already present, please run "JIRA Commit Message: Clear Stored data" to clear.'); + }) + context.subscriptions.push(setDetails); // register a command to open the commit message editor const commitMessageEditor = vscode.commands.registerCommand('jira-git-commit-helper.createCommitMessage', async () => { const secrets = await context.secrets.get(CONSTANTS.storageKeys.auth) - if (!secrets) return vscode.window.showErrorMessage('No JIRA credentials found'); + if (!secrets) { + vscode.window.showErrorMessage('No JIRA credentials found') + vscode.commands.executeCommand('jira-git-commit-helper.setUserDetails') + return + } // check if git extension is installed and enabled const vscodeGit = vscode.extensions.getExtension('vscode.git'); @@ -86,6 +93,9 @@ async function activate(context) { console.log(e); } }); + if(!Array.isArray(jiraTickets)) + return vscode.window.showErrorMessage('Not able to find valid tickets. Use reset command to reset your information and try again.'); + // Store jira tickets in cache and set expiration to 30 mins in seconds await issuesCache.put(CONSTANTS.storageKeys.tickets, jiraTickets, 1800); @@ -159,6 +169,9 @@ async function activate(context) { }); context.subscriptions.push(resetToken); + + if (!secrets) + vscode.commands.executeCommand('jira-git-commit-helper.setUserDetails') } module.exports = activate \ No newline at end of file diff --git a/src/constants.js b/src/constants.js index 26d60a4..f14dc4e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -3,10 +3,10 @@ const CONSTANTS = { { label: '$(add) Enter ticket number manually', action: 'enter-manually' }, { label: '$(refresh) Fetch latest tickets', action: 'refresh' }, ], - types: ['๐Ÿž Bug Fix', 'โซ Updates', '๐Ÿ”ง Optimization', '๐Ÿงน Clean up'], - url: (baseURL) => `${baseURL}/rest/api/3/search/?jql=updated >= -20d AND project = CNTO AND assignee in (currentUser()) order by updated DESC&maxResults=15`, + types: ['๐Ÿž Bug Fix', 'โซ Updates', '๐Ÿ”ง Optimization', '๐Ÿงน Clean up', '๐Ÿ“‹ Chore', 'โšช Temp', '๐Ÿ“’ Documentation', '๐Ÿ”‚ Revert'], + url: (baseURL) => `${baseURL.replace(/\/$/, '')}/rest/api/3/search/?jql=updated >= -20d AND project = CNTO AND assignee in (currentUser()) order by updated DESC&maxResults=15`, strings: { - usernamePlaceholder: 'Enter your JIRA username/email', + usernamePlaceholder: 'Enter your JIRA email (eg: your-name@your-company.com)', tokenPlaceholder: 'Enter your JIRA API token', ticketPlaceholder: 'Select the ticket', manualTicketPlaceholder: 'Enter ticket number manually (e.g. CNTO-1234)',