Skip to content

Commit

Permalink
Capture push and pr success/failure in posthog
Browse files Browse the repository at this point in the history
- just a start since we currently are not getting much data on this
  • Loading branch information
mtsgrd authored and krlvi committed Feb 15, 2024
1 parent f7fd92f commit 167b0b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gitbutler-ui/src/lib/github/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
})
)
Expand Down
3 changes: 3 additions & 0 deletions gitbutler-ui/src/lib/vbranches/branchController.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
}
}

Expand Down
3 changes: 3 additions & 0 deletions gitbutler-ui/src/lib/vbranches/branchStoresCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 167b0b5

Please sign in to comment.