R/jira_users.R

Defines functions jira_user_names_fix jira_users

Documented in jira_users

#' jira_users
#'
#' Extract user data from the JIRA API
#' @param project_url The JIRA project ULR
#' @export

jira_users <- function(project_url) {

require(tidyverse)
require(httr)
require(purrr)
require(neugelbtools)

#get the API credentials

jira_creds <- jira_auth_check()

#generate the url

jira_url <- paste(project_url,"/rest/api/2/user/search?username=.&startAt=0&maxResults=2000",sep='')

#call the API and extract the content

call <- GET(jira_url,authenticate(jira_creds$user,jira_creds$pass))

x <- content(call,"parsed")

users <- do.call('bind_rows',map(map(x, ~ discard(.x, names(.x) %in% c('self','avatarUrls'))),as_tibble)) %>%
  tidycols()

return(users)

}

jira_user_names_fix <- function(df) {

  require(tidyverse)

  df2 <- df %>%
  filter(!is.na(display_name)) %>%
  mutate(is_good_name = ifelse(str_detect(display_name,'@') == TRUE,FALSE,
                               ifelse(str_detect(display_name,' ') == TRUE,TRUE,FALSE)),
         display_name = ifelse(str_detect(display_name,'@') == TRUE,
                               str_to_title(str_replace_all(str_replace_all(display_name,'@.*',''),fixed('.'),' ')),
                               display_name),
         is_good_name = ifelse(str_detect(display_name,'@') == TRUE,FALSE,
                               ifelse(str_detect(display_name,' ') == TRUE,TRUE,FALSE))
         )

  return(df2)

}
neugelb/njira documentation built on Sept. 2, 2020, 7:02 p.m.