Skip to content

feat(autojac): Make jac_to_grad return optional weights #20

feat(autojac): Make jac_to_grad return optional weights

feat(autojac): Make jac_to_grad return optional weights #20

Workflow file for this run

name: PR Title Formatter
on:
pull_request_target:
types: [opened, edited, reopened, labeled, unlabeled]
jobs:
format-title:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format PR Title from Labels
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pr_number = context.payload.pull_request.number;
const rawTitle = context.payload.pull_request.title;
// Step 1: Strip any existing CC prefix to get the bare description.
const ccRegex = /^[a-z-]+(?:\([^)]+\))?!?: (.+)$/;
const ccMatch = rawTitle.match(ccRegex);
let description = ccMatch ? ccMatch[1] : rawTitle;
// Step 2: Capitalize first letter.
description = description.charAt(0).toUpperCase() + description.slice(1);
// Step 3: Read PR labels and require exactly one "cc: <type>" label.
const prLabels = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: pr_number,
per_page: 100,
});
const labelNames = prLabels.data.map(l => l.name);
const ccLabels = labelNames.filter(n => n.startsWith('cc: '));
if (ccLabels.length === 0) {
core.setFailed('No "cc: <type>" label found on this PR. Please add exactly one.');
return;
}
if (ccLabels.length > 1) {
core.setFailed(`Multiple "cc: <type>" labels found: ${ccLabels.join(', ')}. Please keep exactly one.`);
return;
}
const type = ccLabels[0].slice(4);
// Step 4: Use scope from "package: <name>" label if exactly one is present.
const packageLabels = labelNames.filter(n => n.startsWith('package: '));
const scope = packageLabels.length === 1 ? packageLabels[0].slice(9) : null;
// Step 5: Check for breaking-change label.
const isBreaking = labelNames.includes('breaking-change');
// Step 6: Build new title.
let newTitle = type;
if (scope) newTitle += `(${scope})`;
if (isBreaking) newTitle += '!';
newTitle += `: ${description}`;
// Step 7: Enforce 72-character limit (counting the trailing " (#NNN)").
const displayTitle = `${newTitle} (#${pr_number})`;
if (displayTitle.length > 72) {
core.setFailed(
`Formatted title is too long by ${displayTitle.length - 72} characters: "${displayTitle}"`
);
return;
}
// Step 8: Update the PR title.
await github.rest.pulls.update({
owner,
repo,
pull_number: pr_number,
title: newTitle,
});
console.log(`PR title updated to: "${newTitle}"`);