Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
conwnet committed Mar 14, 2021
2 parents f98aa96 + 94a3180 commit c2928e9
Show file tree
Hide file tree
Showing 40 changed files with 1,529 additions and 1,131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml → .github/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
newIssueWelcomeComment: >
Hello there!👋 Welcome to the project!💖
Thank you and congrats🎉for opening your very first issue in this project.Be patient while we get back to you.😄
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
# Comment to be posted to on PRs from first time contributors in your repository

newPRWelcomeComment: >
Hello there!👋 Welcome to the project!💖
Thank you and congrats🎉 for opening your first pull request✨ 🙌.We will get back to you as soon as we can.😄
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
# Comment to be posted to on pull requests merged by a first time user

Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04]
node-version: [14.x, 15.x]
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -31,13 +31,11 @@ jobs:
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ matrix.node-version }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ matrix.node-version }}
${{ runner.os }}-yarn-${{ matrix.node-version }}
- run: yarn --frozen-lockfile --network-timeout 500000
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn --frozen-lockfile
- run: yarn eslint
- run: yarn build
- uses: microsoft/playwright-github-action@v1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _Note_: If you already closed the notification, you can find a "Develop your pro

If you want to view non-public repositories, you need to add an OAuth token. The token is stored only in your browser, and only send to GitHub when fetching your repository's files. Click on the icon near the bottom of the left-hand row of icons, and the dialog box will prompt you for it, and even take you to your GitHub settings page to generate one, if needed.

![VS Code - GitHub1s](https://raw.githubusercontent.com/timbaileyjones/github1s/master/resources/images/auth-token.png)
<img height="500px" src="https://raw.githubusercontent.com/timbaileyjones/github1s/master/resources/images/auth-token.png" />

## Screenshots

Expand Down Expand Up @@ -116,7 +116,7 @@ $ yarn build
The continued development and maintenance of GitHub1s is made possible by these generous sponsors:

<table><tbody><tr>
<td><a href="https://vercel.com/?utm_source=vscode-github1s&utm_campaign=oss">
<td><a href="https://sourcegraph.com/">
<img height="40px" src="https://raw.githubusercontent.com/conwnet/github1s/master/resources/images/sourcegraph-logo.svg">
</a></td>
<td><a href="https://vercel.com/?utm_source=vscode-github1s&utm_campaign=oss">
Expand Down
51 changes: 42 additions & 9 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"onCommand:github1s.update-token",
"onCommand:github1s.clear-token",
"onCommand:github1s.get-current-authority",
"onCommand:github1s.switch-branch",
"onCommand:github1s.switch-tag",
"onCommand:github1s.checkout-ref",
"onView:github1s"
],
"browser": "./dist/extension",
Expand Down Expand Up @@ -58,20 +57,53 @@
"category": "GitHub1s"
},
{
"command": "github1s.switch-branch",
"title": "Switch to Another Branch",
"category": "GitHub1s"
},
{
"command": "github1s.switch-tag",
"title": "Switch to Another Tag",
"command": "github1s.checkout-ref",
"title": "Checkout to...",
"category": "GitHub1s"
},
{
"command": "github1s.open-gitpod",
"title": "Edit files in Gitpod",
"category": "GitHub1s"
}
],
"colors": [
{
"id": "gitDecoration.addedResourceForeground",
"description": "%colors.added%",
"defaults": {
"light": "#587c0c",
"dark": "#81b88b",
"highContrast": "#1b5225"
}
},
{
"id": "gitDecoration.deletedResourceForeground",
"description": "%colors.deleted%",
"defaults": {
"light": "#ad0707",
"dark": "#c74e39",
"highContrast": "#c74e39"
}
},
{
"id": "gitDecoration.modifiedResourceForeground",
"description": "%colors.modified%",
"defaults": {
"light": "#895503",
"dark": "#E2C08D",
"highContrast": "#E2C08D"
}
},
{
"id": "gitDecoration.submoduleResourceForeground",
"description": "%colors.submodule%",
"defaults": {
"light": "#1258a7",
"dark": "#8db9e2",
"highContrast": "#8db9e2"
}
}
]
},
"scripts": {
Expand All @@ -87,6 +119,7 @@
"@apollo/client": "^3.3.9",
"fuse.js": "^6.4.6",
"graphql": "^15.5.0",
"history": "^5.0.0",
"js-base64": "^3.6.0",
"json-stable-stringify": "^1.0.1",
"p-finally": "^2.0.1",
Expand Down
81 changes: 34 additions & 47 deletions extensions/github1s/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@

import * as vscode from 'vscode';
import { getExtensionContext } from '@/helpers/context';
import {
getRepositoryBranchRefs,
getRepositoryTagRefs,
getCurrentRef,
getCurrentAuthority,
changeCurrentRef,
} from '@/helpers/git-ref';
import router from '@/router';
import repository from '@/repository';
import { validateToken } from '@/interfaces/github-api-rest';

export const commandValidateToken = (silent: boolean = false) => {
Expand Down Expand Up @@ -111,53 +106,45 @@ export const commandClearToken = (silent: boolean = false) => {
});
};

export const commandGetCurrentAuthority = (): Promise<string> =>
getCurrentAuthority();
export const commandGetCurrentAuthority = () => router.getAuthority();

export const commandSwitchBranch = () => {
return Promise.all([getRepositoryBranchRefs(), getCurrentRef()]).then(
([repositoryBranches, currentRef]) =>
vscode.window
.showQuickPick(
repositoryBranches.map((item) => item.name),
{ placeHolder: currentRef }
)
.then((newRef: string) => {
return (
newRef &&
changeCurrentRef(newRef).then((newRef) => {
vscode.window.showInformationMessage(
`Switch to branch: ${newRef}`
);
})
);
})
export const commandCheckoutRef = async () => {
const [branchRefs, tagRefs] = await Promise.all([
repository.getBranches(),
repository.getTags(),
]);
const branchPickerItems: vscode.QuickPickItem[] = branchRefs.map(
(branchRef) => ({
label: branchRef.name,
description: (branchRef.object?.sha || '').slice(0, 8),
})
);
};
const tagPickerItems: vscode.QuickPickItem[] = tagRefs.map((tagRef) => ({
label: tagRef.name,
description: `Tag at ${(tagRef.object?.sha || '').slice(0, 8)}`,
}));

export const commandSwitchTag = () => {
return Promise.all([getRepositoryTagRefs(), getCurrentRef()]).then(
([repositoryBranches, currentRef]) =>
vscode.window
.showQuickPick(
repositoryBranches.map((item) => item.name),
{ placeHolder: currentRef }
)
.then((newRef: string) => {
return (
newRef &&
changeCurrentRef(newRef).then((newRef) => {
vscode.window.showInformationMessage(
`Switch to branch: ${newRef}`
);
})
);
})
const quickPick = vscode.window.createQuickPick();
const routerState = await router.getState();
quickPick.placeholder = routerState.ref;
quickPick.items = [...branchPickerItems, ...tagPickerItems];

quickPick.show();
const choice = await new Promise<vscode.QuickPickItem | undefined>(
(resolve) => quickPick.onDidAccept(() => resolve(quickPick.activeItems[0]))
);
quickPick.hide();

const targetRef = choice?.label || quickPick.value;
if (targetRef.toUpperCase() === 'HEAD') {
router.replace(`/${routerState.owner}/${routerState.repo}`);
return;
}
router.replace(`/${routerState.owner}/${routerState.repo}/tree/${targetRef}`);
};

export const commandOpenGitpod = () => {
return getCurrentAuthority().then((currentAuthority) => {
return router.getAuthority().then((currentAuthority) => {
const [currentOwner, currentRepo] = currentAuthority.split('+');
vscode.commands.executeCommand(
'vscode.open',
Expand Down
100 changes: 48 additions & 52 deletions extensions/github1s/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,28 @@ import {
commandUpdateToken,
commandValidateToken,
commandClearToken,
commandSwitchBranch,
commandSwitchTag,
commandCheckoutRef,
commandGetCurrentAuthority,
commandOpenGitpod,
} from '@/commands';
import {
GitHub1sFileSystemProvider,
GitHub1sFileSearchProvider,
GitHub1sTextSearchProvider,
GitHub1sSubmoduleDecorationProvider,
} from '@/providers';
import { registerVSCodeProviders } from '@/providers';
import { GitHub1sFileSystemProvider } from '@/providers/fileSystemProvider';
import { showSponsors } from '@/sponsors';
import { showGitpod } from '@/gitpod';
import router from '@/router';
import { activateSourceControl } from '@/source-control';
import { registerEventListeners } from '@/listeners';
import { PageType } from './router/types';

export async function activate(context: vscode.ExtensionContext) {
// set the global context for convenient
setExtensionContext(context);

// providers
const fsProvider = new GitHub1sFileSystemProvider();
context.subscriptions.push(
vscode.workspace.registerFileSystemProvider(
GitHub1sFileSystemProvider.scheme,
fsProvider,
{
isCaseSensitive: true,
isReadonly: true,
}
),
vscode.workspace.registerFileSearchProvider(
GitHub1sFileSearchProvider.scheme,
new GitHub1sFileSearchProvider(fsProvider)
),
vscode.workspace.registerTextSearchProvider(
GitHub1sTextSearchProvider.scheme,
new GitHub1sTextSearchProvider()
),
vscode.window.registerFileDecorationProvider(
new GitHub1sSubmoduleDecorationProvider(fsProvider)
)
);
// Ensure the router has been initialized at first
await router.initialize();
// register the necessary event listeners
registerEventListeners();
// register VS Code providers
registerVSCodeProviders();

// views
context.subscriptions.push(
Expand All @@ -61,37 +43,51 @@ export async function activate(context: vscode.ExtensionContext) {

// commands
context.subscriptions.push(
// validate GitHub OAuth Token
vscode.commands.registerCommand(
'github1s.validate-token',
commandValidateToken
)
);
context.subscriptions.push(
vscode.commands.registerCommand('github1s.update-token', commandUpdateToken)
);
context.subscriptions.push(
vscode.commands.registerCommand('github1s.clear-token', commandClearToken)
);
context.subscriptions.push(
),
// update GitHub OAuth Token
vscode.commands.registerCommand(
'github1s.update-token',
commandUpdateToken
),
// clear GitHub OAuth Token
vscode.commands.registerCommand('github1s.clear-token', commandClearToken),

// get current authority (`${owner}+${repo}+${ref}`)
vscode.commands.registerCommand(
'github1s.get-current-authority',
commandGetCurrentAuthority
)
);
context.subscriptions.push(
),

// checkout to other branch/tag/commit
vscode.commands.registerCommand(
'github1s.switch-branch',
commandSwitchBranch
)
);
context.subscriptions.push(
vscode.commands.registerCommand('github1s.switch-tag', commandSwitchTag)
);
context.subscriptions.push(
'github1s.checkout-ref',
commandCheckoutRef
),

// open current repository on gitpod
vscode.commands.registerCommand('github1s.open-gitpod', commandOpenGitpod)
);

// activate SourceControl features,
activateSourceControl();

// sponsors in Status Bar
showSponsors();
await showGitpod();

// open corresponding editor if there is a filePath specified in browser url
const { filePath, pageType } = await router.getState();
if (filePath && [PageType.TREE, PageType.BLOB].includes(pageType)) {
vscode.commands.executeCommand(
pageType === PageType.TREE ? 'revealInExplorer' : 'vscode.open',
vscode.Uri.parse('').with({
scheme: GitHub1sFileSystemProvider.scheme,
path: filePath,
})
);
}
}
Loading

1 comment on commit c2928e9

@vercel
Copy link

@vercel vercel bot commented on c2928e9 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.