@@ -2,7 +2,7 @@ name: PR Title Formatter
22
33on :
44 pull_request_target :
5- types : [opened, edited, reopened, labeled, unlabeled]
5+ types : [opened, edited, reopened, labeled, unlabeled, synchronize ]
66
77jobs :
88 format-title :
@@ -18,15 +18,12 @@ jobs:
1818 const pr_number = context.payload.pull_request.number;
1919 const rawTitle = context.payload.pull_request.title;
2020
21- // Step 1: Strip any existing CC prefix to get the bare description.
2221 const ccRegex = /^[a-z-]+(?:\([^)]+\))?!?: (.+)$/;
2322 const ccMatch = rawTitle.match(ccRegex);
2423 let description = ccMatch ? ccMatch[1] : rawTitle;
2524
26- // Step 2: Capitalize first letter.
2725 description = description.charAt(0).toUpperCase() + description.slice(1);
2826
29- // Step 3: Read PR labels and require exactly one "cc: <type>" label.
3027 const prLabels = await github.rest.issues.listLabelsOnIssue({
3128 owner,
3229 repo,
@@ -46,20 +43,21 @@ jobs:
4643 }
4744 const type = ccLabels[0].slice(4);
4845
49- // Step 4: Use scope from "package: <name>" label if exactly one is present.
5046 const packageLabels = labelNames.filter(n => n.startsWith('package: '));
5147 const scope = packageLabels.length === 1 ? packageLabels[0].slice(9) : null;
5248
53- // Step 5: Check for breaking-change label.
5449 const isBreaking = labelNames.includes('breaking-change');
5550
56- // Step 6: Build new title.
5751 let newTitle = type;
5852 if (scope) newTitle += `(${scope})`;
5953 if (isBreaking) newTitle += '!';
6054 newTitle += `: ${description}`;
6155
62- // Step 7: Enforce 72-character limit (counting the trailing " (#NNN)").
56+ if (rawTitle === newTitle) {
57+ console.log("Title is already correctly formatted. Skipping update.");
58+ return;
59+ }
60+
6361 const displayTitle = `${newTitle} (#${pr_number})`;
6462 if (displayTitle.length > 72) {
6563 core.setFailed(
6866 return;
6967 }
7068
71- // Step 8: Update the PR title.
7269 await github.rest.pulls.update({
7370 owner,
7471 repo,
0 commit comments