Log standalone PR creation and failures to posthog

This commit is contained in:
afik.cohen 2024-02-29 17:10:15 -08:00
parent d3f2026fff
commit 5120b6b79e
2 changed files with 22 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import {
createNewBranchFromDiffContents,
createStandalonePullRequest,
} from "../github/create-pr-from-diffcontents"
import { posthog } from "../analytics"
export async function createPr(req, res, next) {
try {
@ -88,11 +89,28 @@ export async function createPr(req, res, next) {
// Respond with the new PR details
console.log(`Created new PR #${newPrData.data.number} with branch ${newPrData.data.head.ref}`)
posthog.capture({
distinctId: userId,
event: `cfapi-create-pr-success-standalone-pr-created`,
properties: {
owner,
repo,
newPrNumber: newPrData.data.number,
newPrBranch: newPrData.data.head.ref,
},
})
res.json(newPrData.data.number)
} catch (error) {
console.log(`Error in /cfapi/create-pr: ${error}`)
console.log(`Error message: ${error.message}`)
console.log(`Error stack: ${error.stack}`)
posthog.capture({
distinctId: req.userId,
event: `cfapi-create-pr-failed-error-creating-standalone-pr`,
properties: {
error,
},
})
res.status(500).send(`Error creating pull request: ${error.message}`)
}
}

View file

@ -118,6 +118,8 @@ export async function suggestPrChanges(req, res): Promise<void> {
distinctId: userId,
event: `cfapi-suggest-pr-changes-success-dependent-pr-created`,
properties: {
owner,
repo,
newPrNumber: newPrData.data.number,
newPrBranch: newPrData.data.head.ref,
},
@ -171,6 +173,8 @@ export async function suggestPrChanges(req, res): Promise<void> {
distinctId: userId,
event: `cfapi-suggest-pr-changes-success-suggestions-made`,
properties: {
owner,
repo,
reviewNumber,
},
})