Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:

jobs:
build:
permissions:
contents: read

strategy:
matrix:
os: [macos-14]
Expand All @@ -19,6 +22,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand All @@ -28,5 +33,12 @@ jobs:
- run: npm install
- run: npm run eslint
- run: npm run build
- uses: microsoft/playwright-github-action@v1
- run: npm run test:ci
env:
GITHUB_API_PREFIX: http://localhost:8080/api/github
- name: Install snapshot test dependencies
working-directory: tests
run: npm ci && npx playwright install --with-deps
- name: Run snapshot tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx start-server-and-test watch:dev-server http://localhost:8080 "env -u GITHUB_TOKEN npm --prefix tests test"
11 changes: 9 additions & 2 deletions .github/workflows/test-wtih-vscode-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run build
- run: npm run link && npm run build
- uses: microsoft/playwright-github-action@v1
- run: npm run test:ci
env:
GITHUB_API_PREFIX: http://localhost:8080/api/github
- name: Install snapshot test dependencies
working-directory: tests
run: npm ci && npx playwright install --with-deps
- name: Run snapshot tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx start-server-and-test watch:dev-server http://localhost:8080 "env -u GITHUB_TOKEN npm --prefix tests test"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
out
node_modules
.worktrees/
tests/__tests__/__image_snapshots__/__diff_output__/
2 changes: 1 addition & 1 deletion docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ npm run build
npx wrangler pages dev dist
```

Omit the OAuth configuration and export for a preview without GitHub OAuth. Open `http://localhost:8788/conwnet/github1s`. This differs from `npm run watch`, whose webpack server runs on port `8080` and only proxies GitHub code search. See [Pages local development](https://developers.cloudflare.com/pages/functions/local-development/) and [local secrets](https://developers.cloudflare.com/pages/functions/bindings/#local-development-with-secrets).
Omit the OAuth configuration and export for a preview without GitHub OAuth. Open `http://localhost:8788/conwnet/github1s`. See [Pages local development](https://developers.cloudflare.com/pages/functions/local-development/) and [local secrets](https://developers.cloudflare.com/pages/functions/bindings/#local-development-with-secrets).

## Other static hosts

Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The install step also installs dependencies for the local extensions. Watch mode

Wait for the application and both extensions to finish compiling, then open [localhost:8080/conwnet/github1s](http://localhost:8080/conwnet/github1s). The development server uses port `8080` and writes generated assets to `dist/`.

GitHub code search is proxied by the development server. OAuth callback Functions are not run by `npm run watch`; use a manually supplied token for repository authentication or follow the [Pages development instructions](deployment.md#preview-pages-functions-locally).
OAuth callback Functions are not run by `npm run watch`; use a manually supplied token for repository authentication or follow the [Pages development instructions](deployment.md#preview-pages-functions-locally).

## Build the application

Expand Down
98 changes: 29 additions & 69 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"textSearchProvider",
"scmHistoryProvider",
"contribSourceControlHistoryTitleMenu",
"contribSourceControlHistoryItemMenu"
"contribSourceControlHistoryItemMenu",
"timeline"
],
"directories": {
"lib": "lib"
Expand Down Expand Up @@ -74,12 +75,6 @@
}
],
"scm": [
{
"id": "github1s.views.fileHistory",
"name": "File History",
"icon": "$(history)",
"when": "github1s:views:fileHistory:visible == true"
},
{
"id": "github1s.views.codeReviewList",
"name": "Code Reviews",
Expand Down Expand Up @@ -172,18 +167,6 @@
"icon": "$(globe)",
"enablement": "github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket'"
},
{
"command": "github1s.commands.refreshFileHistoryCommitList",
"title": "Refresh",
"category": "GitHub1s",
"icon": "$(refresh)"
},
{
"command": "github1s.commands.refreshCommitList",
"title": "Refresh",
"category": "GitHub1s",
"icon": "$(refresh)"
},
{
"command": "github1s.commands.searchCommit",
"title": "Search",
Expand All @@ -196,12 +179,6 @@
"category": "GitHub1s",
"icon": "$(log-in)"
},
{
"command": "github1s.commands.diffCommitFile",
"title": "Diff File",
"category": "GitHub1s",
"icon": "$(diff)"
},
{
"command": "github1s.commands.openCommitOnGitHub",
"title": "Open on GitHub",
Expand Down Expand Up @@ -423,10 +400,6 @@
"command": "github1s.commands.openCodeReviewOnOfficialPage",
"when": "false"
},
{
"command": "github1s.commands.refreshCommitList",
"when": "false"
},
{
"command": "github1s.commands.searchCommit",
"when": "false"
Expand Down Expand Up @@ -486,16 +459,6 @@
"command": "github1s.commands.searchCodeReview",
"when": "view == 'github1s.views.codeReviewList'",
"group": "navigation@2"
},
{
"command": "github1s.commands.refreshFileHistoryCommitList",
"when": "view == 'github1s.views.fileHistory'",
"group": "navigation@1"
},
{
"command": "github1s.commands.searchCommit",
"when": "view == 'github1s.views.fileHistory'",
"group": "navigation@2"
}
],
"view/item/context": [
Expand Down Expand Up @@ -538,36 +501,6 @@
"command": "github1s.commands.openCodeReviewOnOfficialPage",
"when": "viewItem == 'github1s:viewItems:codeReviewListItem' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
"group": "inline@2"
},
{
"command": "github1s.commands.switchToCommit",
"when": "viewItem == 'github1s:viewItems:commitListItem'",
"group": "inline@1"
},
{
"command": "github1s.commands.openCommitOnGitHub",
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitHub'",
"group": "inline@2"
},
{
"command": "github1s.commands.diffCommitFile",
"when": "viewItem == 'github1s:viewItems:commitListItem' && view == 'github1s.views.fileHistory'",
"group": "inline@3"
},
{
"command": "github1s.commands.openCommitOnGitLab",
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitLab'",
"group": "inline@2"
},
{
"command": "github1s.commands.openCommitOnBitbucket",
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'Bitbucket'",
"group": "inline@2"
},
{
"command": "github1s.commands.openCommitOnOfficialPage",
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
"group": "inline@2"
}
],
"editor/title": [
Expand Down Expand Up @@ -640,6 +573,33 @@
"when": "scmProvider == github1s && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
"group": "inline@2"
}
],
"timeline/item/context": [
{
"command": "github1s.commands.switchToCommit",
"when": "timelineItem == 'github1s:timeline:commit'",
"group": "inline@1"
},
{
"command": "github1s.commands.openCommitOnGitHub",
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'GitHub'",
"group": "inline@2"
},
{
"command": "github1s.commands.openCommitOnGitLab",
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'GitLab'",
"group": "inline@2"
},
{
"command": "github1s.commands.openCommitOnBitbucket",
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'Bitbucket'",
"group": "inline@2"
},
{
"command": "github1s.commands.openCommitOnOfficialPage",
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
"group": "inline@2"
}
]
}
},
Expand Down
2 changes: 0 additions & 2 deletions extensions/github1s/src/adapters/bitbucket1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export class BitbucketAdapter implements Adapter {

activateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);
setVSCodeContext('github1s:features:gutterBlame:enabled', true);
}

deactivateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
}
}
4 changes: 2 additions & 2 deletions extensions/github1s/src/adapters/github1s/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ export class GitHub1sDataSource extends DataSource {
async provideCommitChangedFiles(
repoFullName: string,
ref: string,
_options?: CommonQueryOptions,
options?: CommonQueryOptions,
): Promise<ChangedFile[]> {
const fetcher = GitHubFetcher.getInstance();
const { owner, repo } = parseRepoFullName(repoFullName);
const requestParams = { owner, repo, ref };
const requestParams = { owner, repo, ref, per_page: options?.pageSize, page: options?.page };
const { data } = await fetcher.request('GET /repos/{owner}/{repo}/commits/{ref}', requestParams);
return (
data.files?.map((item) => ({
Expand Down
2 changes: 0 additions & 2 deletions extensions/github1s/src/adapters/github1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class GitHub1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', true);
setVSCodeContext('github1s:views:codeReviewList:visible', true);
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);
setVSCodeContext('github1s:features:gutterBlame:enabled', true);

vscode.window.registerWebviewViewProvider(
Expand All @@ -54,7 +53,6 @@ export class GitHub1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', false);
setVSCodeContext('github1s:views:codeReviewList:visible', false);
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
}
}
9 changes: 6 additions & 3 deletions extensions/github1s/src/adapters/gitlab1s/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,13 @@ export class GitLab1sDataSource extends DataSource {
}

@trySourcegraphApiFirst
async provideCommitChangedFiles(repo: string, ref: string, _options?: CommonQueryOptions): Promise<ChangedFile[]> {
async provideCommitChangedFiles(repo: string, ref: string, options?: CommonQueryOptions): Promise<ChangedFile[]> {
const fetcher = GitLabFetcher.getInstance();
const requestParams = { repo, ref };
const { data } = await fetcher.request('GET /projects/{repo}/repository/commits/{ref}/diff', requestParams);
const requestParams = { repo, ref, per_page: options?.pageSize, page: options?.page };
const { data } = await fetcher.request(
'GET /projects/{repo}/repository/commits/{ref}/diff?per_page={per_page}&page={page}',
requestParams,
);
return (
data?.map((item) => ({
path: normalizePath(item.new_path || item.old_path!),
Expand Down
2 changes: 0 additions & 2 deletions extensions/github1s/src/adapters/gitlab1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class GitLab1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', true);
setVSCodeContext('github1s:views:codeReviewList:visible', true);
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);
setVSCodeContext('github1s:features:gutterBlame:enabled', true);

vscode.window.registerWebviewViewProvider(
Expand All @@ -52,7 +51,6 @@ export class GitLab1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', false);
setVSCodeContext('github1s:views:codeReviewList:visible', false);
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
}
}
13 changes: 9 additions & 4 deletions extensions/github1s/src/adapters/sourcegraph/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { ChangedFile, FileChangeStatus } from '../types';
import { querySourcegraphRepository } from './common';

const ComparisonQuery = gql`
query ($repository: String!, $base: String!, $head: String!) {
query ($repository: String!, $base: String!, $head: String!, $first: Int) {
repository(name: $repository) {
comparison(base: $base, head: $head) {
fileDiffs {
fileDiffs(first: $first) {
nodes {
newPath
oldPath
Expand All @@ -35,10 +35,15 @@ const getFileChangeStatus = (oldPath: string | null, newPath: string | null): Fi
return FileChangeStatus.Modified;
};

export const compareCommits = async (repository: string, base: string, head: string): Promise<ChangedFile[]> => {
export const compareCommits = async (
repository: string,
base: string,
head: string,
limit?: number,
): Promise<ChangedFile[]> => {
const repositoryData = await querySourcegraphRepository({
query: ComparisonQuery,
variables: { repository, base, head },
variables: { repository, base, head, first: limit },
});
const diffFiles = repositoryData.comparison?.fileDiffs?.nodes || [];

Expand Down
11 changes: 9 additions & 2 deletions extensions/github1s/src/adapters/sourcegraph/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,15 @@ export class SourcegraphDataSource extends DataSource {
return getCommit(this.buildRepository(repo), ref);
}

async provideCommitChangedFiles(repo: string, ref: string, _options?: CommonQueryOptions): Promise<ChangedFile[]> {
return (await compareCommits(this.buildRepository(repo), `${ref}~`, ref)).map((file) => ({
async provideCommitChangedFiles(repo: string, ref: string, options?: CommonQueryOptions): Promise<ChangedFile[]> {
const changedFiles = await compareCommits(
this.buildRepository(repo),
`${ref}~`,
ref,
options?.pageSize ? options.pageSize * (options.page || 1) : undefined,
);
const files = options?.pageSize ? changedFiles.slice(options.pageSize * ((options.page || 1) - 1)) : changedFiles;
return files.map((file) => ({
...file,
path: normalizePath(file.path),
previousPath: file.previousPath ? normalizePath(file.previousPath) : undefined,
Expand Down
11 changes: 7 additions & 4 deletions extensions/github1s/src/changes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ export const getCodeReviewChangedFiles = async (
});
};

export const getCommitChangedFiles = async (commit: adapterTypes.Commit) => {
const repository = Repository.getCurrentInstance();
export const getCommitChangedFiles = async (
commit: adapterTypes.Commit,
repository = Repository.getCurrentInstance(),
) => {
const { scheme, repo } = repository;
// if the commit.parents is more than one element
// the parents[1].sha should be the merge source commitSha
// so we use the parents[0].sha as the parent commitSha
const parentCommitSha = commit?.parents?.[0] || '';
const baseRootUri = router.buildUri({ ref: parentCommitSha });
const headRootUri = router.buildUri({ ref: commit.sha }, baseRootUri);
const headRootUri = router.buildUri({ scheme, repo, ref: commit.sha });
const baseRootUri = router.buildUri({ ref: parentCommitSha }, headRootUri);
const changedFiles = await repository.getCommitChangedFiles(commit.sha);

return changedFiles.map((commitFile) => {
Expand Down
Loading
Loading