@@ -2,28 +2,78 @@ import { Commit } from '../../entrypoint.api';
22import { ValidConfigOptions } from '../../options/options' ;
33import { getBackportBranchName } from './getBackportBranchName' ;
44
5- const commit = { sourcePullRequest : { number : 1234 } } as Commit ;
6-
75describe ( 'getBackportBranchName' , ( ) => {
8- it ( 'returns the default name' , ( ) => {
9- const name = getBackportBranchName ( {
10- options : {
11- backportBranchName : undefined ,
12- } as ValidConfigOptions ,
13- targetBranch : '7.x' ,
14- commits : [ commit ] ,
6+ describe ( 'when options.backportBranchName is not set' , ( ) => {
7+ it ( 'returns the default name with PR number' , ( ) => {
8+ const commits = [ { sourcePullRequest : { number : 1234 } } ] as Commit [ ] ;
9+ const name = getBackportBranchName ( {
10+ options : { backportBranchName : undefined } as ValidConfigOptions ,
11+ targetBranch : '7.x' ,
12+ commits,
13+ } ) ;
14+ expect ( name ) . toBe ( 'backport/7.x/pr-1234' ) ;
15+ } ) ;
16+
17+ it ( 'returns the default name with commit sha' , ( ) => {
18+ const commits = [ { sourceCommit : { sha : 'abcde' } } ] as Commit [ ] ;
19+ const name = getBackportBranchName ( {
20+ options : { backportBranchName : undefined } as ValidConfigOptions ,
21+ targetBranch : '7.x' ,
22+ commits,
23+ } ) ;
24+ expect ( name ) . toBe ( 'backport/7.x/commit-abcde' ) ;
1525 } ) ;
16- expect ( name ) . toBe ( 'backport/7.x/pr-1234' ) ;
1726 } ) ;
1827
19- it ( 'returns a custom name' , ( ) => {
20- const name = getBackportBranchName ( {
21- options : {
22- backportBranchName : 'bp/pull-{{sourcePullRequest.number}}' ,
23- } as ValidConfigOptions ,
24- targetBranch : '7.x' ,
25- commits : [ commit ] ,
28+ describe ( 'template variables are supported when using options.backportBranchName' , ( ) => {
29+ it ( '{{targetBranch}}' , ( ) => {
30+ const commits = [ { sourcePullRequest : { number : 1234 } } ] as Commit [ ] ;
31+ const name = getBackportBranchName ( {
32+ options : {
33+ backportBranchName : 'bp/target-{{targetBranch}}' ,
34+ } as ValidConfigOptions ,
35+ targetBranch : '7.x' ,
36+ commits,
37+ } ) ;
38+ expect ( name ) . toBe ( 'bp/target-7.x' ) ;
39+ } ) ;
40+
41+ it ( '{{refValues}}' , ( ) => {
42+ const commits = [ { sourcePullRequest : { number : 1234 } } ] as Commit [ ] ;
43+ const name = getBackportBranchName ( {
44+ options : {
45+ backportBranchName : 'bp/ref-{{refValues}}' ,
46+ } as ValidConfigOptions ,
47+ targetBranch : '7.x' ,
48+ commits,
49+ } ) ;
50+ expect ( name ) . toBe ( 'bp/ref-pr-1234' ) ;
51+ } ) ;
52+
53+ it ( '{{sourcePullRequest.number}}' , ( ) => {
54+ const commits = [ { sourcePullRequest : { number : 1234 } } ] as Commit [ ] ;
55+ const name = getBackportBranchName ( {
56+ options : {
57+ backportBranchName : 'bp/pr-{{sourcePullRequest.number}}' ,
58+ } as ValidConfigOptions ,
59+ targetBranch : '7.x' ,
60+ commits,
61+ } ) ;
62+ expect ( name ) . toBe ( 'bp/pr-1234' ) ;
63+ } ) ;
64+
65+ it ( '{{sourcePullRequest.title}}' , ( ) => {
66+ const commits = [
67+ { sourcePullRequest : { title : 'My PR title' , number : 1234 } } ,
68+ ] as Commit [ ] ;
69+ const name = getBackportBranchName ( {
70+ options : {
71+ backportBranchName : 'bp/pr-{{sourcePullRequest.title}}' ,
72+ } as ValidConfigOptions ,
73+ targetBranch : '7.x' ,
74+ commits,
75+ } ) ;
76+ expect ( name ) . toBe ( 'bp/pr-My PR title' ) ;
2677 } ) ;
27- expect ( name ) . toBe ( 'bp/pull-1234' ) ;
2878 } ) ;
2979} ) ;
0 commit comments