我正在尝试编写一种方法来删除JIRA中的问题。
我已经有了创建和更新问题的方法,但是我找不到任何关于如何使用Java删除问题的文档。
如何从Java应用程序中删除JIRA问题?
答案 0 :(得分:1)
答案 1 :(得分:0)
您可以尝试这样:(在此类中,我通过使用JQL获取特定用户创建的问题,并在获得响应后,我将逐个删除所有这些问题)
public class DeleteJiraIssuesHelper {
private InputStream inputStream;
private JsonReader jsonReader;
public void deleteJiraIssues() throws JiraDeleteIssueException, IOException {
String JQL="your jql query";
try {
URL url = new URL(
"your jira url/rest/api/latest/search?jql="+JQL);
String userpass = "UserName" + ":" + "Password";
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", basicAuth);
conn.setRequestProperty("Content-Type", "application/json");
if (conn.getResponseCode() != 200) {
throw new JiraConnectionException("Failed : HTTP error code : " + conn.getResponseCode());
}
conn.getResponseMessage();
inputStream = conn.getInputStream();
jsonReader = Json.createReader(inputStream);
JsonObject jsonObject = jsonReader.readObject();
int no = jsonObject.getInt("total");
JsonArray jsonArray = jsonObject.getJsonArray("issues");
List<String> issueList = new ArrayList<>();
for (int i = 0; i <= no - 1; i++) {
JsonObject jsonObject2 = jsonArray.getJsonObject(i);
String key = jsonObject2.getString("key");
issueList.add(key);
}
conn.disconnect();
HttpURLConnection httpCon = null;
for (int i = 0; i < no; i++) {
URL url2 = new URL(
"Jira url/rest/api/latest/issue/" + issueList.get(i));
httpCon = (HttpURLConnection) url2.openConnection();
httpCon.setRequestProperty("Authorization", basicAuth);
httpCon.setDoOutput(true);
httpCon.setRequestProperty("Content-Type", "application/json");
httpCon.setRequestMethod("DELETE");
httpCon.connect();
httpCon.getResponseCode();
httpCon.disconnect();
}
} catch (IOException ex) {
throw new JiraDeleteIssueException("MalformedURLException: " + ex);
} finally {
inputStream.close();
jsonReader.close();
}
}
}