在調用GitLabApi的時候需要拿到分支的地址作爲參數。git倉庫通常是有兩種方式一種是HTTP的路徑,另一種是SSH的路徑。
怎樣將兩種不同的路徑解析出來得到我們的分支路徑。
http //gitlab.xxx.com/xxx_test_tool/autotest.git
[email protected]:xxx_test_tool/autotest.git
其實·在我們不知道用的到底是哪種方式時,用多次replace就可以拿到分支。
"xx".replace("1", "").replace("2", "")
public class test {
public static String getBranch(String Path){
String branchName = Path.replace("http //gitlab.xxx.com/","")
.replace("[email protected]:","")
.replace("git","");
return branchName;
}
public static void main(String[] args){
System.out.println(getBranch("http //gitlab.xxx.com/xxx_test_tool/autotest.git"));
System.out.println(getBranch("[email protected]:xxx_test_tool/autotest.git"));
}
}