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