Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instead of saving 1K issues per file, save issues with ID within a thousand per file #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/com/SZZ/jiraAnalyser/entities/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void setBug() {
}

try{
Resolution.valueOf(s[2].toUpperCase().replace(" ", "").replace("'", ""));
resolution = Resolution.valueOf(s[2].toUpperCase().replace(" ", "").replace("'", ""));
}
catch(Exception e){
resolution = Resolution.NONE;
Expand Down
28 changes: 18 additions & 10 deletions src/com/SZZ/jiraAnalyser/git/JiraRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private Document parseXML(InputStream stream) {
return doc;
}

private int getIssueIdFromKey(String key) {
return Integer.parseInt(key.replaceFirst(".*?(\\d+).*", "$1"));
}

private int getTotalNumberIssues() {
String tempQuery = "?jqlQuery=project+%3D+{0}+ORDER+BY+key+DESC&tempMax=1";
tempQuery = tempQuery.replace("{0}", projectName);
Expand All @@ -85,8 +89,7 @@ private int getTotalNumberIssues() {
for (int p = 0; p < node.getChildNodes().getLength(); p++) {
if (node.getChildNodes().item(p).getNodeName().equals("key")) {
String key = (node.getChildNodes().item(p).getTextContent());
key = key.replaceFirst(".*?(\\d+).*", "$1");
return Integer.parseInt(key);
return getIssueIdFromKey(key);
}
}
} catch (Exception e) {
Expand All @@ -98,6 +101,7 @@ private int getTotalNumberIssues() {
public void printIssues() {
int page = 0;
int totalePages = (int) Math.ceil(((double) getTotalNumberIssues() / 1000));
int numberOfIssues = 0;
String fileName = projectName + "_" + page + ".csv";
File file = new File( fileName);
System.out.println("Jira issues saved in "+fileName);
Expand All @@ -116,7 +120,7 @@ public void printIssues() {
while (true) {
String tempQuery = "?jqlQuery=project+%3D+{0}+ORDER+BY+key+ASC&tempMax=1000&pager/start={1}";
tempQuery = tempQuery.replace("{0}", projectName);
tempQuery = tempQuery.replace("{1}", ((page) * 1000) + "");
tempQuery = tempQuery.replace("{1}", numberOfIssues + 1 + "");
if (totalePages >= (page + 1))
System.out.println("Download Jira issues. Page: " + (page + 1) + "/" + totalePages);
try {
Expand All @@ -140,7 +144,7 @@ public void printIssues() {
e1.printStackTrace();
}
printHeader(pw);
printIssuesOfPage(d, pw);
numberOfIssues += printIssuesOfPage(d, pw, page);
pw.close();
page++;
} catch (Exception e) {
Expand All @@ -166,13 +170,15 @@ private void printHeader(PrintWriter pw) {
/**
*
* @param doc
* @param nodeName
* @param pw
* @param pageNumber
* @return
*/
private void printIssuesOfPage(Document doc, PrintWriter pw) {
private int printIssuesOfPage(Document doc, PrintWriter pw, int pageNumber) {
NodeList descNodes = doc.getElementsByTagName("item");
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
for (int i = 0; i < descNodes.getLength(); i++) {
int numberOfIssues = 0;
loop: for (int i = 0; i < descNodes.getLength(); i++) {
Node node = descNodes.item(i);
String issueKey = "";
String priority = "";
Expand All @@ -196,7 +202,9 @@ private void printIssuesOfPage(Document doc, PrintWriter pw) {
resolution = children.item(p).getTextContent();
break;
case "key":
issueKey = children.item(p).getTextContent();
String key = children.item(p).getTextContent();
if (getIssueIdFromKey(key) >= (pageNumber + 1) * 1000) break loop;
issueKey = key;
break;
case "created":
String createdDate = children.item(p).getTextContent();
Expand Down Expand Up @@ -256,8 +264,8 @@ private void printIssuesOfPage(Document doc, PrintWriter pw) {
.replace("\r", "").replace("\t", "") + ";";
}
pw.println(toPrint);

numberOfIssues++;
}

return numberOfIssues;
}
}