send more context with feedback (OS, browser, index size)

This commit is contained in:
Scott Chacon 2024-03-14 16:35:00 +01:00
parent ef9239b712
commit cec15bcdd0
7 changed files with 46 additions and 2 deletions

View File

@ -145,6 +145,15 @@ impl App {
.map_err(|e| Error::Other(anyhow::anyhow!(e.to_string())))
}
pub fn git_index_size(&self, project_id: &ProjectId) -> Result<usize, Error> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;
let size = project_repository
.git_index_size()
.context("failed to get index size")?;
Ok(size)
}
pub fn git_head(&self, project_id: &ProjectId) -> Result<String, Error> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;

View File

@ -103,6 +103,17 @@ pub async fn git_test_fetch(
})
}
#[tauri::command(async)]
#[instrument(skip(handle))]
pub async fn git_index_size(handle: tauri::AppHandle, project_id: &str) -> Result<usize, Error> {
let app = handle.state::<app::App>();
let project_id = project_id.parse().map_err(|_| Error::UserError {
code: Code::Validation,
message: "Malformed project id".to_string(),
})?;
Ok(app.git_index_size(&project_id).expect("git index size"))
}
#[tauri::command(async)]
#[instrument(skip(handle))]
pub async fn git_head(handle: tauri::AppHandle, project_id: &str) -> Result<String, Error> {

View File

@ -224,6 +224,10 @@ impl Repository {
self.0.index().map(Into::into).map_err(Into::into)
}
pub fn index_size(&self) -> Result<usize> {
Ok(self.0.index()?.len())
}
pub fn blob_path<P: AsRef<Path>>(&self, path: P) -> Result<Oid> {
self.0
.blob_path(path.as_ref())

View File

@ -240,6 +240,7 @@ fn main() {
commands::project_flush_and_push,
commands::git_test_push,
commands::git_test_fetch,
commands::git_index_size,
zip::commands::get_logs_archive_path,
zip::commands::get_project_archive_path,
zip::commands::get_project_data_archive_path,

View File

@ -125,6 +125,11 @@ impl Repository {
self.project = project.clone();
}
pub fn git_index_size(&self) -> Result<usize, git::Error> {
let head = self.git_repository.index_size()?;
Ok(head)
}
pub fn get_head(&self) -> Result<git::Reference, git::Error> {
let head = self.git_repository.head()?;
Ok(head)

View File

@ -155,6 +155,7 @@ export function getCloudApiClient(
const formData = new FormData();
formData.append('message', params.message);
if (params.email) formData.append('email', params.email);
if (params.context) formData.append('context', params.context);
if (params.logs) formData.append('logs', params.logs);
if (params.repo) formData.append('repo', params.repo);
if (params.data) formData.append('data', params.data);

View File

@ -7,6 +7,7 @@
import * as toasts from '$lib/utils/toasts';
import type { User, getCloudApiClient } from '$lib/backend/cloud';
import { page } from '$app/stores';
import { invoke } from '$lib/backend/ipc';
export let user: User | undefined;
export let cloud: ReturnType<typeof getCloudApiClient>;
@ -15,6 +16,12 @@
modal.show();
}
function gitIndexLength() {
return invoke<void>('git_index_size', {
projectId: projectId
});
}
let modal: Modal;
let messageInputValue = '';
@ -41,9 +48,14 @@
: new Blob([file], { type: 'application/zip' });
}
function onSubmit() {
async function onSubmit() {
const message = messageInputValue;
const email = user?.email ?? emailInputValue;
let context = 'Browser: ' + navigator.userAgent + '\n';
context += 'URL: ' + window.location.href + '\n';
const indexLength = await gitIndexLength();
context += 'Length of index: ' + indexLength + '\n';
toasts.promise(
Promise.all([
sendLogs ? zip.logs().then((path) => readZipFile(path, 'logs.zip')) : undefined,
@ -57,6 +69,7 @@
cloud.feedback.create(user?.access_token, {
email,
message,
context,
logs,
data,
repo
@ -83,7 +96,7 @@
<Modal bind:this={modal} on:close={onClose} title="Share debug data with GitButler team for review">
<div class="flex flex-col gap-4">
<p class="text-color-3">
If you are having trouble, please share your project and logs with the Gitbutler team. We will
If you are having trouble, please share your project and logs with the GitButler team. We will
review it for you and help identify how we can help resolve the issue.
</p>