2016-06-13 106 views
0

有誰知道如何使用JIRA java REST客戶端API或以某種其他方式使用JIRA訪問JIRA敏捷衝刺。使用JIRA REST客戶端api訪問JIRA敏捷衝刺

1)我正在嘗試檢索JIRA數據(項目,衝刺,問題等)。我需要一種方法來查詢項目,並使用不同的過濾器進行衝刺。我想JRJC無法獲得敏捷數據。是否有針對整個JIRA數據的一站式解決方案?

2)JIRA在他們的文檔中給出了2種類型的api:REST Api和Java Api。何時使用每個這些

+0

你在使用greenhopper嗎? –

+0

您能否提供一些文檔鏈接? –

回答

1
  1. 所有你想要的信息的,請訪問:

https://docs.atlassian.com/jira/REST/latest/

需要注意的是,你可以得到這個項目的信息:https://docs.atlassian.com/jira/REST/latest/#api/2/project

一)至於短跑信息 - 你能用JQL獲得你需要的信息嗎?示例 - 您是否可以轉到問題>搜索問題並使用基本搜索?在這裏,在「更多」選項下,你會看到你可以指定Sprint進行過濾。

當你添加/刪除衝刺,你會看到URL的變化。例如,如果我選擇看到來自Sprint 1和Sprint 6所有的問題類型我JQL是這樣的:

?jql=Sprint%20in%20(227%2C%20229) 

注意,這些都是衝刺的ID。

現在你只需調用REST API與搜索這樣的:

https://jira.domain.com/rest/api/2/search?jql=Sprint%20in%20(227%2C%20229) 

更多細節在這裏: https://docs.atlassian.com/jira/REST/latest/#api/2/search

b)如果你能得到你想要的信息帶有過濾器,你可以簡單地保存過濾器,並與REST API調用過濾

https://jira.domain.com/rest/api/2/filter/{filter-id} 

更多細節在這裏:https://docs.atlassian.com/jira/REST/latest/#api/2/filter-getFilter

  • 您的問題的第二個部分是真的另一個計算器問題: 的JIRA REST API是一個簡單的REST API - 這是HTTP方法調用來獲取數據。例如,您可以使用PHP,Java(例如使用Jersey),bash(使用curl)或甚至僅使用帶有Chrome郵遞員的瀏覽器來調用這些。
  • 對於Jira,Java API或REST Java Client是不受支持的一組庫,如果您特別想使用Java來進行這些其餘調用,則可以使用這些庫。當然,您可以使用Jersey或任何您想要進行Rest調用的其他任何東西,但Java Client提供了一些可能有用的庫。

    0

    試試這個..我用下面的代碼,

    private int setSprint(String sprint, String key, String boardId) { 
        String _jiraUser = applicationProperties.get(Constants.JIRAUSER); 
        String _jiraPwd = applicationProperties.get(Constants.JIRAPWD); 
        String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd)); 
    
        String agileURL = applicationProperties.get(Constants.JIRAURL) 
          + "/rest/agile/1.0/board/" + boardId + "/sprint"; 
    
        int sprintId = invokeGetMethod(auth, agileURL, sprint); 
        // Constants.REPORT.info(sprintId); 
    
        String issueURL = applicationProperties.get(Constants.JIRAURL) 
          + "/rest/agile/1.0/issue/" + key; 
    
        int issueId = getIssueId(auth, issueURL, key); 
        // Constants.REPORT.info(issueId); 
        return invokePostMethod(auth, sprintId, key, issueId); 
        // Constants.REPORT.info(statusCode); 
    
    } 
    
    private static int invokeGetMethod(String auth, String agileURL, 
         String sprint) { 
    
        int sprintId = 0; 
        int startAt = 0; 
        agileURL = agileURL + "?startAt=" + startAt; 
        sprintId = getSprintResult(agileURL, auth, sprint, startAt); 
        // sprintId = getSprintId(content, sprint, agileURL); 
    
        return sprintId; 
    } 
    
    private static int getSprintResult(String agileURL, String auth, 
         String sprint, int startAt) { 
        HttpGet post = new HttpGet(agileURL); 
        org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); 
        post.setHeader("Content-type", "application/json"); 
        post.setHeader("Authorization", "Basic " + auth); 
        HttpResponse response = null; 
        String content = null; 
        try { 
         response = httpClient.execute(post); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
        try { 
         content = CharStreams.toString(new InputStreamReader(response 
           .getEntity().getContent(), Charsets.UTF_8)); 
        } catch (IllegalStateException | IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
        int SprintId = getSprintId(content, sprint, agileURL, startAt, auth); 
        if (SprintId != 0) 
         return SprintId; 
        return SprintId; 
    } 
    
    static int getSprintId(String content, String sprint, String agileURL, 
         int startAt, String auth) { 
        boolean flag = false; 
    
        int sprintId = 0; 
        Gson gson = new Gson(); // Class<String> data=new Class<String>(); 
        Data values = gson.fromJson(content, Data.class); 
        for (Values data : values.getValues()) { // data.get 
         if (data.getName().equalsIgnoreCase(sprint)) 
         // Constants.REPORT.info(sprintId=data.getId()); 
         { 
          flag = true; 
          // Constants.REPORT.info(data); 
          // statusCode = response.getEntityInputStream().; 
          return sprintId = data.getId(); 
         } 
    
        } 
        if (!flag) { 
        //Pagination 
         agileURL = agileURL.replaceAll(
           "startAt=" + String.valueOf(startAt), 
           "startAt=" + String.valueOf(startAt += 50)); 
         sprintId = getSprintResult(agileURL, auth, sprint, startAt); 
         if (sprintId != 0) 
          return sprintId; 
    
        } 
        return sprintId; 
    
    } 
    
    private static int getIssueId(String auth, String agileURL, String key) { 
    
        int issueId = 0; 
        try { 
    
         org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); 
         HttpGet post = new HttpGet(agileURL); 
    
         post.setHeader("Content-type", "application/json"); 
         post.setHeader("Authorization", "Basic " + auth); 
         HttpResponse response = httpClient.execute(post); 
         String content = CharStreams.toString(new InputStreamReader(
           response.getEntity().getContent(), Charsets.UTF_8)); 
    
         Gson gson = new Gson(); // Class<String> data=new Class<String>(); 
    
         IssueData issueValues = gson.fromJson(content, IssueData.class); 
         if (issueValues.getKey().equalsIgnoreCase(key)) 
          issueId = issueValues.getId(); 
         // Constants.REPORT.info(issueValues); 
        } catch (Exception e) { 
         Constants.ERROR.info(Level.INFO, e); 
         // vjErrorLog.info(Level.INFO, e); 
        } 
        return issueId; 
    } 
    private static int invokePostMethod(String auth, int sprintId, String key, 
         int issueId) { 
    
        int statusCode = 0; 
        try { 
         String postUrl = applicationProperties.get(Constants.JIRAURL) 
           + "/rest/agile/1.0/sprint/" + sprintId + "/issue"; 
         String str = "{\"issues\": [\"" + key + "\",\"" + issueId + "\"]}"; 
         statusCode = invokePostMethod(auth, postUrl, str); 
    
         return statusCode; 
        } catch (Exception e) { 
         Constants.ERROR.info(Level.INFO, e); 
         // vjErrorLog.info(Level.INFO, e); 
        } 
        return statusCode; 
    } 
    

    下面的屬性創建一個IssueData類。並創建getter/setter也overeride toString()方法。

    private int id; 
    private String self; 
    private String key;