File tree Expand file tree Collapse file tree 3 files changed +69
-15
lines changed
Expand file tree Collapse file tree 3 files changed +69
-15
lines changed Original file line number Diff line number Diff line change 11exports . isBranchNameValid = ( branchName ) =>
2- ( ! ! branchName . match (
3- / ^ ( c o r e | f e a t u r e | f i x | h o t f i x | a s s e t | r e w o r k | d o c u m e n t a t i o n | m o b s u c c e s s b o t | d e p e n d a b o t ) \/ ( [ a - z ] [ a - z 0 - 9 . _ - ] * ) $ /
4- ) ||
2+ isBranchNameValid ( branchName ) || isBranchNameValidLegacy ( branchName ) ;
3+
4+ function isBranchNameValidLegacy ( branchName ) {
5+ return (
6+ ( ! ! branchName . match (
7+ / ^ ( c o r e | f e a t u r e | f i x | h o t f i x | a s s e t | r e w o r k | d o c u m e n t a t i o n | m o b s u c c e s s b o t | d e p e n d a b o t ) \/ ( [ a - z ] [ a - z 0 - 9 . _ - ] * ) $ /
8+ ) ||
9+ ! ! branchName . match ( / ^ ( m o b s u c c e s s b o t ) \/ ( [ a - z 0 - 9 _ \- @ . / _ - ] * ) $ / ) ||
10+ ! ! branchName . match ( / ^ ( d e p e n d a b o t ) \/ ( [ a - z ] [ a - z A - Z 0 - 9 . / _ - ] * ) $ / ) ||
11+ ! ! branchName . match ( / ^ r e v e r t - [ 0 - 9 ] + - / ) ||
12+ ! ! branchName . match ( / ^ ( r e w o r k ) \/ ( [ A - Z ] [ a - z A - Z 0 - 9 . - ] * ) $ / ) ) &&
13+ ! branchName . match ( / - - - / ) &&
14+ ! branchName . match ( / \/ \/ / )
15+ ) ;
16+ }
17+
18+ function isBranchNameValid ( branchName ) {
19+ return (
20+ ! ! branchName . match (
21+ / ^ ( f e a t | f i x | c h o r e | d o c s | r e f a c t o r | c h a n g e | r e m o v e | t e s t | r e v e r t | p o c | m o b s u c c e s s b o t | d e p e n d a b o t ) \/ ( [ a - z ] [ a - z 0 - 9 . _ - ] * ) $ /
22+ ) ||
523 ! ! branchName . match ( / ^ ( m o b s u c c e s s b o t ) \/ ( [ a - z 0 - 9 _ \- @ . / _ - ] * ) $ / ) ||
6- ! ! branchName . match ( / ^ ( d e p e n d a b o t ) \/ ( [ a - z ] [ a - z A - Z 0 - 9 . / _ - ] * ) $ / ) ||
7- ! ! branchName . match ( / ^ r e v e r t - [ 0 - 9 ] + - / ) ||
8- ! ! branchName . match ( / ^ ( r e w o r k ) \/ ( [ A - Z ] [ a - z A - Z 0 - 9 . - ] * ) $ / ) ) &&
9- ! branchName . match ( / - - - / ) &&
10- ! branchName . match ( / \/ \/ / ) ;
24+ ! ! branchName . match ( / ^ ( d e p e n d a b o t ) \/ ( [ a - z ] [ a - z A - Z 0 - 9 . / _ - ] * ) $ / )
25+ ) ;
26+ }
Original file line number Diff line number Diff line change 11exports . isPullRequestTitleValid = ( pullRequestName ) =>
2- ! ! pullRequestName . match (
3- / ^ ( A d d | C l e a n | F i x | I m p r o v e | R e m o v e | U p d a t e | R e w o r k | I g n o r e | B u m p | S w i t c h | M i g r a t e ) .+ $ /
4- /* remember to edit the Notion when changing this value:
5- https://www.notion.so/mobsuccess/Git-Guidelines-41996ef576cb4f29b7737772b74289c5
6- */
7- ) || ! ! pullRequestName . match ( / ^ R e v e r t " .* " $ / ) ;
2+ isPullRequestTitleValid ( pullRequestName ) ||
3+ isPullRequestTitleValidLegacy ( pullRequestName ) ;
4+
5+ function isPullRequestTitleValidLegacy ( pullRequestName ) {
6+ return (
7+ ! ! pullRequestName . match (
8+ / ^ ( A d d | C l e a n | F i x | I m p r o v e | R e m o v e | U p d a t e | R e w o r k | I g n o r e | B u m p | S w i t c h | M i g r a t e ) .+ $ /
9+ /* remember to edit the Notion when changing this value:
10+ https://www.notion.so/mobsuccess/Git-Guidelines-41996ef576cb4f29b7737772b74289c5
11+ */
12+ ) || ! ! pullRequestName . match ( / ^ R e v e r t " .* " $ / )
13+ ) ;
14+ }
15+
16+ // commit convention: prefix([optional scope]): description
17+ function isPullRequestTitleValid ( pullRequestName ) {
18+ return ! ! pullRequestName . match (
19+ / ^ ( f e a t | f i x | c h o r e | d o c s | r e f a c t o r | c h a n g e | r e m o v e | t e s t | r e v e r t | p o c ) (?: \( .+ \) ) ? ! ? : .+ /
20+ ) ;
21+ }
Original file line number Diff line number Diff line change 11const { isPullRequestTitleValid } = require ( "./pullRequest" ) ;
22
3- describe ( "pul request" , ( ) => {
3+ describe ( "pull request" , ( ) => {
44 test ( "recognize pull request branch names" , ( ) => {
55 expect ( isPullRequestTitleValid ( "Add feature" ) ) . toBe ( true ) ;
6+ expect ( isPullRequestTitleValid ( "chore: remove base files" ) ) . toBe ( true ) ;
7+ expect (
8+ isPullRequestTitleValid (
9+ "fix(design-system): update color palette for accessibility compliance"
10+ )
11+ ) . toBe ( true ) ;
12+ expect (
13+ isPullRequestTitleValid (
14+ "feat!: send an email to the customer when a product is shipped"
15+ )
16+ ) . toBe ( true ) ;
17+ expect (
18+ isPullRequestTitleValid (
19+ "feat(api)!: send an email to the customer when a product is shipped"
20+ )
21+ ) . toBe ( true ) ;
622 } ) ;
723 test ( "recognize invalid branch names" , ( ) => {
824 expect ( isPullRequestTitleValid ( "add feature" ) ) . toBe ( false ) ;
25+ expect ( isPullRequestTitleValid ( "chore remove base files" ) ) . toBe ( false ) ;
26+ expect ( isPullRequestTitleValid ( "chore(): remove base files" ) ) . toBe ( false ) ;
27+ expect ( isPullRequestTitleValid ( "add: add new project" ) ) . toBe ( false ) ;
28+ expect (
29+ isPullRequestTitleValid (
30+ "feat!(api): send an email to the customer when a product is shipped"
31+ )
32+ ) . toBe ( false ) ;
933 } ) ;
1034} ) ;
You can’t perform that action at this time.
0 commit comments