diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml new file mode 100644 index 0000000000..c68573aec2 --- /dev/null +++ b/.github/workflows/pr-closed.yml @@ -0,0 +1,49 @@ +name: Closed PR + +on: + pull_request: + types: + - closed + +permissions: + contents: read + pull-requests: read + +jobs: + report-pr-age: + name: Report age of PR + runs-on: ubuntu-24.04 + timeout-minutes: 5 + if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.merged == true + steps: + - name: Calculate PR age + env: + PR_CREATED_AT: ${{ github.event.pull_request.created_at }} + PR_HREF: ${{ github.event.pull_request._links.commits.href }} + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + pr_age=$((($(date '+%s') - $(date -d "$PR_CREATED_AT" '+%s')))) + echo "pr_age=$pr_age" >> $GITHUB_ENV + + first_commit_message_in_pr=$(curl -s "$PR_HREF" | jq '.[0].commit.message') + echo "first_commit_message_in_pr<> $GITHUB_ENV + echo "$first_commit_message_in_pr" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + if [[ $first_commit_message_in_pr =~ Revert[[:space:]] ]]; then + echo "is_revert=true" >> $GITHUB_ENV + else + echo "is_revert=false" >> $GITHUB_ENV + fi + + # Escape the PR title for JSON + pr_title_escaped=$(echo "$PR_TITLE" | jq -R .) + echo "pr_title_escaped<> $GITHUB_ENV + echo "$pr_title_escaped" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + - name: Capture PR age to PostHog + uses: PostHog/posthog-github-action@58dea254b598fb5d469c0699c98af8288a7f7650 # v1.2.0 + with: + posthog-token: ${{ secrets.POSTHOG_API_TOKEN }} + event: 'posthog-ci-pr-stats' + properties: '{"prAgeInSeconds": ${{ env.pr_age }}, "isRevert": ${{ env.is_revert }}, "prTitle": ${{ env.pr_title_escaped }}, "prNumber": "${{ github.event.pull_request.number }}"}'