2017-04-26 66 views

回答

1

您可以通過/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches創建特定回購的一個分支。請查看document瞭解更多信息。

1

我將向你展示如何創建使用郵遞員和編程方式到位桶的一個分支。

使用郵差

選擇方法類型爲POST

添加網址:https://example.com/git/rest/api/1.0/projects/{projectKey}/repos/{repoName}/branches

添加的授權基本認證。

Username and password. 

選擇車身爲raw

選擇JSON(application/json)

這對身體添加爲JSON

{ 
    "name": "feature/my-feature-branch", 
    "startPoint": "refs/heads/master" 
} 

點擊發送

現在同樣的編程

String authToken = "xyzxyzabcabcabcxyzxyzabcabcabcxyzxyzabcabcabc"; 

public boolean createBranchFromIolaus(String projectKey, String repoName, String branchPrefix,String branchName, 
      String headStart) { 
     Map branches = new HashMap(); 
     JSONObject json = new JSONObject(); 
      try { 
       String branch = branchPrefix + "/" + branchName; 
       json.put("name", branch); 
       json.put("startPoint", headStart); 
       branches = restTemplate.exchange(myBitbuketUrl + "git/rest/api/1.0/projects/" 
         + projectKey + "repos" + repoName + "/branches", 
         HttpMethod.POST, postRequestEntityForBitbuket(json.toString()), Map.class).getBody(); 

       break; 
      } catch (RestClientException e) { 
       logger.error("Branches could not be created from bitbucket for " , e);    

       return false; 
      } 

      } 
     return true; 
    } 



public HttpEntity<String> postRequestEntityForBitbuket(String jsonAsString) { 

     HttpHeaders headers = new HttpHeaders(); 
     headers.add("Authorization", "Basic " + authToken); 
     headers.add("content-type", "application/json"); 

     return new HttpEntity<String>(jsonAsString, headers) ; 
    }