在提交详细信息的 Bitbucket 存储库中搜索注释



我们正尝试从我们的JAVA代码中搜索Bitbucket提交中的特定文本。我们需要为此使用 REST Web 服务。

我们尝试使用 APT/2.0/repository/{username}/{repo_slug}/commits 但它返回此存储库的所有提交

我们只需要那些具有特定文本"xyz"的提交详细信息

我们再次找到了一个代码搜索 APIhttps://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 方法不允许在

预期:根据链接中的描述返回一些 JSONhttps://developer.atlassian.com/bitbucket/api/2/reference/resource/teams/%7Busername%7D/search/code

不幸的是,

我们没有找到任何在提交评论中搜索的选项。

现在我们正在以其他方式接近:

我们正在使用 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

最新更新