0

using below code I get this JSON data I want to create a GitHub branch through API in java. JSON data:-

[
    {
        "name": "Dem142",
        "commit": {
            "sha": "1ed824dac2a098a67cfbf651e5ef3bb5cc7fc211",
            "url": "https://github.abc.com/api/v3/repos/code/management/commits/1ed824dac2a098a67cfbf651e5ef3bb5cc7fc211"
        },
        "protected": false
    },
    {
        "name": "Dem289",
        "commit": {
            "sha": "8640bac319923fe538082f2b86588ff276c347c1",
            "url": "https://github.training.cerner.com/api/v3/repos/DevCenter/Patient-Alias-management/commits/8640bac319923fe538082f2b86588ff276c347c1"
        },
        "protected": false
    },
    {
        "name": "master",
        "commit": {
            "sha": "19af457faf433e71c022f1f6bba0562d076b5c15",
            "url": "https://github.abc.com/api/v3/repos/code/management/commits/19af457faf433e71c022f1f6bba0562d076b5c15"
        },
        "protected": false
    },
    {
        "name": "stable",
        "commit": {
            "sha": "19af457faf433e71c022f1f6bba0562d076b5c15",
            "url": "https://github.abc.com/api/v3/repos/code/management/commits/19af457faf433e71c022f1f6bba0562d076b5c15"
        },
        "protected": false
    }
]

String urlLink="https://github.abc.com/api/v3/repos/code/management/branches";
Url obj = new URL(urlLink);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null)
{
    response.append(inputLine);
}
in.close();
Michael
  • 41,989
  • 11
  • 82
  • 128
  • Nothing to do with your question but you should use try-finally or try-with-resources blocks because if your code throws exceptions then you'll leave those streams open – Michael Jun 10 '21 at 10:33
  • could you please check if https://stackoverflow.com/questions/9506181/github-api-create-branch if this can help you? – Vaibhav Miniyar Jun 11 '21 at 07:23
  • could you please help me to get "sha" value from the above json data to create branch. – Shikhar Kushwah Jun 11 '21 at 07:30

0 Answers0