private String findOpenRepository(
        final URI apiUri,
        final HttpClient httpClient,
        final HttpRequest.Builder requestBuilder) throws IOException, InterruptedException
    {
        final HttpRequest request = requestBuilder
            .copy()
            .GET()
            .uri(apiUri.resolve("/manual/search/repositories?ip=client"))
            .build();
        final HttpResponse<String> response = httpClient.send(
            request, (ResponseInfo responseInfo) -> BodySubscribers.ofString(US_ASCII));

        if (200 != response.statusCode())
        {
            throw new IllegalStateException("Failed to query repositories: " +
                "status=" + response.statusCode() + ", response=" + response.body());
        }

        final JSONArray repositories = new JSONObject(response.body()).getJSONArray("repositories");
        if (repositories.isEmpty())
        {
            throw new IllegalStateException("No open repositories found!");
        }

        String repositoryKey = null;
        final String group = groupId.get();
        for (int i = 0; i < repositories.length(); i++)
        {
            final JSONObject repo = (JSONObject)repositories.get(i);
            if ("open".equals(repo.getString("state")))
            {
                final String key = repo.getString("key");
                if (key.contains(group))
                {
                    repositoryKey = key;
                    break;
                }
            }
        }

        if (null == repositoryKey)
        {
            throw new IllegalStateException("No open repositories found!");
        }
        return repositoryKey;
    }
Publish staging repository to the Central Portal.
buildSrc/src/main/java/uk/co/real_logic/sbe/build/SonatypeCentralPortalUploadRepositoryTask.java