Skip to content

Commit

Permalink
Merge pull request #30 from dzsquared/dev-0.6.0
Browse files Browse the repository at this point in the history
release 0.6.0
  • Loading branch information
dzsquared authored Sep 19, 2020
2 parents acb6dd4 + c0a97aa commit 36c98b4
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 80 deletions.
9 changes: 0 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,5 @@
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"terminal.integrated.env.osx": {
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
},
"terminal.integrated.env.linux": {
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
},
"terminal.integrated.env.windows": {
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
}
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This extension provides immediate access to the current First Responder Kit scripts and introductory execution suggestions. (All credit due to http://firstresponderkit.org/)

## Installation
The current release is available to [download as a .vsix file](https://github.com/dzsquared/sqlops-firstresponderkit/releases/download/0.5.1/firstresponderkit-0.5.1.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...`
The current release is available to [download as a .vsix file](https://github.com/dzsquared/sqlops-firstresponderkit/releases/download/0.6.0/firstresponderkit-0.6.0.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...`


## Features
Expand Down Expand Up @@ -52,6 +52,11 @@ Can be raised here: https://github.com/dzsquared/sqlops-firstresponderkit/issues

## Release Notes

### 0.6.0

- Fix for extension unable to pull scripts from GitHub. Change to utilizing `main` branch of First Responder Kit.
- Adds interactive documentation linking to status bar.

### 0.5.1

- Fix for changes to new editor connection changes in Azure Data Studio 1.15.0
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "drewsk",
"engines": {
"vscode": "^1.25.0",
"azdata": "^1.15.0"
"azdata": "^1.21.0"
},
"categories": [
"Other"
Expand All @@ -18,7 +18,7 @@
"activationEvents": [
"*"
],
"main": "./out/extension",
"main": "./dist/extension",
"contributes": {
"commands": [
{
Expand Down
35 changes: 23 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import * as runScripts from './runScripts';

export function activate(context: vscode.ExtensionContext) {
const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/";
// documentation

// documentation help link
let currentBlitz: string = 'sp_Blitz';
let timeout: NodeJS.Timer | null = null;
var docsspblitz = () => {
openDocumentation(baseUrl, currentBlitz);
};
Expand All @@ -24,15 +25,16 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(docsStatusBar);

function checkSpBlitzType() : void {
let blitzes: string[] = ['sp_Blitz', 'sp_BlitzCache', 'sp_BlitzIndex', 'sp_BlitzFirst', 'sp_BlitzWho'
, 'sp_BlitzInMemoryOLTP', 'sp_BlitzLock', 'sp_BlitzQueryStore', 'sp_BlitzBackups'];
let editorText: string = vscode.window.activeTextEditor.document.getText();
let blitzes: string[] = ['sp_Blitz', 'sp_BlitzIndex', 'sp_BlitzCache', 'sp_BlitzWho', 'sp_BlitzFirst', 'sp_BlitzLock', 'sp_Blitz\''];
let blitzLabel: string = "";
blitzes.forEach( blitz => {
if (editorText.toLowerCase().includes(blitz.toLowerCase())) {
blitzLabel = blitz;
}
});
if (vscode.window.activeTextEditor) {
let editorText: string = vscode.window.activeTextEditor.document.getText();
blitzes.forEach( blitz => {
if (editorText.toLowerCase().includes(blitz.toLowerCase())) {
blitzLabel = blitz.replace('\'','');
}
});
}
if (blitzLabel != "") {
docsStatusBar.text = '$(question) ' + blitzLabel + ' Documentation';
docsStatusBar.show();
Expand All @@ -41,8 +43,17 @@ export function activate(context: vscode.ExtensionContext) {
}
currentBlitz = blitzLabel;
}
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(checkSpBlitzType));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(checkSpBlitzType));

function triggerUpdateDocLink() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(checkSpBlitzType, 1000); // wait a second to avoid hammering
}

context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(triggerUpdateDocLink));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(triggerUpdateDocLink));
context.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(triggerUpdateDocLink));

context.subscriptions.push(disposable_spblitzversion);

Expand Down
11 changes: 7 additions & 4 deletions src/getScripts.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
'use strict';
import * as vscode from 'vscode';
import * as sqlops from 'azdata';
import * as request from 'request-promise-native';
import {placeScript} from './placescript';

const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/";

async function spblitzscript(baseUrl: string, fileName: string) {
async function spblitzscript(baseUrl: string, fileName: string, context?: sqlops.ObjectExplorerContext) {
if(context) { vscode.window.showInformationMessage("context before get: "+ context.connectionProfile.id)};
let options = {
uri: baseUrl + fileName,
};
console.log('Bringing in the first responder kit from the mothership.');
const scriptText = await request.get(options);
new placeScript().placescript(fileName,scriptText);
if(context) { vscode.window.showInformationMessage("context after get: "+ context.connectionProfile.id)};
new placeScript().placescript(fileName, scriptText, context);
}

//importing all first responder kit scripts
export let getblitzall = async () => {
await spblitzscript(baseUrl, "Install-All-Scripts.sql");
export let getblitzall = async (context?: sqlops.ObjectExplorerContext) => {
await spblitzscript(baseUrl, "Install-All-Scripts.sql", context);
};
export let disposable_spblitzall = vscode.commands.registerCommand('extension.sp_blitzall', getblitzall);

Expand Down
26 changes: 23 additions & 3 deletions src/placescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@ import * as sqlops from 'azdata';
import * as vscode from 'vscode';

export class placeScript {

private connectionId: string = '';
private dbName: string = '';
// places scriptText into fileName editor with current connection
public async placescript(fileName, scriptText, context?: sqlops.ObjectExplorerContext) {
var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
try {
let doc = await vscode.workspace.openTextDocument(setting);
let editor = await vscode.window.showTextDocument(doc, 1, false);
let connection;
if (context) {
let connection = context.connectionProfile;
this.connectionId = connection.id;
this.dbName = context.connectionProfile.databaseName;
await vscode.commands.executeCommand('explorer.query', context.connectionProfile);
} else {
await vscode.commands.executeCommand('newQuery');
}

let editor = vscode.window.activeTextEditor;
let doc = editor.document;
editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), scriptText);
});

if (context && this.dbName) {
let providerName = context.connectionProfile.providerName;
let dProvider = await sqlops.dataprotocol.getProvider<sqlops.ConnectionProvider>(providerName, sqlops.DataProviderType.ConnectionProvider);
let connectionUri = await sqlops.connection.getUriForConnection(this.connectionId);
await dProvider.changeDatabase(connectionUri,this.dbName);
await sqlops.queryeditor.connect(doc.uri.toString(), this.connectionId);
}
} catch (err) {
vscode.window.showErrorMessage(err);
}
Expand Down
100 changes: 52 additions & 48 deletions src/updateCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ let apiconfig: apiConfig.apiconfig = require('../apiconfig.json');

// checking spblitz versioning
let getblitzversion = async (context?: sqlops.ObjectExplorerContext) => {
// var amIUPD = new updatecheck();
let updateReturn = await checkForUpdates(context);
if (updateReturn) {
if (updateReturn == 'update') {
getblitzall();
if (context) {
getblitzall(context);
} else {
getblitzall();
}
} else if (updateReturn != '') {
let versionURL = 'https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/tag/' + updateReturn;
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(versionURL));
Expand All @@ -24,19 +27,25 @@ export let disposable_spblitzversion = vscode.commands.registerCommand('extensio

async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise<string> {
let baseUrl = "https://api.github.com/repos/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/latest";

let apitoken = 'token ' + apiconfig.token;
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");

try {
var connectId;
if (context) {
let connection = context.connectionProfile;
connectId = connection.id;
let connectionMaybe = await sqlops.connection.getCurrentConnection();
if (!connectionMaybe) {
throw("Connect to server before checking First Responder Kit version.");
}
} else {
let connection = await sqlops.connection.getCurrentConnection();
if (!connection) {
throw("Connect to server before checking First Responder Kit version.");
}
connectId = connection.connectionId;
}
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");

let query = `declare @versionno datetime
DECLARE @VERSION VARCHAR(30)
Expand All @@ -55,61 +64,56 @@ async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise<
select convert(varchar(10),@versionno,112) as versionno`;

if (connectId) {
let connectionUri = await sqlops.connection.getUriForConnection(connectId);
let queryProvider = sqlops.dataprotocol.getProvider<sqlops.QueryProvider>(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
let results = await queryProvider.runQueryAndReturn(connectionUri, query);
let cell = results.rows[0][0];
let currentVersion = cell.displayValue;
let connectionUri = await sqlops.connection.getUriForConnection(connectId);
let queryProvider = sqlops.dataprotocol.getProvider<sqlops.QueryProvider>(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
let results = await queryProvider.runQueryAndReturn(connectionUri, query);
let cell = results.rows[0][0];
let currentVersion = cell.displayValue;

//get live most recent version from github
var options = {
uri: baseUrl,
headers: {
'Authorization': apitoken,
'User-Agent': 'Request-Promise'
},
json: true,
simple: false
};
var scriptText = await request.get(options);
let recentVersion = scriptText.tag_name;
//get live most recent version from github
var options = {
uri: baseUrl,
headers: {
'Authorization': apitoken,
'User-Agent': 'Request-Promise'
},
json: true,
simple: false
};
var scriptText = await request.get(options);
let recentVersion = scriptText.tag_name;

//compare against db version
if (currentVersion == '19000101') {
let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.'
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
if (buttonName){
if (buttonName == "Get It Now") {
return 'update';
} else if (buttonName == "Tell Me More") {
return recentVersion;
}
} else {
return '';
//compare against db version
if (currentVersion == '19000101') {
let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.'
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
if (buttonName){
if (buttonName == "Get It Now") {
return 'update';
} else if (buttonName == "Tell Me More") {
return recentVersion;
}
} else {
return '';
}
else if (recentVersion > currentVersion) {
let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.'
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
if (buttonName){
if (buttonName == "Get It Now") {
return 'update';
} else if (buttonName == "Tell Me More") {
return recentVersion;
}
} else {
return '';
}
else if (recentVersion > currentVersion) {
let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.'
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
if (buttonName){
if (buttonName == "Get It Now") {
return 'update';
} else if (buttonName == "Tell Me More") {
return recentVersion;
}
} else {
vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close");
return '';
}

} else {
vscode.window.showErrorMessage("Please connect to SQL server to check First Responder Kit version.");
vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close");
return '';
}

} catch (e) {
vscode.window.showErrorMessage(e);
}
Expand Down

0 comments on commit 36c98b4

Please sign in to comment.