Capture push and pr success/failure in posthog

- just a start since we currently are not getting much data on this
This commit is contained in:
Mattias Granlund 2024-02-15 12:03:23 +02:00 committed by Kiril Videlov
parent f7fd92f4e0
commit 167b0b5a4d
3 changed files with 11 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import {
import { sleep } from '$lib/utils/sleep'; import { sleep } from '$lib/utils/sleep';
import * as toasts from '$lib/utils/toasts'; import * as toasts from '$lib/utils/toasts';
import lscache from 'lscache'; import lscache from 'lscache';
import posthog from 'posthog-js';
import { import {
Observable, Observable,
EMPTY, EMPTY,
@ -187,15 +188,17 @@ export class GitHubService {
draft draft
}); });
await this.reload(); await this.reload();
posthog.capture('PR Successful');
return { pr: ghResponseToInstance(rsp.data) }; return { pr: ghResponseToInstance(rsp.data) };
} catch (err: any) { } catch (err: any) {
posthog.capture('PR Failed', { error: err });
// Any error that should not be retried needs to be handled here. // Any error that should not be retried needs to be handled here.
if ( if (
err.status == 422 && err.status == 422 &&
err.message.includes('Draft pull requests are not supported') err.message.includes('Draft pull requests are not supported')
) ) {
return { err: 'Draft pull requests are not enabled in your repository' }; return { err: 'Draft pull requests are not enabled in your repository' };
else throw err; } else throw err;
} }
}) })
) )

View File

@ -1,5 +1,6 @@
import { invoke } from '$lib/backend/ipc'; import { invoke } from '$lib/backend/ipc';
import * as toasts from '$lib/utils/toasts'; import * as toasts from '$lib/utils/toasts';
import posthog from 'posthog-js';
import type { RemoteBranchService } from '$lib/stores/remoteBranches'; import type { RemoteBranchService } from '$lib/stores/remoteBranches';
import type { BaseBranchService, VirtualBranchService } from './branchStoresCache'; import type { BaseBranchService, VirtualBranchService } from './branchStoresCache';
import type { Branch, Hunk } from './types'; import type { Branch, Hunk } from './types';
@ -58,8 +59,10 @@ export class BranchController {
ownership, ownership,
runHooks: runHooks runHooks: runHooks
}); });
posthog.capture('Commit Successful');
} catch (err) { } catch (err) {
toasts.error('Failed to commit branch'); toasts.error('Failed to commit branch');
posthog.capture('Commit Failed');
} }
} }

View File

@ -2,6 +2,7 @@ import { BaseBranch, Branch } from './types';
import { invoke, listen } from '$lib/backend/ipc'; import { invoke, listen } from '$lib/backend/ipc';
import * as toasts from '$lib/utils/toasts'; import * as toasts from '$lib/utils/toasts';
import { plainToInstance } from 'class-transformer'; import { plainToInstance } from 'class-transformer';
import posthog from 'posthog-js';
import { import {
switchMap, switchMap,
Observable, Observable,
@ -108,9 +109,11 @@ export class VirtualBranchService {
branchId, branchId,
withForce withForce
}); });
posthog.capture('Push Successful');
await this.reload(); await this.reload();
return await this.getById(branchId); return await this.getById(branchId);
} catch (err: any) { } catch (err: any) {
posthog.capture('Push Failed', { error: err });
if (err.code === 'errors.git.authentication') { if (err.code === 'errors.git.authentication') {
toasts.error('Failed to authenticate. Did you setup GitButler ssh keys?'); toasts.error('Failed to authenticate. Did you setup GitButler ssh keys?');
} else { } else {