Skip to content

Commit

Permalink
v1.0.0 - Fixed some basic issues and added new command
Browse files Browse the repository at this point in the history
  • Loading branch information
samuellawerentz committed Feb 9, 2024
1 parent 5dd01e0 commit a5de58d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 deletions.
Binary file added .DS_Store
Binary file not shown.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `[email protected]`
- `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.
Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
71 changes: 42 additions & 29 deletions src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected])',
tokenPlaceholder: 'Enter your JIRA API token',
ticketPlaceholder: 'Select the ticket',
manualTicketPlaceholder: 'Enter ticket number manually (e.g. CNTO-1234)',
Expand Down

0 comments on commit a5de58d

Please sign in to comment.