Merge pull request #3150 from gitbutlerapp/More-feedback-context

send more context with feedback (OS, browser, index size)
This commit is contained in:
Scott Chacon 2024-03-15 06:16:45 +01:00 committed by GitHub
commit 1cdf1264f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 52 additions and 2 deletions

View File

@ -145,6 +145,15 @@ impl App {
.map_err(|e| Error::Other(anyhow::anyhow!(e.to_string()))) .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> { pub fn git_head(&self, project_id: &ProjectId) -> Result<String, Error> {
let project = self.projects.get(project_id)?; let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?; 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)] #[tauri::command(async)]
#[instrument(skip(handle))] #[instrument(skip(handle))]
pub async fn git_head(handle: tauri::AppHandle, project_id: &str) -> Result<String, Error> { 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) 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> { pub fn blob_path<P: AsRef<Path>>(&self, path: P) -> Result<Oid> {
self.0 self.0
.blob_path(path.as_ref()) .blob_path(path.as_ref())

View File

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

View File

@ -125,6 +125,11 @@ impl Repository {
self.project = project.clone(); 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> { pub fn get_head(&self) -> Result<git::Reference, git::Error> {
let head = self.git_repository.head()?; let head = self.git_repository.head()?;
Ok(head) Ok(head)

View File

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

View File

@ -1,10 +1,12 @@
<script lang="ts"> <script lang="ts">
import TextArea from './TextArea.svelte'; import TextArea from './TextArea.svelte';
import { invoke } from '$lib/backend/ipc';
import * as zip from '$lib/backend/zip'; import * as zip from '$lib/backend/zip';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import Checkbox from '$lib/components/Checkbox.svelte'; import Checkbox from '$lib/components/Checkbox.svelte';
import Modal from '$lib/components/Modal.svelte'; import Modal from '$lib/components/Modal.svelte';
import * as toasts from '$lib/utils/toasts'; import * as toasts from '$lib/utils/toasts';
import { getVersion } from '@tauri-apps/api/app';
import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { User, getCloudApiClient } from '$lib/backend/cloud';
import { page } from '$app/stores'; import { page } from '$app/stores';
@ -15,6 +17,12 @@
modal.show(); modal.show();
} }
function gitIndexLength() {
return invoke<void>('git_index_size', {
projectId: projectId
});
}
let modal: Modal; let modal: Modal;
let messageInputValue = ''; let messageInputValue = '';
@ -41,9 +49,19 @@
: new Blob([file], { type: 'application/zip' }); : new Blob([file], { type: 'application/zip' });
} }
function onSubmit() { async function onSubmit() {
const message = messageInputValue; const message = messageInputValue;
const email = user?.email ?? emailInputValue; const email = user?.email ?? emailInputValue;
// put together context information to send with the feedback
let context = '';
const appVersion = await getVersion();
const indexLength = await gitIndexLength();
context += 'GitButler Version: ' + appVersion + '\n';
context += 'Browser: ' + navigator.userAgent + '\n';
context += 'URL: ' + window.location.href + '\n';
context += 'Length of index: ' + indexLength + '\n';
toasts.promise( toasts.promise(
Promise.all([ Promise.all([
sendLogs ? zip.logs().then((path) => readZipFile(path, 'logs.zip')) : undefined, sendLogs ? zip.logs().then((path) => readZipFile(path, 'logs.zip')) : undefined,
@ -57,6 +75,7 @@
cloud.feedback.create(user?.access_token, { cloud.feedback.create(user?.access_token, {
email, email,
message, message,
context,
logs, logs,
data, data,
repo repo
@ -83,7 +102,7 @@
<Modal bind:this={modal} on:close={onClose} title="Share debug data with GitButler team for review"> <Modal bind:this={modal} on:close={onClose} title="Share debug data with GitButler team for review">
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<p class="text-color-3"> <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. review it for you and help identify how we can help resolve the issue.
</p> </p>