如何使用R解析和获取JIRA查询的输出列表中的参数值?

时间:2017-08-10 00:36:31

标签: r jira jira-rest-api

JIRA 查询中有一个已解析的json 输出列表,其中 n '问题键的数量值如下所示:

library(httr)
library(tibble)
library(dplyr)
url <- "https://somesite.atlassian.net/rest/api/latest/search?jql=project = Project"
res <- GET(url , authenticate("username", "password", "basic") )
parsed_json <- content(res, "parsed")

parsed_json$total
[1] 4

number_of_issues  <- parsed_json$total

parsed_json$issues[[1]]$key
[1] "Project-111"
parsed_json$issues[[2]]$key
[1] "Project-112"
parsed_json$issues[[3]]$key
[1] "Project-113"
parsed_json$issues[[4]]$key
[1] "Project-114"

IssuesList <- paste0("parsed_json$issues[[", 1:number_of_issues,"]]$key")

IssuesList
[1] "parsed_json$issues[[1]]$key" "parsed_json$issues[[2]]$key" "parsed_json$issues[[3]]$key" "parsed_json$issues[[4]]$key"

我希望从列表中获取问题键值。我很惊讶如何从列表中获取parsed_json $ issues [[?]] $ key的值。这个论坛中最接近的问题是R: How to convert the output-list from a FQL-query into a data.frame?。但是,我无法提取单个参数的值。此外,由于生成列表中的参数长度不同,我无法使用此解决方案。有任何建议可以实现吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,并为像我这样计划使用REST API和R查询JIRA的人分享。

library(httr)
library(tibble)
library(dplyr)

url <- "https://somesite.atlassian.net/rest/api/latest/search?jql=project = Project"
res <- GET(url , authenticate("username", "password", "basic") )
parsed_json <- content(res, "parsed")
parsed_json <- enframe(unlist(parsed_json, recursive = TRUE, use.names = TRUE))

# Select the parameters which has values for all the issues in the JIRA query output list 
# to avoid  "arguments in the generated list are not of same length" error message while unstacking.

df<- filter(parsed_json, (name == "issues.key" | name == "issues.fields.status.name" | name == "issues.fields.summary" |  
                          name == "issues.fields.assignee.displayName" | name == "issues.fields.created" | 
                          name == "issues.fields.updated"...))
df <- unstack(as.data.frame(df), value ~ name)