I am trying to publish the github release notes via Java REST service. The have achieved the same by writing the sh script and using curl post call.
I have written the code to do POST call using HttpUrlConnection by passing the JsonObject data.
String postUrl = "host_name/api/v3/repos/"+ userName + "/" + project_name
+ "/releases";
URL url = new URL(postUrl);
JSONObject values = new JSONObject();
JSONObject data = new JSONObject();
values.put("tag_name", "TEST_TAG1");
values.put("target_commitish", "master");
values.put("name", "1.0");
values.put("body", "TEST Description");
values.put("draft", false);
values.put("prerelease", false);
data.put("data", values);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", "token goes here");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/vnd.github.v3+json");
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data.toString());
wr.flush();
wr.close();
Expected Result : Release notes should get published on github
Error: {"message":"Invalid request.\n\n\"tag_name\" wasn't supplied.","documentation_url":"https://developer.github.com/enterprise/2.16/v3/repos/releases/#create-a-release"}