Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* @brandonroberts

/apps/docs-app/ @benpsnyder
/apps/trpc-app/ @benpsnyder
/apps/trpc-app-e2e-playwright/ @benpsnyder
29 changes: 29 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,37 @@

Closes #

## Affected scope

<!-- List the primary scope from CONTRIBUTING.md and any closely related secondary scopes. -->

- Primary scope:
- Secondary scopes:

## Recommended merge strategy for maintainer [optional]

<!-- This is a recommendation for maintainers, not a requirement. -->
<!-- Prefer rebase merge when this PR intentionally preserves multiple related commits. -->

- [ ] Rebase merge
- [ ] Squash merge
- [ ] No preference

## Why preserve commits? [optional]

<!-- If you recommend rebase merge, explain the commit boundaries maintainers should preserve. -->

## What is the new behavior?

## Test plan

<!-- List the commands you ran and any manual verification you performed. -->

- [ ] `pnpm prettier:check`
- [ ] Relevant `nx build <project>`
- [ ] Relevant `nx test <project>`
- [ ] Manual verification

## Does this PR introduce a breaking change?

- [ ] Yes
Expand Down
152 changes: 152 additions & 0 deletions .github/pr-scope-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"areas": [
{
"scope": "astro-angular",
"label": "scope:astro-angular",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/astro-angular",
"prefixes": ["packages/astro-angular/"]
},
{
"scope": "content",
"label": "scope:content",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/content",
"prefixes": ["packages/content/"]
},
{
"scope": "content-plugin",
"label": "scope:content-plugin",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/content-plugin",
"prefixes": ["packages/content-plugin/"]
},
{
"scope": "create-analog",
"label": "scope:create-analog",
"kind": "package",
"color": "0e8a16",
"description": "Changes in create-analog",
"prefixes": ["packages/create-analog/"]
},
{
"scope": "nx-plugin",
"label": "scope:nx-plugin",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/nx-plugin",
"prefixes": ["packages/nx-plugin/", "apps/nx-plugin-e2e/"]
},
{
"scope": "platform",
"label": "scope:platform",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/platform",
"prefixes": ["packages/platform/"]
},
{
"scope": "router",
"label": "scope:router",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/router",
"prefixes": ["packages/router/"]
},
{
"scope": "storybook-angular",
"label": "scope:storybook-angular",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/storybook-angular",
"prefixes": ["packages/storybook-angular/"]
},
{
"scope": "trpc",
"label": "scope:trpc",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/trpc",
"prefixes": [
"packages/trpc/",
"apps/trpc-app/",
"apps/trpc-app-e2e-playwright/"
]
},
{
"scope": "vite-plugin-angular",
"label": "scope:vite-plugin-angular",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/vite-plugin-angular",
"prefixes": ["packages/vite-plugin-angular/"]
},
{
"scope": "vite-plugin-nitro",
"label": "scope:vite-plugin-nitro",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/vite-plugin-nitro",
"prefixes": ["packages/vite-plugin-nitro/"]
},
{
"scope": "vitest-angular",
"label": "scope:vitest-angular",
"kind": "package",
"color": "0e8a16",
"description": "Changes in @analogjs/vitest-angular",
"prefixes": [
"packages/vitest-angular/",
"packages/vitest-angular-tools/",
"tests/vitest-angular/"
]
},
{
"scope": "docs",
"label": "scope:docs",
"kind": "auxiliary",
"color": "fbca04",
"description": "Documentation changes",
"prefixes": ["apps/docs-app/"],
"files": [
"README.md",
"CONTRIBUTING.md",
"CHANGELOG.md",
"CODE_OF_CONDUCT.md",
"MAINTAINER.md"
]
},
{
"scope": "ci",
"label": "scope:ci",
"kind": "auxiliary",
"color": "5319e7",
"description": "GitHub workflow changes",
"prefixes": [".github/workflows/"]
},
{
"scope": "repo",
"label": "scope:repo",
"kind": "auxiliary",
"color": "6e7781",
"description": "Repository metadata and tooling",
"prefixes": [".githooks/"],
"files": [
".github/CODEOWNERS",
".github/PULL_REQUEST_TEMPLATE.md",
".github/pr-scope-map.json",
"AGENTS.md",
"commitlint.config.cjs",
"nx.json",
"package.json",
"pnpm-workspace.yaml",
"release.config.cjs",
"server.mjs",
"tsconfig.base.json"
]
}
]
}
185 changes: 185 additions & 0 deletions .github/workflows/pr-scope-governance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: pr-scope-governance

on:
pull_request_target:
types: [opened, reopened, edited, synchronize, ready_for_review]

permissions:
contents: read
issues: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
apply-scope-metadata:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}

- uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

const marker = '<!-- pr-scope-governance -->';
const config = JSON.parse(
fs.readFileSync('.github/pr-scope-map.json', 'utf8')
);
const pr = context.payload.pull_request;

const changedFiles = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
}
);

const filenames = changedFiles.map((file) => file.filename);
const matches = config.areas.filter((area) => {
const prefixes = area.prefixes ?? [];
const files = area.files ?? [];

return filenames.some((filename) => {
return (
prefixes.some((prefix) => filename.startsWith(prefix)) ||
files.includes(filename)
);
});
});

const matchedLabels = [...new Set(matches.map((area) => area.label))];
const managedLabels = config.areas.map((area) => area.label);

for (const area of config.areas) {
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: area.label,
});
} catch (error) {
if (error.status !== 404) {
throw error;
}

await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: area.label,
color: area.color,
description: area.description,
});
}
}

const issueLabels = await github.paginate(
github.rest.issues.listLabelsOnIssue,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
per_page: 100,
}
);

const currentManaged = issueLabels
.map((label) => label.name)
.filter((label) => managedLabels.includes(label));

const labelsToAdd = matchedLabels.filter(
(label) => !currentManaged.includes(label)
);
const labelsToRemove = currentManaged.filter(
(label) => !matchedLabels.includes(label)
);

if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: labelsToAdd,
});
}

for (const label of labelsToRemove) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: label,
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
}

const packageMatches = matches.filter(
(area) => area.kind === 'package'
);

const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
per_page: 100,
}
);

const existingComment = comments.find(
(comment) =>
comment.user?.type === 'Bot' &&
comment.body?.includes(marker)
);

if (packageMatches.length > 1) {
const scopes = packageMatches
.map((area) => `\`${area.scope}\``)
.join(', ');

const body = [
marker,
`This PR touches multiple package scopes: ${scopes}.`,
'',
'Please confirm the changes are closely related. If the commit boundaries are intentional, recommend `Rebase merge` in the PR template and explain which commits should be preserved.',
].join('\n');

if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body,
});
}
} else if (existingComment) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
});
}

core.info(`Changed files: ${filenames.join(', ')}`);
core.info(`Matched labels: ${matchedLabels.join(', ') || 'none'}`);
Loading
Loading