Created
January 27, 2016 01:47
-
-
Save PreSoichiSumi/d57db9730764af2b2ed2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.univ.graftability; | |
import java.net.URI; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import com.atlassian.jira.rest.client.api.JiraRestClient; | |
import com.atlassian.jira.rest.client.api.domain.Issue; | |
import com.atlassian.jira.rest.client.api.domain.SearchResult; | |
import com.atlassian.jira.rest.client.auth.AnonymousAuthenticationHandler; | |
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory; | |
import com.atlassian.util.concurrent.Promise; | |
public class JiraIssueDumper { | |
private String projectName; | |
private List<String> projectList; | |
final private int SLEEP_TIME=5000; | |
final private int PAGE_SIZE=50; | |
public JiraIssueDumper(String projectName) { | |
super(); | |
this.projectName = projectName; | |
} | |
//Jira Apacheの検索結果と同じのが全部取得できたで | |
public List<Iterable<Issue>> getIssueList() | |
throws Exception { | |
final URI jiraServerUri = URI.create("https://issues.apache.org/jira/"); | |
final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); | |
final JiraRestClient restClient = factory.create(jiraServerUri, | |
new AnonymousAuthenticationHandler()); | |
List<Iterable<Issue>> issueList = new ArrayList<Iterable<Issue>>(); | |
Set<String> search = new HashSet<String>(); | |
search.add("*all"); | |
try { | |
Promise<SearchResult> searchJqlPromise = restClient | |
.getSearchClient() | |
.searchJql( | |
"project = " | |
+ projectName | |
+ " AND status = Closed AND resolution = Fixed AND issuetype = Bug", | |
PAGE_SIZE, 0, search); | |
int resTotal = searchJqlPromise.claim().getTotal(); | |
int pageItrt = 0; | |
if (resTotal != 0) { | |
while (pageItrt <= resTotal) { // ページイテレータがAPIに見つからなかったから自分でめくる | |
searchJqlPromise = restClient | |
.getSearchClient() | |
.searchJql( | |
"project = " | |
+ projectName | |
+ " AND status = Closed AND resolution = Fixed AND issuetype = Bug", | |
PAGE_SIZE, pageItrt, search); | |
issueList.add(searchJqlPromise.claim().getIssues()); | |
pageItrt += PAGE_SIZE; | |
System.out.println("Waiting for 5 seconds."); | |
Thread.sleep(SLEEP_TIME); | |
} | |
} | |
} catch(Exception e){ | |
System.out.println(e); | |
System.out.println(); | |
} finally { | |
restClient.close(); | |
} | |
return issueList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment