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): label external product-analytics PRs instead of requesting team review (#64311)

Sam Pennington784eab7124dd
diff --git a/.github/scripts/assign-reviewers.js b/.github/scripts/assign-reviewers.js
index e81f28ab6c6e..d4274c84b637 100644
--- a/.github/scripts/assign-reviewers.js
+++ b/.github/scripts/assign-reviewers.js
@@ -194,6 +194,25 @@ async function getChangedFiles() {
return allFiles
}
+// On external PRs these teams are labelled instead of requested as reviewers, so
+// the team is surfaced without being pulled into the queue before triage. Names
+// are the part after `@PostHog/`.
+const LABEL_ONLY_TEAMS_FOR_EXTERNAL = new Set(['team-product-analytics'])
+
+// `team-product-analytics` -> `team/product-analytics`; null for non-team owners.
+function teamSlugToLabel(name) {
+ if (!name || !name.startsWith('team-')) {
+ return null
+ }
+ return name.replace(/^team-/, 'team/')
+}
+
+function partitionExternalTeams(teams) {
+ const toLabel = teams.filter((name) => LABEL_ONLY_TEAMS_FOR_EXTERNAL.has(name))
+ const toRequest = teams.filter((name) => !LABEL_ONLY_TEAMS_FOR_EXTERNAL.has(name))
+ return { toLabel, toRequest }
+}
+
// Resolve a raw CODEOWNERS owner token to a kind we can act on, or null if it's
// something we don't assign (e.g. a malformed entry).
function classifyOwner(owner) {
@@ -433,6 +452,39 @@ async function assignReviewers(teams, users) {
console.info('✅ Reviewers assigned successfully')
}
+// Best-effort: a label failure must never fail the job.
+async function applyTeamLabels(labels) {
+ const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER } = process.env
+
+ if (labels.length === 0) {
+ console.info('ℹ️ No team labels to apply')
+ return
+ }
+
+ console.info(`Applying team labels: ${labels.join(', ')}`)
+
+ try {
+ const response = await fetch(`https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels`, {
+ method: 'POST',
+ headers: {
+ Authorization: `token ${GITHUB_TOKEN}`,
+ Accept: 'application/vnd.github.v3+json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ labels }),
+ })
+
+ if (!response.ok) {
+ console.warn(`⚠️ Could not apply team labels: ${response.status} ${response.statusText}`)
+ return
+ }
+
+ console.info('✅ Team labels applied')
+ } catch (error) {
+ console.warn(`⚠️ Skipping team labels: ${error.message}`)
+ }
+}
+
async function findExistingComment(marker) {
const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER } = process.env
let url = `https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments?per_page=100`
@@ -538,12 +590,22 @@ async function main() {
const teams = requested.filter((f) => f.type === 'team').map((f) => f.name)
const users = requested.filter((f) => f.type === 'user').map((f) => f.name)
- console.info(`Teams to request: ${teams.join(', ') || 'none'}`)
+ // Forks come from external contributors (no write access for same-repo branches).
+ const isExternal = process.env.IS_FORK === 'true'
+
+ console.info(`External (fork) PR: ${isExternal}`)
+ console.info(`Teams matched: ${teams.join(', ') || 'none'}`)
console.info(`Users to request: ${users.join(', ') || 'none'}`)
console.info(`Demoted to comment: ${demoted.map((f) => f.owner).join(', ') || 'none'}`)
console.info()
- await assignReviewers(teams, users)
+ if (!isExternal) {
+ await assignReviewers(teams, users)
+ } else {
+ const { toLabel, toRequest } = partitionExternalTeams(teams)
+ await applyTeamLabels(toLabel.map(teamSlugToLabel).filter(Boolean))
+ await assignReviewers(toRequest, users)
+ }
const commentBody = buildReviewerComment(requested, demoted)
if (commentBody) {
@@ -563,6 +625,8 @@ module.exports = {
CONFIG,
isExcludedFile,
classifyOwner,
+ teamSlugToLabel,
+ partitionExternalTeams,
computeOwnerFootprints,
isSubstantive,
classifyOwners,
diff --git a/.github/scripts/assign-reviewers.test.js b/.github/scripts/assign-reviewers.test.js
index 31c6f5a786e4..6805d6916324 100644
--- a/.github/scripts/assign-reviewers.test.js
+++ b/.github/scripts/assign-reviewers.test.js
@@ -2,6 +2,8 @@ const {
CONFIG,
isExcludedFile,
classifyOwner,
+ teamSlugToLabel,
+ partitionExternalTeams,
computeOwnerFootprints,
isSubstantive,
classifyOwners,
@@ -68,6 +70,35 @@ describe('assign-reviewers', () => {
})
})
+ describe('teamSlugToLabel', () => {
+ test.each([
+ ['team-product-analytics', 'team/product-analytics'],
+ ['team-infra', 'team/infra'],
+ ['rafaeelaudibert', null],
+ ['', null],
+ ])('%s -> %s', (name, expected) => {
+ expect(teamSlugToLabel(name)).toBe(expected)
+ })
+ })
+
+ describe('partitionExternalTeams', () => {
+ test('labels product-analytics, still requests every other team', () => {
+ const { toLabel, toRequest } = partitionExternalTeams([
+ 'team-product-analytics',
+ 'team-web-analytics',
+ 'team-infra',
+ ])
+ expect(toLabel).toEqual(['team-product-analytics'])
+ expect(toRequest).toEqual(['team-web-analytics', 'team-infra'])
+ })
+
+ test('no product-analytics owner → nothing labelled, all requested', () => {
+ const { toLabel, toRequest } = partitionExternalTeams(['team-web-analytics', 'team-infra'])
+ expect(toLabel).toEqual([])
+ expect(toRequest).toEqual(['team-web-analytics', 'team-infra'])
+ })
+ })
+
describe('computeOwnerFootprints', () => {
test('ignores generated/excluded files when matching ownership', () => {
const rules = [
diff --git a/.github/workflows/auto-assign-reviewers.yml b/.github/workflows/auto-assign-reviewers.yml
index 4d2760ec3193..d3516bc3d4f7 100644
--- a/.github/workflows/auto-assign-reviewers.yml
+++ b/.github/workflows/auto-assign-reviewers.yml
@@ -56,5 +56,6 @@ jobs:
GITHUB_REPOSITORY: ${{ github.repository }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
run: |
node .github/scripts/assign-reviewers.js