Skip to content
Merged
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
41 changes: 41 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Configuration for GitHub's automatically generated release notes.
# Consumed by `gh release create --generate-notes` (see workflows/release.yml).
#
# IMPORTANT: GitHub groups merged PRs into these categories by their *labels*,
# never by their title. This project encodes change type in Conventional Commit
# title prefixes (feat/fix/docs/...), so workflows/label-pr.yml translates each
# prefix into the matching label below. Keep the two files in sync.
#
# A PR lands in the FIRST category whose label list it matches; order matters.
# Docs: https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
changelog:
exclude:
# PRs/authors here are dropped from the notes entirely.
labels:
- skip-changelog
authors:
- dependabot
- github-actions
categories:
- title: 🛠 Breaking Changes
labels:
- breaking-change
- title: 🎉 New Features
labels:
- enhancement
- title: 🐛 Bug Fixes
labels:
- bug
- title: ⚡ Performance
labels:
- performance
- title: 📚 Documentation
labels:
- documentation
- title: 🧹 Maintenance & CI
labels:
- maintenance
# Catch-all: any merged PR not matched above (e.g. an unlabeled PR).
- title: 📦 Other Changes
labels:
- "*"
79 changes: 79 additions & 0 deletions .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Label PR from title

# Translates a PR's Conventional Commit title prefix into a label, so that the
# categories in .github/release.yml (which group strictly by label) populate
# correctly in auto-generated release notes.
#
# feat: -> enhancement
# fix: -> bug
# perf: -> performance
# docs: -> documentation
# refactor/chore/ -> maintenance
# ci/build/style/test
# <any>!: or -> breaking-change (in addition to the type label)
# BREAKING CHANGE
#
# Runs on `pull_request_target` so it also has permission to label PRs opened
# from forks (the plain `pull_request` token is read-only for forks). We never
# check out or run the PR's code here, so the elevated token is not exposed to
# untrusted input — only the title string is read.
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]

permissions:
pull-requests: write # required to add labels
contents: read

# One labeling run per PR; a newer edit supersedes an in-flight run.
concurrency:
group: label-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Apply labels from title prefix
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const title = pr.title || "";

// Conventional Commit header: type(scope)!: description
const match = title.match(/^(\w+)(?:\([^)]*\))?(!)?:/);
const typeToLabel = {
feat: "enhancement",
fix: "bug",
perf: "performance",
docs: "documentation",
refactor: "maintenance",
chore: "maintenance",
ci: "maintenance",
build: "maintenance",
style: "maintenance",
test: "maintenance",
};

const labels = new Set();
if (match) {
const mapped = typeToLabel[match[1].toLowerCase()];
if (mapped) labels.add(mapped);
if (match[2] === "!") labels.add("breaking-change");
}
// `BREAKING CHANGE:` footer is also a Conventional Commit breaking marker.
if (/breaking change/i.test(pr.body || "")) labels.add("breaking-change");

if (labels.size === 0) {
core.info(`No type prefix recognized in title: "${title}"`);
return;
}

await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [...labels],
});
core.info(`Applied labels: ${[...labels].join(", ")}`);