Skip to content

Commit

Permalink
ZETA-9187: Complete documentation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieGreenman committed Oct 7, 2024
1 parent cf4a78d commit b9843b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/documentation/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import { exec } from 'child_process';
import { promisify } from 'util';
import * as path from 'path';

const execAsync = promisify(exec);

Expand All @@ -16,26 +17,44 @@ export async function getGitHistoryAndNavigateToRazrooUrl() {
const lineNumber = editor.selection.active.line + 1;

try {
// Find the git root directory
const { stdout: gitRoot } = await execAsync('git rev-parse --show-toplevel', { cwd: path.dirname(filePath) });
const gitRootPath = gitRoot.trim();

// Get relative path of the file from git root
const relativeFilePath = path.relative(gitRootPath, filePath);

// Get Git blame information
const { stdout: blameOutput } = await execAsync(`git blame -L ${lineNumber},${lineNumber} "${filePath}"`);
const { stdout: blameOutput } = await execAsync(`git blame -L ${lineNumber},${lineNumber} "${relativeFilePath}"`, { cwd: gitRootPath });
const commitHash = blameOutput.split(' ')[0];

// Get commit details
const { stdout: commitDetails } = await execAsync(`git show --format="%B" -s ${commitHash}`);
const { stdout: commitDetails } = await execAsync(`git show --format="%B" -s ${commitHash}`, { cwd: gitRootPath });
console.log('commitDetails', commitDetails);

// Extract URL from commit message
const urlMatch = commitDetails.match(/https?:\/\/razroo\.com\S+/);
const urlMatch = commitDetails.match(/razroo\.com\S+/);
console.log('urlMatch', urlMatch);
if (!urlMatch) {
vscode.window.showInformationMessage('No Razroo URL found in the commit message.');
return;
}

const url = urlMatch[0];
const url = urlMatch[0].replace(/\]$/, '');

console.log('url', url);

// Open URL in default browser
vscode.env.openExternal(vscode.Uri.parse(url));
vscode.env.openExternal(vscode.Uri.parse(`https://${url}`)).then(() => {
vscode.window.showInformationMessage(`Opened ${url} in your default browser.`);
}, (error) => {
vscode.window.showErrorMessage(`Failed to open ${url}: ${error}`);
});

} catch (error: any) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
if (error.message.includes('not a git repository')) {
vscode.window.showErrorMessage('The current file is not in a Git repository.');
} else {
vscode.window.showErrorMessage(`Error: ${error.message}`);
}
}
}
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export async function activate(context: vscode.ExtensionContext) {
async() => {
try {
getGitHistoryAndNavigateToRazrooUrl();
console.log('show documentation called');
} catch (error) {
console.log('COMMAND_TRY_TO_AUTH ERROR');
console.error(error);
Expand Down

0 comments on commit b9843b6

Please sign in to comment.