我正在尝试使用他们的REST-API创建一个Bitbucket存储库。一切似乎都有效,除了设置"父母"项目,需要在其中创建存储库。在this链接上提供了一个cURL示例。在体内,参数" scm"被设置为" git"或" hg",两者都是字符串,参数"项目"似乎是一个包含键值对的json对象。到目前为止我尝试的所有东西都不起作用(json对象,字符串等)
问题:如何在特定项目中创建存储库?
我的代码如下所示:
RestTemplate restTemplate = new RestTemplate();
String url = "https://api.bitbucket.org/2.0/repositories/" + tName + "/" + rName;
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Basic 1234567890qwert");
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> project = new LinkedMultiValueMap();
project.add("key", "aaaaaaaa"); //the repo should be created in the project aaaaaaaa
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
postParameters.add("scm", "hg"); //hg or git, does not matter
postParameters.add("project", project); //<-- the api ignores the declared project
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(body, headers);
ResponseEntity<BitbucketRepository> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, BitbucketRepository.class);
System.out.println("createRepository: " + response);
return response;
答案 0 :(得分:0)
您可以使用bitbucket-rest库来执行此操作:
BitbucketClient client = BitbucketClient.builder()
.endPoint("http://127.0.0.1:7990")
.credentials("admin:password") // will base64 for you if not already done. Can optionally use token auth as well.
.build();
CreateRepository crepo = CreateRepository.create("my-repo", true);
Repository repo = client.api().repositoryApi().create("my-project", crepo);