Skip to content

Commit aafa3e3

Browse files
committed
feat(parser): Add breaking change detection and styling
- [feat] Add breaking change detection logic in github-commit-labels.js:commit message parsing - [feat] Add breaking change styling (red border, bold text) in github-commit-labels.js:label creation - [feat] Add warning emoji for breaking changes in github-commit-labels.js:label text - [docs] Update README.md with breaking change syntax and examples - [release] Bump version to 1.5.1 in github-commit-labels.js
1 parent 2f297af commit aafa3e3

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A userscript that enhances GitHub commits by adding beautiful labels for convent
1515
- ⚙️ Fully customizable through a user-friendly configuration panel
1616
- 🔄 Supports multiple aliases for each commit type
1717
- 🎯 Works on commit history and single commit pages
18+
- ⚠️ Special highlighting for BREAKING CHANGES (using `type!:` or `type(scope)!:`)
1819

1920

2021
![preview1](https://raw.githubusercontent.com/nazdridoy/github-commit-labels/main/previews/preview1.png)
@@ -67,6 +68,8 @@ docs: update API documentation
6768
# With scope
6869
feat(auth): implement OAuth2 login
6970
fix(api): handle rate limiting errors
71+
feat!(auth): implement breaking change in auth
72+
refactor!(parser): rewrite parser logic (breaking change)
7073
docs(readme): add installation guide
7174
style(button): improve hover effects
7275
refactor(service): clean up user service code
@@ -77,8 +80,9 @@ test(auth): add unit tests for auth service
7780
The script will automatically detect the commit type from the first word of your commit message and add the appropriate label. Make sure to:
7881
1. Use one of the supported commit types or their aliases
7982
2. Follow the format: `type(scope): description` or `type: description`
80-
3. Keep the commit message clear and concise
81-
4. Use meaningful scopes that describe the area of the codebase being changed
83+
3. Indicate **breaking changes** by adding `!` after the type or scope: `type!:` or `type(scope)!:`.
84+
4. Keep the commit message clear and concise
85+
5. Use meaningful scopes that describe the area of the codebase being changed
8286

8387
## Installation
8488

github-commit-labels.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name GitHub Commit Labels
33
// @namespace https://github.com/nazdridoy
4-
// @version 1.5.0
4+
// @version 1.5.1
55
// @description Enhances GitHub commits with beautiful labels for conventional commit types (feat, fix, docs, etc.)
66
// @author nazdridoy
77
// @license MIT
@@ -1313,14 +1313,31 @@ SOFTWARE.
13131313
continue;
13141314
}
13151315

1316-
const match = text.match(/^(\w+)(?:\(([\w-]+)\))?:\s*(.*)/);
1317-
debugLog('Commit message match result:', match);
1316+
// Step 1: Basic parse - Capture type, middle part, and message
1317+
const basicMatch = text.match(/^(\w+)(.*?):\s*(.*)$/);
1318+
debugLog('Basic commit message match result:', basicMatch);
13181319

1319-
if (match) {
1320-
const type = match[1].toLowerCase();
1321-
const scope = match[2] || '';
1322-
const restOfMessage = match[3];
1323-
debugLog(`Extracted: type=${type}, scope=${scope}, message=${restOfMessage}`);
1320+
if (basicMatch) {
1321+
const type = basicMatch[1].toLowerCase();
1322+
const middlePart = basicMatch[2].trim();
1323+
const restOfMessage = basicMatch[3];
1324+
1325+
let scope = '';
1326+
let isBreaking = false;
1327+
let scopePart = middlePart; // Start with the full middle part
1328+
1329+
// Step 2: Check for breaking change indicator anywhere in the middle part
1330+
if (middlePart.includes('!')) {
1331+
isBreaking = true;
1332+
scopePart = middlePart.replace('!', '').trim(); // Remove ! for scope extraction
1333+
}
1334+
1335+
// Step 3: Check if the remaining part is a scope
1336+
if (scopePart.startsWith('(') && scopePart.endsWith(')')) {
1337+
scope = scopePart.slice(1, -1); // Extract scope content
1338+
}
1339+
1340+
debugLog(`Extracted: type=${type}, scope=${scope}, isBreaking=${isBreaking}, message=${restOfMessage}`);
13241341

13251342
if (USER_CONFIG.commitTypes[type]) {
13261343
debugLog(`Found matching commit type: ${type}`);
@@ -1331,6 +1348,9 @@ SOFTWARE.
13311348
label.className = 'commit-label';
13321349
label.dataset.commitType = type;
13331350
label.dataset.commitScope = scope;
1351+
if (isBreaking) {
1352+
label.dataset.isBreaking = 'true';
1353+
}
13341354

13351355
const color = COLORS[USER_CONFIG.commitTypes[type].color];
13361356

@@ -1342,6 +1362,11 @@ SOFTWARE.
13421362
display: USER_CONFIG.labelsVisible ? 'inline-flex' : 'none'
13431363
};
13441364

1365+
if (isBreaking) {
1366+
styles.border = '2px solid #d73a49';
1367+
styles.fontWeight = 'bold';
1368+
}
1369+
13451370
label.style.cssText = Object.entries(styles)
13461371
.map(([key, value]) => `${key.replace(/[A-Z]/g, m => '-' + m.toLowerCase())}: ${value}`)
13471372
.join(';');
@@ -1444,6 +1469,9 @@ SOFTWARE.
14441469

14451470
const labelText = document.createElement('span');
14461471
labelText.textContent = USER_CONFIG.commitTypes[type].label;
1472+
if (isBreaking) {
1473+
labelText.textContent += ' ⚠️';
1474+
}
14471475

14481476
label.appendChild(emoji);
14491477
label.appendChild(labelText);

0 commit comments

Comments
 (0)