22
33import com .google .common .base .Splitter ;
44import jp .kazamori .github .actions .backlog .constant .SubCommand ;
5+ import lombok .val ;
56
67import java .util .List ;
78import java .util .regex .Pattern ;
@@ -33,16 +34,16 @@ public static List<String> extractStringWithSingleQuoteToTokens(String str) {
3334 }
3435
3536 private static String extractArgumentsWithoutCommits (String str , int commitsPosition , int quoteEnd ) {
36- var s1 = str .substring (0 , commitsPosition ).trim ();
37+ val s1 = str .substring (0 , commitsPosition ).trim ();
3738 if (str .length () == quoteEnd ) {
3839 return s1 ;
3940 }
40- var s2 = str .substring (quoteEnd + 1 , str .length ()).trim ();
41+ val s2 = str .substring (quoteEnd + 1 , str .length ()).trim ();
4142 return String .format ("%s %s" , s1 , s2 );
4243 }
4344
4445 private static int getLastIndexFromBeginning (String str , int quoteStart , String quote ) {
45- var index = str .indexOf (quote , quoteStart );
46+ var index = str .indexOf (quote , quoteStart + 1 );
4647 if (index < 0 ) {
4748 return index ;
4849 }
@@ -61,16 +62,19 @@ private static int getLastIndexFromBeginning(String str, int quoteStart, String
6162 private static final String COMMITS_OPTION = "--commits" ;
6263
6364 public static List <String > extractPushCommandArguments (String str ) {
64- var commitsPosition = str .indexOf (COMMITS_OPTION );
65+ val commitsPosition = str .indexOf (COMMITS_OPTION );
6566 if (commitsPosition < 0 ) {
6667 return extractStringWithDoubleQuoteToTokens (str );
6768 }
68- var quoteStart = str .indexOf (SINGLE_QUOTE , commitsPosition + 1 );
69- var quoteEnd = getLastIndexFromBeginning (str , quoteStart , SINGLE_QUOTE );
70- var json = str .substring (quoteStart + 1 , quoteEnd );
69+ val quoteStart = str .indexOf (SINGLE_QUOTE , commitsPosition + 1 );
70+ val quoteEnd = getLastIndexFromBeginning (str , quoteStart , SINGLE_QUOTE );
71+ if (quoteEnd < 0 ) {
72+ throw new IllegalArgumentException ("Invalid arguments" );
73+ }
74+ val json = str .substring (quoteStart + 1 , quoteEnd );
7175 // extract arguments without "--commits"
72- var others = extractArgumentsWithoutCommits (str , commitsPosition , quoteEnd );
73- var tokens = extractStringWithDoubleQuoteToTokens (others );
76+ val others = extractArgumentsWithoutCommits (str , commitsPosition , quoteEnd );
77+ val tokens = extractStringWithDoubleQuoteToTokens (others );
7478 tokens .add (COMMITS_OPTION );
7579 tokens .add (json );
7680 return tokens .stream ().filter (e -> !e .trim ().isEmpty ()).collect (Collectors .toList ());
0 commit comments