Skip to content

Commit 3df064b

Browse files
author
Mike Nikles
authored
Allow users to edit files with Gitpod. (conwnet#214)
* Allow users to edit files with Gitpod. * Provide a command to edit files in Gitpod. * Provide a Gitpod link in the status bar so it is visible if the notification is closed. * Document how to invoke Gitpod if the notification is no longer visible. * Add Gitpod screenshots. * Fix the image paths.
1 parent b0c1857 commit 3df064b

9 files changed

Lines changed: 86 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ Or save the following code snippet as a bookmarklet, you can use it to quickly s
2222
javascript: window.location.href = window.location.href.replace(/github(1s)?.com/, function(match, p1) { return p1 ? 'github.com' : 'github1s.com' })
2323
```
2424

25+
### Develop in the cloud
26+
27+
To edit files, run Docker containers, create pull requests and more, click the "[Gitpod](https://www.gitpod.io) ready-to-code" button at the bottom of your browser once you open your project with github1s.
28+
29+
![Gitpod Notification](https://raw.githubusercontent.com/conwnet/github1s/master/resources/images/gitpod-notification.png)
30+
31+
_Note_: If you already closed the notification, you can find a "Develop your project on Gitpod" button in the status bar. You can also open the Command Palette (default shortcut `Ctrl+Shift+P`) and choose `GitHub1s: Edit files in Gitpod`.
32+
33+
![Gitpod Status Bar](https://raw.githubusercontent.com/conwnet/github1s/master/resources/images/gitpod-statusbar.png)
34+
2535
## Documentation
2636

2737
- [How it works](https://github.com/conwnet/github1s/blob/master/docs/guide.md)

‎extensions/github1s/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
"command": "github1s.switch-tag",
6767
"title": "Switch to Another Tag",
6868
"category": "GitHub1s"
69+
},
70+
{
71+
"command": "github1s.open-gitpod",
72+
"title": "Edit files in Gitpod",
73+
"category": "GitHub1s"
6974
}
7075
]
7176
},

‎extensions/github1s/src/commands.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,15 @@ export const commandSwitchTag = () => {
155155
})
156156
);
157157
};
158+
159+
export const commandOpenGitpod = () => {
160+
return getCurrentAuthority().then((currentAuthority) => {
161+
const [currentOwner, currentRepo] = currentAuthority.split('+');
162+
vscode.commands.executeCommand(
163+
'vscode.open',
164+
vscode.Uri.parse(
165+
`https://gitpod.io/#https://github.com/${currentOwner}/${currentRepo}`
166+
)
167+
);
168+
});
169+
};

‎extensions/github1s/src/extension.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
commandSwitchBranch,
1414
commandSwitchTag,
1515
commandGetCurrentAuthority,
16+
commandOpenGitpod,
1617
} from '@/commands';
1718
import {
1819
GitHub1sFileSystemProvider,
@@ -21,8 +22,9 @@ import {
2122
GitHub1sSubmoduleDecorationProvider,
2223
} from '@/providers';
2324
import { showSponsors } from '@/sponsors';
25+
import { showGitpod } from '@/gitpod';
2426

25-
export function activate(context: vscode.ExtensionContext) {
27+
export async function activate(context: vscode.ExtensionContext) {
2628
setExtensionContext(context);
2729

2830
// providers
@@ -85,7 +87,11 @@ export function activate(context: vscode.ExtensionContext) {
8587
context.subscriptions.push(
8688
vscode.commands.registerCommand('github1s.switch-tag', commandSwitchTag)
8789
);
90+
context.subscriptions.push(
91+
vscode.commands.registerCommand('github1s.open-gitpod', commandOpenGitpod)
92+
);
8893

8994
// sponsors in Status Bar
9095
showSponsors();
96+
await showGitpod();
9197
}

‎extensions/github1s/src/gitpod.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file Show Gitpod In Status Bar
3+
* @author mikenikles
4+
*/
5+
6+
import * as vscode from 'vscode';
7+
import { getCurrentAuthority } from '@/helpers/git-ref';
8+
9+
const getGitpodRepoUri = () =>
10+
getCurrentAuthority().then((currentAuthority) => {
11+
const [currentOwner, currentRepo] = currentAuthority.split('+');
12+
return vscode.Uri.parse(
13+
`https://gitpod.io/#https://github.com/${currentOwner}/${currentRepo}`
14+
);
15+
});
16+
17+
export const showGitpod = async () => {
18+
const gitpodRepoUri = await getGitpodRepoUri();
19+
20+
const item = vscode.window.createStatusBarItem(
21+
vscode.StatusBarAlignment.Left,
22+
0
23+
);
24+
item.text = ' $(pencil) Develop your project on Gitpod';
25+
item.tooltip = 'Edit files, open/review PRs, use Docker - all online.';
26+
item.command = {
27+
title: `Open Gitpod`,
28+
command: 'vscode.open',
29+
arguments: [gitpodRepoUri],
30+
};
31+
item.show();
32+
};
235 KB
Loading
70.2 KB
Loading

‎src/vs/github1s/notification.ts‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@ const NOTIFICATION_STORAGE_KEY = 'GITHUB1S_NOTIFICATION';
99
// Change this if a new notification should be shown
1010
const NOTIFICATION_STORAGE_VALUE = '20210212';
1111

12-
const notification = {
12+
const getGitpodRepoUrl = () => window.location.pathname.match(/^\/[^\/]+\/[^\/]+/) ? `https://gitpod.io/#https://github.com${window.location.pathname.match(/^\/[^\/]+\/[^\/]+/)![0]}` : '';
13+
14+
const notifications = [{
1315
title: 'ATTENTION: This page is NOT officially provided by GitHub.',
1416
content:
1517
'GitHub1s is an open source project, which is not officially provided by GitHub.',
1618
link: 'https://github.com/conwnet/github1s',
17-
};
19+
}, {
20+
title: `<a class="notification-link" href="${getGitpodRepoUrl()}" alt="Gitpod ready-to-code" target="_blank"><img src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod"></a>`,
21+
content:
22+
'Click the button above to develop your project in the cloud.',
23+
}];
1824

19-
const notificationHtml = `
20-
<div class="notification-main">
21-
<div class="notification-title">${notification.title}</div>
22-
<div class="notification-content">
23-
${notification.content}
24-
<a class="notification-link" href="${notification.link}" target="_blank">See more</a>
25-
</div>
26-
</div>
25+
const notificationHtml = `${
26+
notifications.map(notification => (`
27+
<div class="notification-main">
28+
<div class="notification-title">${notification.title}</div>
29+
<div class="notification-content">
30+
${notification.content}
31+
${notification.link ? `<a class="notification-link" href="${notification.link}" target="_blank">See more</a>` : ''}
32+
</div>
33+
</div>`
34+
))
35+
}
2736
<div class="notification-footer">
2837
<button class="notification-confirm-button">OK</button>
2938
<div class="notification-show-me-again">

‎src/vs/workbench/contrib/url/browser/trustedDomains.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ const github1sDefaultTrustedDomains = [
307307
'*.github1s.com',
308308
'*.vercel.com',
309309
'*.sourcegraph.com',
310+
'*.gitpod.io',
310311
];
311312

312313
export function readStaticTrustedDomains(

0 commit comments

Comments
 (0)