Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): fix fork contributor thanks token and add replay (#125063)

Raúl Negrón-Oteroecccdaff07ff
diff --git a/.agents/skills/recreating-fork-prs/SKILL.md b/.agents/skills/recreating-fork-prs/SKILL.md
index 10614ac1c200..3a79ec081bf5 100644
--- a/.agents/skills/recreating-fork-prs/SKILL.md
+++ b/.agents/skills/recreating-fork-prs/SKILL.md
@@ -111,3 +111,4 @@ The merge queue squash-merges, and GitHub adds a `Co-authored-by` line for every
When the new PR merges, the `Thank fork contributor` job in `.github/workflows/pr-closed.yml` reads the marker.
It comments on the fork PR with a link to the merged PR, then closes the fork PR.
Leave the fork PR open until then.
+If that job fails, a rerun reuses the failed run's workflow file, so fix the cause and then run `gh workflow run pr-closed.yml -f merged_pr_number=<new PR number>`.
diff --git a/.github/scripts/thank-fork-contributor.js b/.github/scripts/thank-fork-contributor.js
index 466481351107..6442a58eeea6 100644
--- a/.github/scripts/thank-fork-contributor.js
+++ b/.github/scripts/thank-fork-contributor.js
@@ -1,4 +1,5 @@
-// Runs through actions/github-script when a pull request merges. If its body
+// Runs through actions/github-script when a pull request merges, or from a
+// manual dispatch that names a merged pull request to replay. If its body
// carries the hidden marker that the recreating-fork-prs skill writes
// ("<!-- fork-pr: <n> @<login> -->"), it tells the contributor on fork PR #<n>
// where their change landed, then closes that PR.
@@ -43,6 +44,7 @@ function buildComment({ login, mergedPrNumber, credited }) {
const MERGED_PR_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
+ merged
body
mergeCommit { authors(first: 50) { nodes { user { login } } } }
}
@@ -73,11 +75,16 @@ async function fetchPullRequest(github, query, variables) {
}
}
-module.exports = async ({ github, context, core }) => {
+module.exports = async ({ github, context, core, mergedPrNumber }) => {
const { owner, repo } = context.repo
- const mergedPrNumber = context.payload.pull_request.number
const mergedPr = await fetchPullRequest(github, MERGED_PR_QUERY, { owner, name: repo, number: mergedPrNumber })
+ // A manual dispatch can name any number, and thanking for an unmerged PR
+ // would close the fork PR before its change lands.
+ if (!mergedPr?.merged) {
+ core.warning(`Skipping #${mergedPrNumber}: not a merged pull request`)
+ return
+ }
const contribution = parseContribution(mergedPr.body)
if (!contribution) {
core.info(`#${mergedPrNumber} has no fork-pr marker`)
diff --git a/.github/scripts/thank-fork-contributor.test.js b/.github/scripts/thank-fork-contributor.test.js
index aadd0c7b2290..adf75f175980 100644
--- a/.github/scripts/thank-fork-contributor.test.js
+++ b/.github/scripts/thank-fork-contributor.test.js
@@ -15,11 +15,12 @@ const forkPr = (overrides = {}) => ({
})
const MERGED_PR = {
+ merged: true,
body: '<!-- fork-pr: 1001 @Jane-Doe -->',
mergeCommit: { authors: { nodes: [{ user: { login: 'Jane-Doe' } }] } },
}
-function fakeGithub(forkPrResult) {
+function fakeGithub(forkPrResult, mergedPr) {
const calls = []
return {
calls,
@@ -30,7 +31,7 @@ function fakeGithub(forkPrResult) {
}
return { repository: { pullRequest: forkPrResult } }
}
- return { repository: { pullRequest: MERGED_PR } }
+ return { repository: { pullRequest: mergedPr } }
},
rest: {
issues: { createComment: async (args) => calls.push(['comment', args.issue_number]) },
@@ -39,7 +40,7 @@ function fakeGithub(forkPrResult) {
}
}
-const context = { repo: { owner: 'PostHog', repo: 'posthog' }, payload: { pull_request: { number: 1002 } } }
+const context = { repo: { owner: 'PostHog', repo: 'posthog' } }
const core = { info: () => {}, warning: () => {} }
test.describe('thank-fork-contributor', () => {
@@ -75,7 +76,7 @@ test.describe('thank-fork-contributor', () => {
})
const notFound = Object.assign(new Error('not found'), { errors: [{ type: 'NOT_FOUND' }] })
- for (const [name, forkPrResult, expectedCalls] of [
+ for (const [name, forkPrResult, expectedCalls, mergedPr = MERGED_PR] of [
[
'open fork PR gets a comment and is closed',
forkPr(),
@@ -91,10 +92,10 @@ test.describe('thank-fork-contributor', () => {
],
['a closed fork PR only gets the comment', forkPr({ state: 'CLOSED' }), [['comment', 1001]]],
['a PR number that does not exist is skipped', notFound, []],
- ]) {
+ ['a dispatch naming an unmerged PR is skipped', forkPr(), [], { ...MERGED_PR, merged: false }], ]) {
test(name, async () => {
- const github = fakeGithub(forkPrResult)
- await thankForkContributor({ github, context, core })
+ const github = fakeGithub(forkPrResult, mergedPr)
+ await thankForkContributor({ github, context, core, mergedPrNumber: 1002 })
assert.deepEqual(github.calls, expectedCalls)
})
}
diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml
index 90fd0316bc56..3b839f0c3829 100644
--- a/.github/workflows/pr-closed.yml
+++ b/.github/workflows/pr-closed.yml
@@ -4,6 +4,12 @@ on:
pull_request:
types:
- closed
+ workflow_dispatch:
+ inputs:
+ merged_pr_number:
+ description: Merged pull request to rerun the fork contributor thanks for
+ required: true
+ type: number
permissions:
contents: read
@@ -130,9 +136,10 @@ jobs:
runs-on: ubuntu-24.04
timeout-minutes: 5
if: >
+ github.event_name == 'workflow_dispatch' || (
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.merged == true &&
- contains(github.event.pull_request.body, '<!-- fork-pr: ')
+ contains(github.event.pull_request.body, '<!-- fork-pr: '))
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
@@ -145,17 +152,20 @@ jobs:
with:
client-id: ${{ vars.GH_APP_POSTHOG_SCHEDULED_ACTIONS_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_SCHEDULED_ACTIONS_PRIVATE_KEY }}
- permission-issues: write
+ permission-contents: read
permission-pull-requests: write
- name: Thank the contributor on the fork PR
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
+ env:
+ MERGED_PR_NUMBER: ${{ inputs.merged_pr_number || github.event.pull_request.number }}
with:
github-token: ${{ steps.app-token.outputs.token }}
retries: 3
script: |
const thankForkContributor = require('./.github/scripts/thank-fork-contributor.js')
- await thankForkContributor({ github, context, core })
+ const mergedPrNumber = Number(process.env.MERGED_PR_NUMBER)
+ await thankForkContributor({ github, context, core, mergedPrNumber })
report-pr-age:
name: Report age of PR