#' jira_issues_df
#'
#' Converts the issues data from the Jira API into a data frame
#' @param issues_list The list of Jira issues
#' @param fields_list The list of the fields
#' @param project_id The project ID
#' @export
jira_issues_df <- function(issues_list,fields_list,project_id=NULL) {
require(httr)
require(jsonlite)
require(tidyverse)
require(rlist)
require(neugelbtools)
require(fasttime)
require(lubridate)
require(purrr)
if (is_empty(project_id) == TRUE) {
project_id <- as.numeric(fields_list[[1]]$project$id)
} else {
project_id <- as.numeric(project_id)
}
#convert the issues, as needed
final_tbl <- tibble()
#run through each issue
for (test in 1:length(issues_list)) {
issue <- issues_list[[test]]
fields <- fields_list[[test]]
field_names <- names(fields)
#create single row table for the issue
index_nr = test
issue_tbl <- as_tibble(issue) %>%
mutate(index = index_nr)
#run through each field
for (r in 1:length(fields)) {
name <- field_names[[r]]
val <- map(fields[[r]],compact)
if ('avatarUrls' %in% names(val)) {
val$avatarUrls <- NULL
}
#fields to skip
if (is_empty(val) == TRUE | name %in% c("issuelinks","customfield_12200",'subtasks','customfield_11002','customfield_10104','parent',"customfield_12124","customfield_10102")) {
next()
} else if (name == 'customfield_10103') {
#fix the sprint fields
spr <- mba_sprint_fix(val)
issue_tbl <- bind_cols(issue_tbl,spr)
} else if (name == 'labels') {
#convert the labels into a list column
test = tibble(labels = list(unlist(val)))
issue_tbl <- bind_cols(issue_tbl,test)
} else if (name == 'status') {
sc <- as_tibble(nullToNA(val$statusCategory)) %>%
col_renamer('status_category')
s <- as_tibble(nullToNA(val)) %>%
slice(1) %>%
select(-statusCategory) %>%
col_renamer('status') %>%
bind_cols(sc)
issue_tbl <- bind_cols(issue_tbl,s)
} else if (name %in% c('components','versions','fixVersions')) {
#convert these elements into list columns
comps <- list()
for (s in 1:length(val)) {
val2 <- nullToNA(val[[s]]$name)
comps <- list.append(comps,val2)
}
test <- tibble(val = list(unlist(comps)))
colnames(test) <- name
issue_tbl <- bind_cols(issue_tbl,test)
} else {
#apply to all other types of list object
if (list_depth(val) > 1 & str_detect(name,'customfield')==TRUE) {
test <- do.call('bind_rows',map(nullToNA(val),as_tibble)) %>%
slice(1)
} else if (length(val) > 1) {
test <- as_tibble(nullToNA(val)) %>%
slice(1)
} else {
test <- tibble(value = unlist(val))
}
#rename the columns
colnames(test) <- paste(name,names(test),sep='_')
issue_tbl <- bind_cols(issue_tbl,test)
}
}
final_tbl <- bind_rows(final_tbl,issue_tbl)
}
print('All tickets processed')
#drop some unneeded columns
self_names <- names(final_tbl)[str_detect(names(final_tbl),'self|icon|avatar') == FALSE]
ts_cols <- c('created_value','updated_value')
final_tbl <- final_tbl %>%
select(self_names) %>%
select(-expand,-index) %>%
tidycols() %>%
mutate_at(ts_cols,~ fastPOSIXct(str_replace_all(.,'T',' '))) %>%
remove_na_cols() %>%
mutate(is_resolved = ifelse(status_category_name == 'Done',TRUE,FALSE)) %>%
mutate(creation_to_resolution = ifelse(is_resolved == TRUE,round(difftime(updated_value,created_value,units='days'),3),NA)) %>%
mutate_if(is.character, trimws)
if (project_id == 11200) {
final_tbl <- mobile_app_cleaner(final_tbl)
}
return(final_tbl)
}
mobile_app_cleaner <- function(final_tbl) {
if ('customfield_10105_value' %in% names(final_tbl)) {
final_tbl <- final_tbl %>%
rename(story_points = customfield_10105_value)
}
if ('customfield_12000_value' %in% names(final_tbl)) {
final_tbl <- final_tbl %>%
rename(team_name = customfield_12000_value)
}
if ('customfield_12000_id' %in% names(final_tbl)) {
final_tbl <- final_tbl %>%
rename(team_id = customfield_12000_id)
}
return(final_tbl)
}
recruitment_cleaner <- function(final_tbl) {
if (project_id == 11200) {
if ('customfield_10105_value' %in% names(final_tbl)) {
final_tbl <- final_tbl %>%
rename(story_points = customfield_10105_value)
}
}
return(final_tbl)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.