fix gitsync (#6152)

* buffer in node rather than the renderer

* handle no internet
This commit is contained in:
Jack Kavanagh 2023-07-13 19:09:02 +02:00 committed by GitHub
parent 35d6e24867
commit 6f60482853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 34 deletions

View File

@ -1,5 +1,15 @@
import { test } from '../../playwright/test';
test('Clone from github', async ({ page }) => {
await page.getByRole('button', { name: 'Git Clone' }).click();
await page.getByRole('tab', { name: ' Git' }).click();
await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/gatzjames/insomnia-git-example.git');
await page.getByPlaceholder('Name').fill('J');
await page.getByPlaceholder('Email').fill('J');
await page.getByPlaceholder('MyUser').fill('J');
await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill('J');
await page.getByTestId('git-repository-settings-modal__sync-btn').click();
await page.getByRole('button', { name: 'Toggle Preview' }).click();
});
test('Sign in with GitHub', async ({ app, page }) => {
await page.getByRole('button', { name: 'New Document' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();

View File

@ -25,7 +25,11 @@ export const axiosRequest = async (config: AxiosRequestConfig): Promise<AxiosRes
// ignore HTTP_PROXY, HTTPS_PROXY, NO_PROXY environment variables
proxy: false,
};
// hack for http-client
const isArrayBuffer = Array.isArray(config.data) && config.responseType === 'arraybuffer';
if (isArrayBuffer) {
finalConfig.data = Buffer.concat(config.data);
}
if (settings.proxyEnabled && proxyUrl && !isUrlMatchedInNoProxyRule(finalConfig.url, settings.noProxy)) {
const { hostname, port } = urlParse(setDefaultProtocol(proxyUrl));
@ -44,7 +48,7 @@ export const axiosRequest = async (config: AxiosRequestConfig): Promise<AxiosRes
status: response.status,
statusText: response.statusText,
headers: response.headers,
data: response.data,
data: !!response.data,
config: {
method: response.config.method,
url: response.config.url,

View File

@ -2,16 +2,11 @@
export const httpClient = {
request: async (config: any) => {
let response;
let body: Buffer | null = null;
if (config.headers && !config.headers.Accept) {
config.headers.Accept = '*/*';
}
if (Array.isArray(config.body)) {
body = Buffer.concat(config.body);
}
try {
// hosted-git-info was adding git+ to the beginning of the url which isn't supported by axios after 0.27.0
const withoutGitPlus = config.url.replace(/^git\+/, '');
@ -19,15 +14,17 @@ export const httpClient = {
url: withoutGitPlus,
method: config.method,
headers: config.headers,
data: body,
data: config.body,
responseType: 'arraybuffer',
maxRedirects: 10,
});
} catch (err) {
if (!err.response) {
console.log('[git-http-client] Error thrown', err.message);
// NOTE: config.url is unreachable
throw err;
}
console.log('[git-http-client] Ignored Error', err.response);
response = err.response;
}

View File

@ -260,12 +260,18 @@ export const gitLogLoader: LoaderFunction = async ({
workspaceMeta.gitRepositoryId
);
invariant(gitRepository, 'Git Repository not found');
try {
const log = await GitVCS.log({ depth: 35 });
return {
log,
};
} catch (e) {
console.log(e);
return {
log: [],
};
}
};
export interface GitChangesLoaderData {
@ -294,7 +300,7 @@ export const gitChangesLoader: LoaderFunction = async ({
invariant(gitRepository, 'Git Repository not found');
const branch = await GitVCS.getBranch();
try {
const { changes, statusNames } = await getGitChanges(GitVCS, workspace);
return {
@ -302,6 +308,14 @@ export const gitChangesLoader: LoaderFunction = async ({
changes,
statusNames,
};
} catch (e) {
console.log(e);
return {
branch,
changes: [],
statusNames: {},
};
}
};
// Actions
@ -413,7 +427,7 @@ export const cloneGitRepoAction: ActionFunction = async ({
});
return {
errors: ['Error cloning repository'],
errors: [originalUriError.message],
};
}
@ -435,9 +449,7 @@ export const cloneGitRepoAction: ActionFunction = async ({
},
});
return {
errors: [
'Error Cloning Repository: failed to clone with and without `.git` suffix',
],
errors: [dotGitError.message],
};
}
}
@ -1004,7 +1016,9 @@ export const pushToGitRemoteAction: ActionFunction = async ({
try {
canPush = await GitVCS.canPush(gitRepository.credentials);
} catch (err) {
return { errors: ['Error Pushing Repository'] };
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
return { errors: [`Error Pushing Repository ${errorMessage}`] };
}
// If nothing to push, display that to the user
if (!canPush) {
@ -1277,7 +1291,7 @@ export const gitStatusLoader: LoaderFunction = async ({
const workspace = await models.workspace.getById(workspaceId);
invariant(workspace, 'Workspace not found');
try {
const { changes } = await getGitChanges(GitVCS, workspace);
const localChanges = changes.filter(i => i.editable).length;
@ -1286,4 +1300,11 @@ export const gitStatusLoader: LoaderFunction = async ({
localChanges,
},
};
} catch (e) {
return {
status: {
localChanges: 0,
},
};
}
};