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 * as toasts from '$lib/utils/toasts';
import lscache from 'lscache';
import posthog from 'posthog-js';
import {
Observable,
EMPTY,
@ -187,15 +188,17 @@ export class GitHubService {
draft
});
await this.reload();
posthog.capture('PR Successful');
return { pr: ghResponseToInstance(rsp.data) };
} catch (err: any) {
posthog.capture('PR Failed', { error: err });
// Any error that should not be retried needs to be handled here.
if (
err.status == 422 &&
err.message.includes('Draft pull requests are not supported')
)
) {
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 * as toasts from '$lib/utils/toasts';
import posthog from 'posthog-js';
import type { RemoteBranchService } from '$lib/stores/remoteBranches';
import type { BaseBranchService, VirtualBranchService } from './branchStoresCache';
import type { Branch, Hunk } from './types';
@ -58,8 +59,10 @@ export class BranchController {
ownership,
runHooks: runHooks
});
posthog.capture('Commit Successful');
} catch (err) {
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 * as toasts from '$lib/utils/toasts';
import { plainToInstance } from 'class-transformer';
import posthog from 'posthog-js';
import {
switchMap,
Observable,
@ -108,9 +109,11 @@ export class VirtualBranchService {
branchId,
withForce
});
posthog.capture('Push Successful');
await this.reload();
return await this.getById(branchId);
} catch (err: any) {
posthog.capture('Push Failed', { error: err });
if (err.code === 'errors.git.authentication') {
toasts.error('Failed to authenticate. Did you setup GitButler ssh keys?');
} else {