#' jira_issues
#'
#' Extract issue data from the JIRA API; returns a single data frame of issue data by default, or two dataframes in a list if changelog is set to TRUE
#' @param project_url The JIRA project ULR
#' @param project_id The JIRA project ID
#' @param changelog If you want to get a dataframe of all changes change this to TRUE
#' @param sample If you want to get only a sample of the most recent 200 issues, set this to TRUE
#' @param jql Pass a JQL string if you want to search for only specific issues
#' @param sprint Pass a specific sprint name if you want to search only for issues relating to it; defaults to NULL. Only works if formatted like 'Mobile Sprint 108', doesn't work with the full sprint name
#' @export
jira_issues <- function(project_url,project_id,changelog = FALSE,sample = FALSE, jql = NULL,sprint = NULL) {
require(httr)
require(jsonlite)
require(tidyverse)
require(rlist)
require(neugelbtools)
require(fasttime)
require(lubridate)
require(purrr)
start_point <- 0
issues_list <- list()
#get the API credentials
issues_list <- jira_issues_api(project_url,project_id,changelog,sample,jql,sprint)
#convert to tabular format
issues_prep <- jira_issues_prep(issues_list,changelog)
final_tbl <- jira_issues_df(issues_prep$issues_list,issues_prep$fields_list,project_id)
if (changelog == TRUE) {
changes <- jira_changelog(issues_prep$issues_list,issues_prep$changes_list,issues_prep$fields_list)
all_list <- list()
all_list$issues <- final_tbl
all_list$changelog <- changes
return(all_list)
} else if (changelog == FALSE) {
return(final_tbl)
}
}
#mba_sprint_fix
mba_sprint_process <- function(value) {
#extract the string from its place in the list
v1 <- value[[1]]
#clean the edges of the string
v1 = str_replace_all(str_replace_all(v1,".*\\[",''),'\\]','')
#split the single large string into a vector
v2 = str_split(v1,',')
#pull the vector out from the new list
v2 <- v2[[1]]
sprint_tbl <- tibble(index = 1)
#create a table with each little string converted to a key value pair of column name and value
for (spr in 1:length(v2)) {
valnew <- str_split(v2[[spr]],'=')
name <- valnew[[1]][[1]]
value <- tibble(val = valnew[[1]][[2]])
colnames(value) <- name
sprint_tbl <- bind_cols(sprint_tbl,value)
}
sprint_tbl <- sprint_tbl %>%
select(-index) %>%
#clean any messy values
mutate_all(~ ifelse(. %in% c('<null>',''),NA,.))
#rename the columns
colnames(sprint_tbl) <- paste('sprint',names(sprint_tbl),sep = '_')
return(sprint_tbl)
}
#mba_sprint_fix
mba_sprint_fix <- function(value) {
require(purrr)
require(tidyverse)
require(neugelbtools)
date_cols <- c('sprint_start_date','sprint_end_date','sprint_complete_date')
if (length(value) > 1) {
sprint_tbl <- do.call('bind_rows',map(value,mba_sprint_process)) %>%
tidycols() %>%
mutate_at(date_cols,~ as_date(str_replace_all(.,'T',' '))) %>%
filter(!sprint_state == 'FUTURE') %>%
filter(sprint_end_date == max(sprint_end_date))
} else {
sprint_tbl <- mba_sprint_process(value) %>%
tidycols() %>%
mutate_at(date_cols,~ as_date(str_replace_all(.,'T',' ')))
}
return(sprint_tbl)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.