我们正尝试从我们的JAVA代码中搜索“ Bitbucket提交”中的特定文本。 我们需要为此使用REST Web服务
我们尝试使用APT /2.0/repositories/{username}/{repo_slug}/commits,但它会返回此存储库的所有提交
我们只需要那些提交细节,其具体文字为“ xyz”
同样,我们找到了一个代码搜索API https://api.bitbucket.org/2.0/teams/ {用户名} /搜索/代码 此处出现错误:服务器返回了HTTP响应代码:405方法不允许
String commitsUrl="https://api.bitbucket.org/2.0/teams/"+bitbucketUsername+"/search/code";
URL url = new URL(commitsUrl);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
String encoded = Base64.getEncoder().encodeToString((bitbucketUsername+":"+bitbucketPasscode).getBytes(StandardCharsets.UTF_8));
connection.setRequestProperty("Authorization", "Basic "+encoded);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
String body = "search_query="+search_query;
os = connection.getOutputStream();
os.write(body.getBytes(StandardCharsets.UTF_8));
connection.connect();
br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
显示错误:
不允许使用405方法预期:根据链接中的描述返回一些JSON https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams/%7Busername%7D/search/code
答案 0 :(得分:0)
不幸的是,我们没有找到任何在提交评论中进行搜索的选项。
现在我们正以其他方式接近
我们正在使用REST API进行所有提交存储库{用户名} {repo_slug}提交 并通过其注释字段手动比较搜索文本。
String commitsUrl=ROOT_REPOSITORY+bitbucketUsername+"/"+repoName+"/commits/";
URL url = new URL(urlString);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod(methodType);
connection.setRequestProperty("Authorization", "Bearer "+token);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.connect();
BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
StringBuilder sb = new StringBuilder();
String output;
while ((output = br.readLine()) != null) {
sb.append(output);
}
JSONObject root = new JSONObject(sb.toString());
JSONArray array = root.getJSONArray("values");
for(int i=0; i< array.length(); i++) {
JSONObject obj = (JSONObject) array.get(i);
String message = obj.getString("message");
//From this message string search your text