: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): auto-label docs and Inkeep PRs (#72547)
Sarah Sanders7b0414681563
diff --git a/.github/scripts/label-pr-from-title.js b/.github/scripts/label-pr-from-title.jsindex 7b48ea590510..6306ca03af9a 100644--- a/.github/scripts/label-pr-from-title.js+++ b/.github/scripts/label-pr-from-title.js@@ -1,8 +1,9 @@#!/usr/bin/env node// Adds team/feature labels to a PR based on its conventional-commit scope-// (`type(scope): summary`). Additive only — it never removes labels, so manual-// labels and the ownership-based labeler (assign-reviewers.js) are left intact.+// (`type(scope): summary`), plus the `docs` label for docs-typed or Inkeep-bot+// PRs. Additive only — it never removes labels, so manual labels and the+// ownership-based labeler (assign-reviewers.js) are left intact.//// The scope -> labels mapping lives in .github/auto-assign-labels.json, OUTSIDE// this script, so the owning team can adjust mappings without changing (and@@ -40,6 +41,25 @@ function parseScopes(title) {.filter(Boolean)}+// The Inkeep docs bot's login. Its PRs get the `docs` label so the website+// team's project board can exclude them — GitHub project views can't filter by+// author.+const INKEEP_BOT_LOGIN = 'inkeep[bot]'++// Pull the conventional-commit type out of a subject: `type(scope): …` / `type: …`.+// Requires the trailing colon so stray words don't match. Case-insensitive.+function parseType(title) {+ const match = /^\s*(\w+)(\([^)]*\))?!?:/.exec(title || '')+ return match ? match[1].toLowerCase() : null+}++// The `docs` label applies to docs-typed PRs (`docs:` / `docs(scope):`) and to+// anything the Inkeep docs bot opens. Unlike the scope rules, this keys off the+// commit type and the author rather than the scope.+function docsLabelApplies(title, author) {+ return parseType(title) === 'docs' || author === INKEEP_BOT_LOGIN+}+// Map a title's scopes to the de-duplicated labels they should carry.function labelsForTitle(title, rules) {const scopes = new Set(parseScopes(title))@@ -99,7 +119,7 @@ async function addLabels(labels) {}async function main() {- const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER, PR_TITLE } = process.env+ const { GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER, PR_TITLE, PR_AUTHOR } = process.envconst missing = Object.entries({ GITHUB_TOKEN, GITHUB_REPOSITORY, PR_NUMBER }).filter(([, value]) => !value).map(([name]) => name)@@ -112,6 +132,9 @@ async function main() {try {const rules = loadRules()const labels = labelsForTitle(PR_TITLE, rules)+ if (docsLabelApplies(PR_TITLE, PR_AUTHOR) && !labels.includes('docs')) {+ labels.push('docs')+ }console.info(`PR title: ${PR_TITLE || '(empty)'}`)await addLabels(labels)} catch (error) {@@ -124,4 +147,4 @@ if (require.main === module) {main()}-module.exports = { parseScopes, labelsForTitle, loadRules }+module.exports = { parseScopes, parseType, docsLabelApplies, labelsForTitle, loadRules }diff --git a/.github/scripts/label-pr-from-title.test.js b/.github/scripts/label-pr-from-title.test.jsindex 78454b87c5bd..3cefff7a71c2 100644--- a/.github/scripts/label-pr-from-title.test.js+++ b/.github/scripts/label-pr-from-title.test.js@@ -7,7 +7,7 @@const test = require('node:test')const assert = require('node:assert/strict')-const { parseScopes, labelsForTitle, loadRules } = require('./label-pr-from-title')+const { parseScopes, parseType, docsLabelApplies, labelsForTitle, loadRules } = require('./label-pr-from-title')// Mirrors the rule shape in .github/auto-assign-labels.json so the logic is// exercised against the real structure without reading the file.@@ -75,6 +75,39 @@ test('labelsForTitle', async (t) => {}})+const PARSE_TYPE_CASES = [+ { title: 'docs: add guide', expected: 'docs', description: 'type with no scope' },+ { title: 'docs(internal): x', expected: 'docs', description: 'type with scope' },+ { title: 'feat(flags): x', expected: 'feat', description: 'non-docs type' },+ { title: 'chore!: drop thing', expected: 'chore', description: 'breaking-change bang' },+ { title: 'update the docs please', expected: null, description: 'prose without a CC type -> null' },+ { title: '', expected: null, description: 'empty title -> null' },+]++test('parseType', async (t) => {+ for (const { title, expected, description } of PARSE_TYPE_CASES) {+ await t.test(description, () => {+ assert.equal(parseType(title), expected)+ })+ }+})++const DOCS_LABEL_CASES = [+ { title: 'docs: x', author: 'someuser', expected: true, description: 'docs type applies' },+ { title: 'docs(cdp): x', author: 'someuser', expected: true, description: 'docs type with scope applies' },+ { title: 'feat(flags): x', author: 'inkeep[bot]', expected: true, description: 'inkeep author applies on any title' },+ { title: 'feat(flags): x', author: 'someuser', expected: false, description: 'neither type nor author -> no docs label' },+ { title: 'chore: tidy up docs', author: 'someuser', expected: false, description: 'docs only in prose does not apply' },+]++test('docsLabelApplies', async (t) => {+ for (const { title, author, expected, description } of DOCS_LABEL_CASES) {+ await t.test(description, () => {+ assert.equal(docsLabelApplies(title, author), expected)+ })+ }+})+// Catches a malformed or empty .github/auto-assign-labels.json in this PR's// ci-scripts run, rather than letting it silently disable labeling on master.test('the shipped config loads into well-formed rules', () => {diff --git a/.github/workflows/auto-assign-labels.yml b/.github/workflows/auto-assign-labels.ymlindex e8f6fb66b4b7..98ca9c308919 100644--- a/.github/workflows/auto-assign-labels.yml+++ b/.github/workflows/auto-assign-labels.yml@@ -52,5 +52,6 @@ jobs:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}PR_NUMBER: ${{ github.event.pull_request.number }}PR_TITLE: ${{ github.event.pull_request.title }}+ PR_AUTHOR: ${{ github.event.pull_request.user.login }}GITHUB_REPOSITORY: ${{ github.repository }}run: node .github/scripts/label-pr-from-title.js