Skip to content

Commit

Permalink
feat: adds configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Howard committed Dec 29, 2018
1 parent 7e7c359 commit 30d1e31
Show file tree
Hide file tree
Showing 39 changed files with 149 additions and 57 deletions.
61 changes: 28 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ Access your GitHub Gists within Visual Studio Code. You can add, edit, and delet
Press <kbd>F1</kbd> and narrow down the list commands by typing `extension`. Pick `Extensions: Install Extensions`.
Select the `Gist Extension` extension from the list.

## GitHub Authentication
## GitHub Profiles

The plugin requires you authenticate with GitHub.
_**NOTE:** You must provide a personal access token to be authenticated with GitHub or a GitHub Enterprise instance._

You can either enter a username and password or a personal access token.
Press <kbd>F1</kbd> and type `select profile` to initialize the profile selector. You can add as many profiles as you would like.

### Login With Username
![login-username](./images/login-username.gif)
![vscode-gist-profiles](./images/vscode-gist-profiles.gif)

### Login With Access Token

Note: To access _Login With Access Token_, leave username blank and press <kbd>ENTER</kbd> or <kbd>ESCAPE</kbd> and jump to this option.

![login-access-token](./images/login-access-token.gif)
If you are using a GitHub Enterprise account, be sure to add the appropriate API url. This extension uses the REST v3 API by GitHub. Your GHE API url should look similar to this: `http(s)://[hostname]/api/v3` [(documentation)](https://developer.github.com/enterprise/2.13/v3/#schema)

## Usage

Expand All @@ -36,7 +31,7 @@ You must have a file open and active to create a gist.
Press <kbd>F1</kbd> and enter the following:

~~~
GIST: Create New Block
GIST: Create New Gist
~~~

You will be prompted a gist description.
Expand All @@ -46,8 +41,8 @@ You will be prompted a gist description.
Press <kbd>F1</kbd> and enter one fo the following:

~~~
GIST: Open Block
GIST: Open Favorite Block
GIST: Open Gist
GIST: Open Favorite Gist
~~~

All files associated with the gist will be opened in group layout.
Expand All @@ -59,29 +54,29 @@ Once you have opened an **owned*** gist, saving it will commit a new revision.
You can also use the following commands:

~~~
GIST: Delete Block
GIST: Remove From Block
GIST: Add To Block
GIST: Change Block Description
GIST: Delete Gist
GIST: Delete File
GIST: Add File
GIST: Open Block In Browser
GIST: Insert Code Into Current File
GIST: Insert Text From Gist File
~~~

## Keyboard Shortcuts

You can associate the following commands to your own keyboard shortcuts:

~~~
extension.openCodeBlock
extension.openFavoriteCodeBlock
extension.createCodeBlock
extension.openCodeBlockInBrowser
extension.deleteCodeBlock
extension.removeFileFromCodeBlock
extension.addToCodeBlock
extension.changeCodeBlockDescription
extension.insertCode
~~~
## All Commands & Keyboard Mappings

Here is a list of commands and their mapped keyboard shortcuts

| Command | Command Pallet Label | Keyboard Mapping | Notes |
|:--------|:---------------------|:-----------------|:------|
|extension.gist.open|Open Gist|ctrl+alt+o|
|extension.gist.openFavorite|Open Favorite Gist|not mapped|
|extension.gist.create|Create New Gist|not mapped|
|extension.gist.openInBrowser|Open Gist In Browser|ctrl+alt+b|
|extension.gist.delete|Delete Gist|not mapped|
|extension.gist.deleteFile|Delete File|not mapped|
|extension.gist.add|Add File|ctrl+alt+a ctrl+alt+a|
|extension.gist.insert|Insert Text From Gist File|not mapped|
|extension.profile.select|Select Profile|ctrl+alt+=|
|extension.resetState|n/a|ctrl+alt+0|Delete All Extension Memory (removes auth tokens)|

## Show Your Support

Expand Down
Binary file added images/vscode-gist-profiles.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
testMatch: ['**/__tests__/**/(*.)+(spec|test).ts?(x)'],
coverageThreshold: {
global: {
branches: 70, // TODO: adjust this back to 80%
branches: 68, // TODO: adjust this back to 80%
functions: 80,
lines: 80,
statements: 80
Expand Down
33 changes: 28 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
],
"main": "./out/extension",
"contributes": {
"configuration": {
"type": "object",
"title": "Gist configuration",
"properties": {
"gist.maxFiles": {
"type": "number",
"default": 10,
"description": "The maximum number of files to open without a prompt."
},
"gist.defaultPrivate": {
"type": "boolean",
"default": false,
"description": "Defaults all newly created Gists to PRIVATE."
}
}
},
"commands": [
{
"command": "extension.gist.open",
Expand Down Expand Up @@ -52,11 +68,6 @@
"title": "Add File",
"category": "GIST"
},
{
"command": "extension.changeCodeBlockDescription",
"title": "Change Block Description",
"category": "GIST"
},
{
"command": "extension.gist.insert",
"title": "Insert Text From Gist File",
Expand All @@ -76,6 +87,18 @@
{
"command": "extension.resetState",
"key": "ctrl+alt+0"
},
{
"command": "extension.gist.add",
"key": "ctrl+alt+a ctrl+alt+a"
},
{
"command": "extension.gist.openInBrowser",
"key": "ctrl+alt+b"
},
{
"command": "extension.gist.open",
"key": "ctrl+alt+o"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ const commandInitializers: CommandInitializer[] = [
];

const init = (
config: Configuration,
services: Services,
initializers: CommandInitializer[] = commandInitializers
): Disposable[] => {
const { insights, logger } = services;

const registerCommand = (commandInit: CommandInitializer): Disposable => {
const [command, commandFn] = commandInit(services, utils);
const [command, commandFn] = commandInit(config, services, utils);

return commands.registerCommand(command, commandFn);
};
Expand Down
6 changes: 5 additions & 1 deletion src/commands/gists/__tests__/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ describe('open gist', () => {
};
const insights = { exception: jest.fn() };
const logger = { debug: jest.fn(), error: errorMock, info: jest.fn() };
addFn = add({ gists, insights, logger } as any, utilsMock as any)[1];
addFn = add(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
(<any>window).activeTextEditor = undefined;
});
afterEach(() => {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/gists/__tests__/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ describe('create gist', () => {
const gists = { createGist: createGistMock };
const insights = { exception: jest.fn() };
const logger = { error: errorMock };
createFn = create({ gists, insights, logger } as any, utilsMock as any)[1];
createFn = create(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
(<any>window).activeTextEditor = undefined;
});
afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/__tests__/delete-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('open gist', () => {
const insights = { exception: jest.fn() };
const logger = { error: errorMock, info: jest.fn() };
deleteFileFn = deleteFile(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/__tests__/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('open gist', () => {
const insights = { exception: jest.fn() };
const logger = { error: errorMock, info: jest.fn() };
deleteFn = deleteCommand(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
Expand Down
6 changes: 5 additions & 1 deletion src/commands/gists/__tests__/insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ describe('open gist', () => {
};
const insights = { exception: jest.fn() };
const logger = { debug: jest.fn(), error: errorMock, info: jest.fn() };
insertFn = insert({ gists, insights, logger } as any, utilsMock as any)[1];
insertFn = insert(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
window.activeTextEditor = <any>{
document: { getText: jest.fn() },
selection: { isEmpty: true }
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/__tests__/open-favorite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('open favorite gist', () => {
const insights = { exception: jest.fn() };
const logger = { error: errorMock, info: jest.fn() };
openFavoriteFn = openFavorite(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/__tests__/open-in-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('open favorite gist', () => {
const insights = { exception: jest.fn() };
const logger = { error: errorMock, info: jest.fn() };
openInBrowserFn = openInBrowser(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
Expand Down
6 changes: 5 additions & 1 deletion src/commands/gists/__tests__/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ describe('open gist', () => {
const gists = { getGists: getGistsMock, getGist: getGistMock };
const insights = { exception: jest.fn() };
const logger = { error: errorMock, info: jest.fn() };
openFn = open({ gists, insights, logger } as any, utilsMock as any)[1];
openFn = open(
{ get: jest.fn() },
{ gists, insights, logger } as any,
utilsMock as any
)[1];
(<any>window).activeTextEditor = undefined;
});
afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/__tests__/update-access-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('update access key', () => {
const insights = { track: jest.fn() };
const logger = { debug: jest.fn() };
updateAccessKeyFn = updateAccessKey(
{ get: jest.fn() },
{ gists, insights, logger, profiles } as any,
utilsMock as any
)[1];
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { window } from 'vscode';
import { GistCommands } from '../extension-commands';

const add: CommandInitializer = (
_config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down
9 changes: 7 additions & 2 deletions src/commands/gists/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GistCommands } from '../extension-commands';
import { openGist } from './utils';

const create: CommandInitializer = (
config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand All @@ -26,8 +27,12 @@ const create: CommandInitializer = (
const details = utils.files.extractTextDocumentDetails(editor.document);
const filename = (details && details.filename) || 'untitled.txt';
const description = await utils.input.prompt('Enter description');
const defaultValue = config.get<boolean>('defaultPrivate') ? 'N' : 'Y';
const isPublic =
((await utils.input.prompt('Public? Y = Yes, N = No', 'Y')) || 'Y') // TODO: add configuration for default value
(
(await utils.input.prompt('Public? Y = Yes, N = No', defaultValue)) ||
defaultValue
)
.slice(0, 1)
.toLowerCase() === 'y';

Expand All @@ -39,7 +44,7 @@ const create: CommandInitializer = (
isPublic
);

await openGist(gist);
await openGist(gist, config.get<number>('maxFiles'));
} catch (err) {
const context = gistName ? ` ${gistName}` : '';
const error: Error = err as Error;
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/delete-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { commands, window } from 'vscode';
import { GistCommands } from '../extension-commands';

const deleteFile: CommandInitializer = (
_config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { commands, window } from 'vscode';
import { GistCommands } from '../extension-commands';

const deleteCommand: CommandInitializer = (
_config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GistCommands } from '../extension-commands';
import { insertText, selectFile } from './utils';

const insert: CommandInitializer = (
_config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/gists/open-favorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GistCommands } from '../extension-commands';
import { openGist } from './utils';

const openFavorite: CommandInitializer = (
config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down Expand Up @@ -34,7 +35,8 @@ const openFavorite: CommandInitializer = (
logger.info(`User Selected Gist: "${selected.label}"`);

const { fileCount } = await openGist(
await gists.getGist(selected.block.id)
await gists.getGist(selected.block.id),
config.get<number>('maxFiles')
);

logger.info('Opened Gist');
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/open-in-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { commands, Uri, window } from 'vscode';
import { GistCommands } from '../extension-commands';

const openInBrowser: CommandInitializer = (
_config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/gists/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GistCommands } from '../extension-commands';
import { openGist } from './utils';

const open: CommandInitializer = (
config: Configuration,
services: Services,
utils: Utils
): [Command, CommandFn] => {
Expand All @@ -23,7 +24,8 @@ const open: CommandInitializer = (
logger.info(`User Selected Gist: "${selected.label}"`);

const { fileCount } = await openGist(
await gists.getGist(selected.block.id)
await gists.getGist(selected.block.id),
config.get<number>('maxFiles')
);

logger.info('Opened Gist');
Expand Down
1 change: 1 addition & 0 deletions src/commands/gists/update-access-key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GistCommands } from '../extension-commands';

const updateAccessKey: CommandInitializer = (
_config: Configuration,
services: Services,
_utils: Utils
): [Command, CommandFn] => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gists/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const _openDocument = async (file: string): Promise<void> => {

const openGist = async (
gist: Gist,
maxFiles = 10 // TODO: make this a config option
maxFiles = 10
): Promise<{
fileCount: number;
files: { [x: string]: { content: string } };
Expand Down
1 change: 1 addition & 0 deletions src/commands/profiles/__tests__/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('create profile', () => {
const logger = { error: errorMock };
const profiles = { add: addMock };
createFn = create(
{ get: jest.fn() },
{ insights, logger, profiles } as any,
utilsMock as any
)[1];
Expand Down

0 comments on commit 30d1e31

Please sign in to comment.