Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 499ae5e

Browse files
committed
chore(ci): capture PR age metrics to PostHog on merge
Adds a Closed PR workflow that fires a posthog-ci-pr-stats event when a PR is merged, mirroring the measurement already running in PostHog/posthog. Events go to project 2 via POSTHOG_API_TOKEN and carry repository/actor metadata (added by posthog-github-action v1.2.0) so PR velocity can be tracked per repo. Generated-By: PostHog Code Task-Id: 50da29c4-f95f-45b8-83a5-f0682414bedf
1 parent 7a4f19a commit 499ae5e

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/pr-closed.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Closed PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
12+
jobs:
13+
report-pr-age:
14+
name: Report age of PR
15+
runs-on: ubuntu-24.04
16+
timeout-minutes: 5
17+
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.merged == true
18+
steps:
19+
- name: Calculate PR age
20+
env:
21+
PR_CREATED_AT: ${{ github.event.pull_request.created_at }}
22+
PR_HREF: ${{ github.event.pull_request._links.commits.href }}
23+
PR_TITLE: ${{ github.event.pull_request.title }}
24+
run: |
25+
pr_age=$((($(date '+%s') - $(date -d "$PR_CREATED_AT" '+%s'))))
26+
echo "pr_age=$pr_age" >> $GITHUB_ENV
27+
28+
first_commit_message_in_pr=$(curl -s "$PR_HREF" | jq '.[0].commit.message')
29+
echo "first_commit_message_in_pr<<EOF" >> $GITHUB_ENV
30+
echo "$first_commit_message_in_pr" >> $GITHUB_ENV
31+
echo "EOF" >> $GITHUB_ENV
32+
33+
if [[ $first_commit_message_in_pr =~ Revert[[:space:]] ]]; then
34+
echo "is_revert=true" >> $GITHUB_ENV
35+
else
36+
echo "is_revert=false" >> $GITHUB_ENV
37+
fi
38+
39+
# Escape the PR title for JSON
40+
pr_title_escaped=$(echo "$PR_TITLE" | jq -R .)
41+
echo "pr_title_escaped<<EOF" >> $GITHUB_ENV
42+
echo "$pr_title_escaped" >> $GITHUB_ENV
43+
echo "EOF" >> $GITHUB_ENV
44+
- name: Capture PR age to PostHog
45+
uses: PostHog/posthog-github-action@58dea254b598fb5d469c0699c98af8288a7f7650 # v1.2.0
46+
with:
47+
posthog-token: ${{ secrets.POSTHOG_API_TOKEN }}
48+
event: 'posthog-ci-pr-stats'
49+
properties: '{"prAgeInSeconds": ${{ env.pr_age }}, "isRevert": ${{ env.is_revert }}, "prTitle": ${{ env.pr_title_escaped }}, "prNumber": "${{ github.event.pull_request.number }}"}'

0 commit comments

Comments
 (0)