Skip to content

Commit

Permalink
feat: add open on github command (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
conwnet authored Apr 30, 2021
1 parent 36523a5 commit 8c1eace
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"onCommand:github1s.switch-to-commit",
"onCommand:github1s.diff-view-open-left-file",
"onCommand:github1s.diff-view-open-right-file",
"onCommand:github1s.open-on-github",
"onView:github1s"
],
"browser": "./dist/extension",
Expand Down Expand Up @@ -198,6 +199,11 @@
"light": "assets/icons/light/close-blame.svg"
},
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
},
{
"command": "github1s.open-on-github",
"title": "Open on GitHub",
"category": "GitHub1s"
}
],
"colors": [
Expand Down
19 changes: 19 additions & 0 deletions extensions/github1s/src/commands/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file GitHub1s Ref Related Commands
* @author netcon
*/

import * as vscode from 'vscode';
import router from '@/router';

export const commandOpenOnGitHub = async () => {
const location = router.history.location;
const githubPath =
location.pathname === '/'
? '/conwnet/github1s'
: `${location.pathname}${location.search}${location.hash}`;
const GITHUB_ORIGIN = 'https://github.com';
const gitHubUri = vscode.Uri.parse(GITHUB_ORIGIN + githubPath);

return vscode.commands.executeCommand('vscode.open', gitHubUri);
};
5 changes: 4 additions & 1 deletion extensions/github1s/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as vscode from 'vscode';
import { getExtensionContext } from '@/helpers/context';
import { pullRequestTreeDataProvider, commitTreeDataProvider } from '@/views';
import {
commandValidateToken,
commandUpdateToken,
Expand Down Expand Up @@ -40,6 +39,7 @@ import {
commandOpenEditorGutterBlame,
commandCloseEditorGutterBlame,
} from './blame';
import { commandOpenOnGitHub } from './global';

const commands: { id: string; callback: (...args: any[]) => any }[] = [
// validate GitHub OAuth Token
Expand Down Expand Up @@ -98,6 +98,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
{ id: 'github1s.open-editor-gutter-blame', callback: commandOpenEditorGutterBlame }, // prettier-ignore
// close the gutter blame of a editor
{ id: 'github1s.close-editor-gutter-blame', callback: commandCloseEditorGutterBlame }, // prettier-ignore

// open current page on GitHub
{ id: 'github1s.open-on-github', callback: commandOpenOnGitHub },
];

export const registerGitHub1sCommands = () => {
Expand Down

0 comments on commit 8c1eace

Please sign in to comment.