mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 02:34:21 +01:00
ci: send stats to posthog
This commit is contained in:
2
.github/workflows/stats.yml
vendored
2
.github/workflows/stats.yml
vendored
@@ -30,3 +30,5 @@ jobs:
|
|||||||
git add STATS.md
|
git add STATS.md
|
||||||
git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
|
git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
|
||||||
git push
|
git push
|
||||||
|
env:
|
||||||
|
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
|
||||||
|
|||||||
23
AGENTS.md
23
AGENTS.md
@@ -1,13 +1,12 @@
|
|||||||
## Style
|
## IMPORTANT
|
||||||
|
|
||||||
- prefer single word variable/function names
|
- Try to keep things in one function unless composable or reusable
|
||||||
- avoid try catch where possible - prefer to let exceptions bubble up
|
- DO NOT do unnecessary destructuring of variables
|
||||||
- avoid else statements where possible
|
- DO NOT use `else` statements unless necessary
|
||||||
- do not make useless helper functions - inline functionality unless the
|
- DO NOT use `try`/`catch` if it can be avoided
|
||||||
function is reusable or composable
|
- AVOID `try`/`catch` where possible
|
||||||
- prefer Bun apis
|
- AVOID `else` statements
|
||||||
|
- AVOID using `any` type
|
||||||
## Workflow
|
- AVOID `let` statements
|
||||||
|
- PREFER single word variable names where possible
|
||||||
- you can regenerate the golang sdk by calling ./scripts/stainless.ts
|
- Use as many bun apis as possible like Bun.file()
|
||||||
- we use bun for everything
|
|
||||||
|
|||||||
@@ -17,19 +17,6 @@
|
|||||||
- **Error handling**: Use Result patterns, avoid throwing exceptions in tools
|
- **Error handling**: Use Result patterns, avoid throwing exceptions in tools
|
||||||
- **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`)
|
- **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`)
|
||||||
|
|
||||||
## IMPORTANT
|
|
||||||
|
|
||||||
- Try to keep things in one function unless composable or reusable
|
|
||||||
- DO NOT do unnecessary destructuring of variables
|
|
||||||
- DO NOT use `else` statements unless necessary
|
|
||||||
- DO NOT use `try`/`catch` if it can be avoided
|
|
||||||
- AVOID `try`/`catch` where possible
|
|
||||||
- AVOID `else` statements
|
|
||||||
- AVOID using `any` type
|
|
||||||
- AVOID `let` statements
|
|
||||||
- PREFER single word variable names where possible
|
|
||||||
- Use as many bun apis as possible like Bun.file()
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
- **Tools**: Implement `Tool.Info` interface with `execute()` method
|
- **Tools**: Implement `Tool.Info` interface with `execute()` method
|
||||||
|
|||||||
@@ -1,5 +1,33 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
|
async function sendToPostHog(event: string, properties: Record<string, any>) {
|
||||||
|
const key = process.env["POSTHOG_KEY"]
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
console.warn("POSTHOG_API_KEY not set, skipping PostHog event")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch("https://us.i.posthog.com/i/v0/e/", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
distinct_id: "download",
|
||||||
|
api_key: key,
|
||||||
|
event,
|
||||||
|
properties: {
|
||||||
|
...properties,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}).catch(() => null)
|
||||||
|
|
||||||
|
if (response && !response.ok) {
|
||||||
|
console.warn(`PostHog API error: ${response.status}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface Asset {
|
interface Asset {
|
||||||
name: string
|
name: string
|
||||||
download_count: number
|
download_count: number
|
||||||
@@ -173,6 +201,16 @@ console.log(`Fetched npm all-time downloads: ${npmDownloads.toLocaleString()}\n`
|
|||||||
|
|
||||||
await save(githubTotal, npmDownloads)
|
await save(githubTotal, npmDownloads)
|
||||||
|
|
||||||
|
await sendToPostHog("download", {
|
||||||
|
count: githubTotal,
|
||||||
|
source: "github",
|
||||||
|
})
|
||||||
|
|
||||||
|
await sendToPostHog("download", {
|
||||||
|
count: npmDownloads,
|
||||||
|
source: "npm",
|
||||||
|
})
|
||||||
|
|
||||||
const totalDownloads = githubTotal + npmDownloads
|
const totalDownloads = githubTotal + npmDownloads
|
||||||
|
|
||||||
console.log("=".repeat(60))
|
console.log("=".repeat(60))
|
||||||
@@ -181,23 +219,6 @@ console.log(` GitHub: ${githubTotal.toLocaleString()}`)
|
|||||||
console.log(` npm: ${npmDownloads.toLocaleString()}`)
|
console.log(` npm: ${npmDownloads.toLocaleString()}`)
|
||||||
console.log("=".repeat(60))
|
console.log("=".repeat(60))
|
||||||
|
|
||||||
console.log("\nDownloads by release:")
|
|
||||||
console.log("-".repeat(60))
|
|
||||||
|
|
||||||
stats
|
|
||||||
.sort((a, b) => b.downloads - a.downloads)
|
|
||||||
.forEach((release) => {
|
|
||||||
console.log(`${release.tag.padEnd(15)} ${release.downloads.toLocaleString().padStart(10)} downloads`)
|
|
||||||
|
|
||||||
if (release.assets.length > 1) {
|
|
||||||
release.assets
|
|
||||||
.sort((a, b) => b.downloads - a.downloads)
|
|
||||||
.forEach((asset) => {
|
|
||||||
console.log(` └─ ${asset.name.padEnd(25)} ${asset.downloads.toLocaleString().padStart(8)}`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log("-".repeat(60))
|
console.log("-".repeat(60))
|
||||||
console.log(`GitHub Total: ${githubTotal.toLocaleString()} downloads across ${releases.length} releases`)
|
console.log(`GitHub Total: ${githubTotal.toLocaleString()} downloads across ${releases.length} releases`)
|
||||||
console.log(`npm Total: ${npmDownloads.toLocaleString()} downloads`)
|
console.log(`npm Total: ${npmDownloads.toLocaleString()} downloads`)
|
||||||
|
|||||||
Reference in New Issue
Block a user