library(RCurl) library(curl) library(jsonlite) library(gsubfn) library(gplots) library(RColorBrewer) #functions companies <- function (names) { companys = list() for (name in names) { for (n in name) { companys[[length(companys) + 1]] <- strapplyc(n, "@(.*)", simplify = TRUE) } } company <- unique(companys) return (company) } display_heatmap <- function(report, m, suffix) { report_name <- paste(report["name"], suffix, ".png",sep = "") png(file=report_name, title = report["name"]) #display raw data print(m) cat("Generating", report_name) # following code limits the lowest and highest color to 5%, and 95% of your range, respectively quantile.range <- quantile(m, probs = seq(0, 1, 0.01)) palette.breaks <- seq(quantile.range["5%"], quantile.range["95%"], 0.1) # use http://colorbrewer2.org/ to find optimal divergent color palette (or set own) color.palette <- colorRampPalette(c("#FC8D59", "#FFFFBF", "#91CF60"))(length(palette.breaks) - 1) watcher_heatmap <- heatmap.2( m, dendrogram = 'row', Rowv = TRUE, Colv = FALSE, trace = "none", margins = c(12, 12), col = color.palette, breaks = palette.breaks, ylab = "company", xlab = "project" ) dev.off() } watcher_heatmap <- function(report) { baseurl <- "https://projects.linaro.org/rest/api/2/" fields <- "&fields=watches,key,project" type <- "search?" jql <- paste ("jql=project+in+(",report["team"],")+AND+issuetype+in+(Initiative,Epic)&maxResults=2000", sep = "") url <- paste(baseurl, type, jql, fields, sep = "") cat (url,"\n") webpage <- curl (url, handle = h) #get data it into R jira_raw <- fromJSON(webpage, simplifyDataFrame = TRUE) # extract the data node keys <- jira_raw$issues$key #x axis the number of projects projects <- unique(jira_raw$issues$fields$project$key) num_projects <- length(projects) #projects #from the website now get watchers names with another query for all keys found previously fields <- "/watchers" type <- "issue/" names = list() for (key in keys) { url <- paste(baseurl, type, key, fields, sep = "") webpage <- curl (url, handle = h) jira_raw_names <- fromJSON(webpage, simplifyDataFrame = TRUE) names[[length(names) + 1]] <- as.list(jira_raw_names$watchers$name) } #create empty matrix comp <- companies(names) num_comp <- length(comp) m <- matrix(NA, nrow = num_comp, ncol = num_projects) colnames(m) <- projects rownames(m) <- comp m[] <- 0L #from the website now get watchers names with another query for all keys found previously fields <- "/watchers" type <- "issue/" for (key in keys) { #y mike <- match (key, keys) team <- jira_raw$issues$fields$project$key[mike] y <- match (team, projects) #x names = list() url <- paste(baseurl, type, key, fields, sep = "") webpage <- curl (url, handle = h) jira_raw_names <- fromJSON(webpage, simplifyDataFrame = TRUE) names[[length(names) + 1]] <- as.list(jira_raw_names$watchers$name) interested = companies(names) for (c in interested) { x <- match (c, comp) m[x, y] <- m[x, y] + 1 } } #remove companies rows.to.delete <- c('linaro.org', 'broadcom.com', 'character') for (d in rows.to.delete) { m <- as.matrix(m[!grepl(d, rownames(m)),]) } display_heatmap(report, m,"_wt") } sponsor_heatmap <- function (report) { baseurl <- "https://projects.linaro.org/rest/api/2/" fields <- "&fields=customfield_10101,key,project" type <- "search?" jql <- paste( "jql=project+in+(", report["team"], ")+AND+issuetype+in+(Initiative,Epic)&maxResults=1000", sep = "" ) url <- paste(baseurl, type, jql, fields, sep = "") cat (url,"\n") webpage <- curl (url, handle = h) #get data it into R jira_raw <- fromJSON(webpage, simplifyDataFrame = TRUE) #list of every issue keys <- jira_raw$issues$key #x axis the number of projects projects <- unique(jira_raw$issues$fields$project$key) num_projects <- length(projects) #y axis the companies or sponsors sponsor <- jira_raw$issues$fields$customfield_10101 names = list() for (key in keys) { s <- sponsor[[match (key, keys)]][[2]] for (n in s) { names[[length(names) + 1]] <- n } } #create empty matrix comp <- unique(names) num_comp <- length(comp) m <- matrix(NA, nrow = num_comp, ncol = num_projects) colnames(m) <- projects rownames(m) <- comp m[] <- 0L # count companies per project by looking at every key and update matrix for (key in keys) { #y mike <- match (key, keys) team <- jira_raw$issues$fields$project$key[mike] y <- match (team, projects) #x s <- sponsor[[match (key, keys)]][[2]] for (c in s) { x <- match (c, comp) m[x, y] <- m[x, y] + 1 } } #remove companies we don't like ;) rows.to.delete <- c('Linaro') for (d in rows.to.delete) { m <- as.matrix(m[!grepl(d, rownames(m)),]) } display_heatmap(report, m, "_sp") } #from the website get the initiatives list for the four teams id <- Sys.getenv(c("JIRA_USERNAME", "JIRA_PASSWORD")) if (id[1] == '') { print ("export JIRA_USERNAME='john.doe@linaro.org'") q() } if (id[2] == '') { print ("export JIRA_PASSWORD='my-super-secret-password'") q() } user_password <- paste(id[1], id[2], sep=":") h <- new_handle(failonerror = TRUE) handle_setopt(h, verbose = 0) handle_setopt(h, userpwd = user_password) handle_setopt(h, httpauth = 1) report_name <- c("coredev", "segment", "ct_t") team_list <- c( "Security,Kernel,'Power',Virtualization,LSK", "LHG,LEG,LNG,LITE,LMG", "CTT,BB,LAVA,LAB,QA,SYS,TCWG" ) reports <- data.frame(name = report_name , team = team_list, stringsAsFactors = FALSE) apply(reports, 1, sponsor_heatmap) apply(reports, 1, watcher_heatmap)